From 18027ee80ac47ad86f6dc7b942507e2d23bc9d7b Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Mon, 25 Oct 2021 14:53:45 -0700 Subject: [PATCH] rutabaga_gfx: silence warnings when not building virgl_renderer Sprinkle cfg checks throughout build.rs to get rid of the compiler warnings about unused functions when building with the default features (without --features=virgl_renderer). BUG=None TEST=cargo build TEST=cargo build --features=virgl_renderer Change-Id: I2a1548ec0de33d958c5cd5b6658ec92cd6840566 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3243013 Reviewed-by: Dennis Kempin Tested-by: kokoro Commit-Queue: Daniel Verkamp --- rutabaga_gfx/build.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/rutabaga_gfx/build.rs b/rutabaga_gfx/build.rs index 945062871c..198d8ea4a7 100644 --- a/rutabaga_gfx/build.rs +++ b/rutabaga_gfx/build.rs @@ -2,22 +2,34 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -use anyhow::{bail, Result}; +use anyhow::Result; + +#[cfg(feature = "virgl_renderer")] +use anyhow::bail; +#[cfg(feature = "virgl_renderer")] use std::env; +#[cfg(feature = "virgl_renderer")] use std::fs; +#[cfg(feature = "virgl_renderer")] use std::path::Path; +#[cfg(feature = "virgl_renderer")] use std::path::PathBuf; +#[cfg(feature = "virgl_renderer")] use std::process::Command; +#[cfg(feature = "virgl_renderer")] const MINIGBM_SRC: &str = "../third_party/minigbm"; +#[cfg(feature = "virgl_renderer")] const VIRGLRENDERER_SRC: &str = "../third_party/virglrenderer"; +#[cfg(feature = "virgl_renderer")] fn is_native_build() -> bool { env::var("HOST").unwrap() == env::var("TARGET").unwrap() } /// Returns the target triplet prefix for gcc commands. No prefix is required /// for native builds. +#[cfg(feature = "virgl_renderer")] fn get_cross_compile_prefix() -> String { if is_native_build() { return String::from(""); @@ -31,6 +43,7 @@ fn get_cross_compile_prefix() -> String { /// For cross-compilation with meson, we need to pick a cross-file, which /// live in /usr/local/share/meson/cross. +#[cfg(feature = "virgl_renderer")] fn get_meson_cross_args() -> Vec { if is_native_build() { Vec::new() @@ -42,6 +55,7 @@ fn get_meson_cross_args() -> Vec { } } +#[cfg(feature = "virgl_renderer")] fn build_minigbm(out_dir: &Path) -> Result<()> { let lib_path = out_dir.join("libgbm.a"); if lib_path.exists() { @@ -73,6 +87,7 @@ fn build_minigbm(out_dir: &Path) -> Result<()> { Ok(()) } +#[cfg(feature = "virgl_renderer")] fn build_virglrenderer(out_dir: &Path) -> Result<()> { let lib_path = out_dir.join("src/libvirglrenderer.a"); if lib_path.exists() { @@ -114,6 +129,7 @@ fn build_virglrenderer(out_dir: &Path) -> Result<()> { Ok(()) } +#[cfg(feature = "virgl_renderer")] fn virglrenderer() -> Result<()> { // System provided runtime dependencies. pkg_config::Config::new().probe("epoxy")?;