--- a/library/std/build.rs +++ b/library/std/build.rs @@ -1,6 +1,39 @@ use std::env; fn main() { + // MacPorts Legacy Support for macOS < 10.12 + // Provides missing POSIX functions like clock_gettime, CLOCK_UPTIME_RAW, etc. + if env::var_os("MACPORTS_LEGACY_SUPPORT_ENABLED") + .map(|s| s.to_string_lossy() == "1") + .unwrap_or(false) + { + let str = env::var_os("MACPORTS_LEGACY_SUPPORT_LDFLAGS") + .map(|s| s.to_string_lossy().to_string()) + .expect("MACPORTS_LEGACY_SUPPORT_LDFLAGS shouldn't be empty"); + let (path, mut name) = str + .strip_suffix(".a") + .expect("MACPORTS_LEGACY_SUPPORT_LDFLAGS should be static library") + .split_at(str.rfind("/").unwrap_or(0)); + name = name.strip_prefix("/lib").unwrap_or(name); + if path.len() > 0 { + println!("cargo:rustc-link-search=native={}", path); + } + if name.len() == 0 { + panic!("MACPORTS_LEGACY_SUPPORT_LDFLAGS should contain library name") + } + println!("cargo:rustc-link-lib=static={}", name); + } + + // Emulated TLS support for macOS < 10.7 + // Compiles LLVM's emutls.c to provide __thread variable support + if cfg!(target_os = "macos") && cfg!(target_enforce_emulated_tls) { + let mut emutls_cfg = cc::Build::new(); + emutls_cfg.warnings(false); + emutls_cfg + .file("../../src/llvm-project/compiler-rt/lib/builtins/emutls.c") + .compile("emutls"); + } + println!("cargo:rerun-if-changed=build.rs"); let target = env::var("TARGET").expect("TARGET was not set");