crosvm/net_util/build.rs
Noah Gold 1977979fbb net_util: upstream Windows support
Adds the libslirp interface code, as well as the Windows pseudo-tap
device.

BUG=b:213151463

TEST=bots (unix + windows)

Change-Id: I975b27a76c82e25037d4061587fec0c31222a159
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3598234
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2022-06-02 03:00:36 +00:00

44 lines
1.6 KiB
Rust

// Copyright 2020 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.
#[cfg(all(feature = "slirp", windows))]
mod win_slirp {
use std::env;
pub(super) fn main() {
// This must be an absolute path or linking issues will result when a consuming crate
// tries to link since $PWD will be different.
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
#[cfg(debug_assertions)]
let build_type = "debug";
#[cfg(not(debug_assertions))]
let build_type = "release";
println!(
r#"cargo:rustc-link-search={}\..\..\..\third_party\libslirp\{}"#,
manifest_dir, build_type
);
println!(
r#"cargo:rustc-env=PATH={};{}\..\..\..\third_party\libslirp\{};"#,
env::var("PATH").unwrap(),
manifest_dir,
build_type,
manifest_dir
);
}
}
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.
#[cfg(all(feature = "slirp", windows))]
win_slirp::main();
// For unix, libslirp-sys's build script will make the appropriate linking calls to pkg_config.
}