crosvm/gpu_display/build.rs

103 lines
3.3 KiB
Rust
Raw Normal View History

// Copyright 2018 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use std::env;
use std::ffi::OsStr;
use std::fs;
use std::path::{Path, PathBuf};
use std::process::Command;
// Performs a recursive search for a file with name under path and returns the full path if such a
// file is found.
fn scan_path<P: AsRef<Path>, O: AsRef<OsStr>>(path: P, name: O) -> Option<PathBuf> {
for entry in (fs::read_dir(path).ok()?).flatten() {
let file_type = match entry.file_type() {
Ok(t) => t,
Err(_) => continue,
};
if file_type.is_file() && entry.file_name() == name.as_ref() {
return Some(entry.path());
} else if file_type.is_dir() {
if let Some(found) = scan_path(entry.path(), name.as_ref()) {
return Some(found);
}
}
}
None
}
// Searches for the given protocol in both the system wide and bundles protocols path.
fn find_protocol(name: &str) -> PathBuf {
let protocols_path = pkg_config::get_variable("wayland-protocols", "pkgdatadir")
.unwrap_or_else(|_| "/usr/share/wayland-protocols".to_owned());
let protocol_file_name = PathBuf::from(format!("{}.xml", name));
// Prioritize the systems wayland protocols before using the bundled ones.
if let Some(found) = scan_path(protocols_path, &protocol_file_name) {
return found;
}
// Use bundled protocols as a fallback.
let protocol_path = Path::new("protocol").join(protocol_file_name);
assert!(
protocol_path.is_file(),
"unable to locate wayland protocol specification for `{}`",
name
);
protocol_path
}
fn compile_protocol<P: AsRef<Path>>(name: &str, out: P) -> PathBuf {
let in_protocol = find_protocol(name);
println!("cargo:rerun-if-changed={}", in_protocol.display());
let out_code = out.as_ref().join(format!("{}.c", name));
let out_header = out.as_ref().join(format!("{}.h", name));
eprintln!("building protocol: {}", name);
Command::new("wayland-scanner")
.arg("code")
.arg(&in_protocol)
.arg(&out_code)
.output()
.expect("wayland-scanner code failed");
Command::new("wayland-scanner")
.arg("client-header")
.arg(&in_protocol)
.arg(&out_header)
.output()
.expect("wayland-scanner client-header failed");
out_code
}
fn main() {
Reland "github: Minimize dependencies for document generation" This is a reland of commit 2b85d4d1e521ef66f165bca21741b52607acdb22 Diff from the original CL: * Changed the return value of `main()` in power_monitor/build.rs * Ran cargo-check with all features enabled Original change's description: > github: Minimize dependencies for document generation > > Instead of install full dependencies with `install-deps` in GitHub > action, minimize dependencies because we use GitHub only for document > generation. > > - Passed `CARGO_DOC` environment when running cargo-doc command so we > can skip unnecessary build flow when we just want to generate API docs. > - Added a new script `install-docs-deps` to install only doc-related > dependencies. > > BUG=none > TEST=test on GitHub Action at my personal repository > > Change-Id: Ibe988ab43215e285d946812bdd6c1536ae87b50e > Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3578144 > Tested-by: kokoro <noreply+kokoro@google.com> > Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> > Reviewed-by: Anton Romanov <romanton@google.com> > Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org> Bug=none TEST=cargo check --all-features Change-Id: I77ee6543910e3fe7f69be48f8f965eda3433d4e6 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3584063 Auto-Submit: Keiichi Watanabe <keiichiw@chromium.org> Reviewed-by: Dennis Kempin <denniskempin@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2022-04-08 10:51:32 +00:00
// Skip installing dependencies when generating documents.
if std::env::var("CARGO_DOC").is_ok() {
return;
}
println!("cargo:rerun-if-env-changed=WAYLAND_PROTOCOLS_PATH");
let out_dir = env::var("OUT_DIR").unwrap();
let mut build = cc::Build::new();
build.warnings(true);
build.warnings_into_errors(true);
build.include(&out_dir);
build.flag("-std=gnu11");
build.file("src/display_wl.c");
println!("cargo:rerun-if-changed=src/display_wl.c");
for protocol in &[
"aura-shell",
"linux-dmabuf-unstable-v1",
"xdg-shell",
"viewporter",
gpu_display: Add opt wayland ext for sending scanout id Cuttlefish's streaming server, which acts as a Wayland compositor in order to receive display framebuffers from Crosvm, needs some mechanism to tell which Wayland surface corresponds to which display (a "display" is a "scanout" in virtio-gpu terminology). Wayland object ids can not be directly used for this as all Wayland objects share a single global id space (so the first created Wayland wl_surface surface object may have id = 15). Previously, the case of unchanging displays was handled by enforcing the creation order of surfaces within Crosvm so that Cuttlefish's streaming server (which is a Wayland compositor) could assume the creation order corresponded to the display order. However, this still experienced issues (b:186580833) when surfaces were destroyed and later recreated when handling `set_scanout(..., resource_id = 0)` commands. There is also an ongoing effort to support adding and removing displays at runtime in (see aosp/1671968) which experiences the same issue. When surfaces are arbitrarily created and destroyed, Cuttlefish's streaming server has no way to determine which Wayland surface corresponds to which display. To solve all of this, this change introduces an extension to allow Wayland clients (Crosvm) to attach additional metadata (scanout_id) to Wayland objects (surfaces) so that Wayland compositors (Cuttlefish's streaming server) can exactly determine which surfaces correspond to which displays. I will attempt to upstream this protocol (tracked in b:191901112). BUG=b:188904670 BUG=b:187351899 BUG=b:191901112 TEST=launch Cuttlefish with single display TEST=launch Cuttlefish with multiple displays TEST=launch Cuttlefish and hotplug some displays Change-Id: I2aa4b714a49e4d85b6a3c705ba0d5bc1720b838e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2909903 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dennis Kempin <denniskempin@google.com> Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org> Reviewed-by: Dennis Kempin <denniskempin@chromium.org> Commit-Queue: Jason Macnak <natsu@google.com>
2021-05-21 16:33:27 +00:00
"virtio-gpu-metadata-v1",
] {
build.file(compile_protocol(protocol, &out_dir));
}
build.compile("display_wl");
println!("cargo:rustc-link-lib=dylib=wayland-client");
}