Skip to content

Commit

Permalink
Introduced support of MACPORTS_LEGACY_SUPPORT_*
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
catap committed Jul 17, 2022
1 parent e05775b commit 59461f5
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions library/std/build.rs
Original file line number Diff line number Diff line change
@@ -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") {
Expand Down

0 comments on commit 59461f5

Please sign in to comment.