Skip to content

Commit 336fb8e

Browse files
authored
Fix cross-compilation of Windows surrogate binary on Linux (#1045)
Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
1 parent bfbd008 commit 336fb8e

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

Justfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ fmt-apply:
240240
clippy target=default-target: (witguest-wit)
241241
{{ cargo-cmd }} clippy --all-targets --all-features --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -- -D warnings
242242

243+
# for use on a linux host-machine when cross-compiling to windows. Uses the windows-gnu which should be sufficient for most purposes
244+
# Note: `--all-targets` does not work because build issues from tracy-crate
245+
clippyw target=default-target: (witguest-wit)
246+
{{ cargo-cmd }} clippy --all-features --target x86_64-pc-windows-gnu --profile={{ if target == "debug" { "dev" } else { target } }} -- -D warnings
247+
243248
clippy-guests target=default-target: (witguest-wit)
244249
cd src/tests/rust_guests/simpleguest && cargo clippy --profile={{ if target == "debug" { "dev" } else { target } }} -- -D warnings
245250
cd src/tests/rust_guests/witguest && cargo clippy --profile={{ if target == "debug" { "dev" } else { target } }} -- -D warnings

src/hyperlight_host/build.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ fn main() -> Result<()> {
2525

2626
// Windows requires the hyperlight_surrogate.exe binary to be next to the executable running
2727
// hyperlight. We are using rust-embed to include the binary in the hyperlight-host library
28-
// and then extracting it at runtime why the surrogate process manager starts and needed pass
28+
// and then extracting it at runtime when the surrogate process manager starts. We need to pass
2929
// the location of the binary to the rust build.
30-
#[cfg(target_os = "windows")]
31-
{
30+
// This logic runs when targeting Windows, even if cross-compiling from Linux.
31+
if std::env::var("CARGO_CFG_TARGET_OS")? == "windows" {
3232
println!("cargo:rerun-if-changed=src/hyperlight_surrogate/src/main.rs");
3333

3434
// Build hyperlight_surrogate and
@@ -56,7 +56,7 @@ fn main() -> Result<()> {
5656
// be the same as the CARGO_TARGET_DIR for the hyperlight-host otherwise
5757
// the build script will hang. Using a sub directory works tho!
5858
// xref - https://github.com/rust-lang/cargo/issues/6412
59-
let target_dir = std::path::PathBuf::from(&out_dir).join("..\\..\\hls");
59+
let target_dir = std::path::PathBuf::from(&out_dir).join("../../hls");
6060

6161
let profile = std::env::var("PROFILE")?;
6262
let build_profile = if profile.to_lowercase() == "debug" {
@@ -65,19 +65,29 @@ fn main() -> Result<()> {
6565
profile.clone()
6666
};
6767

68-
std::process::Command::new("cargo")
68+
let target_triple = std::env::var("TARGET")?;
69+
70+
let status = std::process::Command::new("cargo")
6971
.env("CARGO_TARGET_DIR", &target_dir)
7072
.arg("build")
7173
.arg("--manifest-path")
7274
.arg(&target_manifest_path)
75+
.arg("--target")
76+
.arg(&target_triple)
7377
.arg("--profile")
7478
.arg(build_profile)
7579
.arg("--verbose")
76-
.output()
77-
.unwrap();
80+
.status()
81+
.expect("Failed to execute cargo build for surrogate");
82+
83+
if !status.success() {
84+
panic!("Failed to build hyperlight surrogate");
85+
}
7886

7987
println!("cargo:rustc-env=PROFILE={}", profile);
80-
let surrogate_binary_dir = std::path::PathBuf::from(&target_dir).join(profile);
88+
let surrogate_binary_dir = std::path::PathBuf::from(&target_dir)
89+
.join(&target_triple)
90+
.join(profile);
8191

8292
println!(
8393
"cargo:rustc-env=HYPERLIGHT_SURROGATE_DIR={}",

0 commit comments

Comments
 (0)