@@ -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