xref: /aosp_15_r20/external/crosvm/net_util/build.rs (revision bb4ee6a4ae7042d18b07a98463b9c8b875e44b39)
1 // Copyright 2020 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 static PREBUILTS_VERSION_FILENAME: &str = "prebuilts_version";
6 static SLIRP_LIB: &str = "libslirp.lib";
7 static SLIRP_DLL: &str = "libslirp-0.dll";
8 static GLIB_FILENAME: &str = "libglib-2.0.dll.a";
9 
main()10 fn main() {
11     // We (the Windows crosvm maintainers) submitted upstream patches to libslirp-sys so it doesn't
12     // try to link directly on Windows. This is because linking on Windows tends to be specific
13     // to the build system that invokes Cargo (e.g. the crosvm jCI scripts that also produce the
14     // required libslirp DLL & lib). The integration here (win_slirp::main) is specific to crosvm's
15     // build process.
16     if std::env::var("CARGO_CFG_WINDOWS").is_ok() {
17         let version = std::fs::read_to_string(PREBUILTS_VERSION_FILENAME)
18             .unwrap()
19             .trim()
20             .parse::<u32>()
21             .unwrap();
22         // TODO(b:242204245) build libslirp locally on windows from build.rs.
23         let mut libs = vec![SLIRP_DLL, SLIRP_LIB];
24         if std::env::var("CARGO_CFG_TARGET_ENV") == Ok("gnu".to_string()) {
25             libs.push(GLIB_FILENAME);
26         }
27         prebuilts::download_prebuilts("libslirp", version, &libs).unwrap();
28     }
29 
30     // For unix, libslirp-sys's build script will make the appropriate linking calls to pkg_config.
31 }
32