diff options
author | Jonathan Schwender <55576758+jschwe@users.noreply.github.com> | 2024-06-15 00:38:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-14 22:38:53 +0000 |
commit | 19067366df28c9131dcbc436bc96a27e64e0a194 (patch) | |
tree | d09fbdccfecdf6631b3887317c64e6d67e431d2b | |
parent | 33701464900ef00dc9a11a0304b753b8ae66464e (diff) | |
download | servo-19067366df28c9131dcbc436bc96a27e64e0a194.tar.gz servo-19067366df28c9131dcbc436bc96a27e64e0a194.zip |
Fix cross-compiling servoshell on Mac hosts (#32504)
`#[cfg(target_os = "xxx")]` when used in build scripts checks which
platform the **build script** is compiled for - i.e. the Host OS.
Since ware interested in the actual target os, we need to read
`CARGO_CFG_TARGET_OS`, a value that is set at **runtime of the build
script**.
Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
-rw-r--r-- | ports/servoshell/Cargo.toml | 4 | ||||
-rw-r--r-- | ports/servoshell/build.rs | 30 |
2 files changed, 19 insertions, 15 deletions
diff --git a/ports/servoshell/Cargo.toml b/ports/servoshell/Cargo.toml index f465ca186b0..fb28678d80d 100644 --- a/ports/servoshell/Cargo.toml +++ b/ports/servoshell/Cargo.toml @@ -20,13 +20,11 @@ bench = false [build-dependencies] vergen = { version = "8.3.1", features = ["git", "git2"] } +cc = "1.0" [target.'cfg(windows)'.build-dependencies] winres = "0.1" -[target.'cfg(target_os = "macos")'.build-dependencies] -cc = "1.0" - [package.metadata.winres] FileDescription = "Servo" LegalCopyright = "© The Servo Project Developers" diff --git a/ports/servoshell/build.rs b/ports/servoshell/build.rs index 961e30ba36e..ae6a1cacaa8 100644 --- a/ports/servoshell/build.rs +++ b/ports/servoshell/build.rs @@ -21,15 +21,21 @@ fn main() -> Result<(), Box<dyn Error>> { println!("cargo:rustc-cfg=servo_do_not_use_in_production"); } - #[cfg(windows)] - { - let mut res = winres::WindowsResource::new(); - res.set_icon("../../resources/servo.ico"); - res.set_manifest_file("platform/windows/servo.exe.manifest"); - res.compile().unwrap(); - } - #[cfg(target_os = "macos")] - { + // Note: We can't use `#[cfg(windows)]`, since that would check the host platform + // and not the target platform + let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap(); + + if target_os == "windows" { + #[cfg(windows)] + { + let mut res = winres::WindowsResource::new(); + res.set_icon("../../resources/servo.ico"); + res.set_manifest_file("platform/windows/servo.exe.manifest"); + res.compile().unwrap(); + } + #[cfg(not(windows))] + panic!("Cross-compiling to windows is currently not supported"); + } else if target_os == "macos" { cc::Build::new() .file("platform/macos/count_threads.c") .compile("count_threads"); @@ -50,8 +56,8 @@ fn main() -> Result<(), Box<dyn Error>> { // On MacOS, all dylib dependencies are shipped along with the binary // in the "/lib" directory. Setting the rpath here, allows the dynamic // linker to locate them. See `man dyld` for more info. - #[cfg(target_os = "macos")] - println!("cargo:rustc-link-arg=-Wl,-rpath,@executable_path/lib/"); - + if target_os == "macos" { + println!("cargo:rustc-link-arg=-Wl,-rpath,@executable_path/lib/"); + } Ok(()) } |