crosvm/net_util/build.rs
Dennis Kempin 01da29a398 net_util/win_audio: Do not use cfg conditional compilation in build.rs
The build.rs file will be compiled for the host platform and cfg()
flags will reflect those of the host platform and not of the build
target.
Use CARGO_CFG_ environment variables instead.

BUG=b:240593511
TEST=CQ

Change-Id: Ib8b6c8e8bfb44ad83212bb2aa40a17a4e16a4adf
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4518569
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
2023-05-09 20:27:26 +00:00

31 lines
1.4 KiB
Rust

// Copyright 2020 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
static PREBUILTS_VERSION_FILENAME: &str = "prebuilts_version";
static SLIRP_LIB: &str = "libslirp.lib";
static SLIRP_DLL: &str = "libslirp-0.dll";
static GLIB_FILENAME: &str = "libglib-2.0.dll.a";
fn main() {
// We (the Windows crosvm maintainers) submitted upstream patches to libslirp-sys so it doesn't
// try to link directly on Windows. This is because linking on Windows tends to be specific
// to the build system that invokes Cargo (e.g. the crosvm jCI scripts that also produce the
// required libslirp DLL & lib). The integration here (win_slirp::main) is specific to crosvm's
// build process.
if std::env::var("CARGO_CFG_WINDOWS").is_ok() {
let version = std::fs::read_to_string(PREBUILTS_VERSION_FILENAME)
.unwrap()
.trim()
.parse::<u32>()
.unwrap();
// TODO(b:242204245) build libslirp locally on windows from build.rs.
let mut libs = vec![SLIRP_DLL, SLIRP_LIB];
if std::env::var("CARGO_CFG_TARGET_ENV") == Ok("gnu".to_string()) {
libs.push(GLIB_FILENAME);
}
prebuilts::download_prebuilts("libslirp", version, &libs).unwrap();
}
// For unix, libslirp-sys's build script will make the appropriate linking calls to pkg_config.
}