mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Fixes the following warning: ``` warning: servoshell@0.0.1: Could not generate git version information: "dyld[59398]: Symbol not found: _libintl_setlocale\n Referenced from: <CB4FE7B2-A5DC-34F0-8247-A96F45D664E8> /opt/homebrew/Cellar/git/2.48.1/bin/git\n Expected in: <0DA2D46D-7A17-3860-809D-71FD05B785FA> /Library/Frameworks/GStreamer.framework/Versions/1.0/lib/libintl.8.dylib\n" ``` This was discussed in https://github.com/servo/servo/issues/36435#issuecomment-2794224073. mach sets DYLD_LIBRARY_PATH, which is currently necessary for our unit tests, but causes git to fail in the build script. Simply unsetting the environment variable before invoking git works around this problem. Testing: Tested manually on macos and verified the warning does not occur anymore. Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
98 lines
3.9 KiB
Rust
98 lines
3.9 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
use std::error::Error;
|
|
use std::fs::File;
|
|
use std::io::Write;
|
|
use std::path::Path;
|
|
use std::process::Command;
|
|
|
|
fn git_sha() -> Result<String, String> {
|
|
let output = Command::new("git")
|
|
.args(["rev-parse", "--short", "HEAD"])
|
|
// on macos mach sets DYLD_LIBRARY_PATH since it is needed for unit-tests, but it
|
|
// causes git to fail, so we remove it for the git invocation.
|
|
.env_remove("DYLD_LIBRARY_PATH")
|
|
.output()
|
|
.map_err(|e| e.to_string())?;
|
|
if output.status.success() {
|
|
let hash = String::from_utf8(output.stdout).map_err(|e| e.to_string())?;
|
|
Ok(hash.trim().to_owned())
|
|
} else {
|
|
let stderr = String::from_utf8(output.stderr).map_err(|e| e.to_string())?;
|
|
Err(stderr)
|
|
}
|
|
}
|
|
|
|
fn main() -> Result<(), Box<dyn Error>> {
|
|
println!("cargo::rustc-check-cfg=cfg(servo_production)");
|
|
println!("cargo::rustc-check-cfg=cfg(servo_do_not_use_in_production)");
|
|
// Cargo does not expose the profile name to crates or their build scripts,
|
|
// but we can extract it from OUT_DIR and set a custom cfg() ourselves.
|
|
let out = std::env::var("OUT_DIR")?;
|
|
let out = Path::new(&out);
|
|
let krate = out.parent().unwrap();
|
|
let build = krate.parent().unwrap();
|
|
let profile = build
|
|
.parent()
|
|
.unwrap()
|
|
.file_name()
|
|
.unwrap()
|
|
.to_string_lossy();
|
|
if profile == "production" || profile.starts_with("production-") {
|
|
println!("cargo:rustc-cfg=servo_production");
|
|
} else {
|
|
println!("cargo:rustc-cfg=servo_do_not_use_in_production");
|
|
}
|
|
|
|
// 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" {
|
|
println!("cargo:rerun-if-changed=platform/macos/count_threads.c");
|
|
cc::Build::new()
|
|
.file("platform/macos/count_threads.c")
|
|
.compile("count_threads");
|
|
} else if target_os == "android" {
|
|
// FIXME: We need this workaround since jemalloc-sys still links
|
|
// to libgcc instead of libunwind, but Android NDK 23c and above
|
|
// don't have libgcc. We can't disable jemalloc for Android as
|
|
// in 64-bit aarch builds, the system allocator uses tagged
|
|
// pointers by default which causes the assertions in SM & mozjs
|
|
// to fail. See https://github.com/servo/servo/issues/32175.
|
|
let mut libgcc = File::create(out.join("libgcc.a")).unwrap();
|
|
libgcc.write_all(b"INPUT(-lunwind)").unwrap();
|
|
println!("cargo:rustc-link-search=native={}", out.display());
|
|
}
|
|
|
|
match git_sha() {
|
|
Ok(hash) => println!("cargo:rustc-env=GIT_SHA={}", hash),
|
|
Err(error) => {
|
|
println!(
|
|
"cargo:warning=Could not generate git version information: {:?}",
|
|
error
|
|
);
|
|
println!("cargo:rustc-env=GIT_SHA=nogit");
|
|
},
|
|
}
|
|
|
|
// 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.
|
|
if target_os == "macos" {
|
|
println!("cargo:rustc-link-arg=-Wl,-rpath,@executable_path/lib/");
|
|
}
|
|
Ok(())
|
|
}
|