From 59461f577c356f685ff398bb9d8b5128dbb9fedd Mon Sep 17 00:00:00 2001 From: "Kirill A. Korinsky" Date: Tue, 8 Feb 2022 04:07:30 +0100 Subject: [PATCH] Introduced support of `MACPORTS_LEGACY_SUPPORT_*` MacPorts defines `MACPORTS_LEGACY_SUPPORT_ENABLED` with value `1` when port should link against LegacySupport. Rust doesn't care about include path, but `MACPORTS_LEGACY_SUPPORT_LDFLAGS` is a good source path and name for a library to link. --- library/std/build.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/library/std/build.rs b/library/std/build.rs index a14ac63c7a..f481ffd176 100644 --- a/library/std/build.rs +++ b/library/std/build.rs @@ -1,6 +1,23 @@ use std::env; fn main() { + 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 contains library name") + } + println!("cargo:rustc-link-lib=static={}", name); + } + println!("cargo:rerun-if-changed=build.rs"); let target = env::var("TARGET").expect("TARGET was not set"); if target.contains("freebsd") { -- 2.37.2