Skip to content

Commit dee44af

Browse files
committed
Use the os from the target triple, rather than Rust's nickname
1 parent 2f36cde commit dee44af

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

build.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ fn switch(configure: &mut Command, feature: &str, name: &str) {
189189
configure.arg(arg.to_string() + name);
190190
}
191191

192-
fn build() -> io::Result<()> {
192+
fn build(target_os: &str) -> io::Result<()> {
193193
let source_dir = source();
194194

195195
// Command's path is not relative to command's current_dir
@@ -217,10 +217,7 @@ fn build() -> io::Result<()> {
217217
"--arch={}",
218218
env::var("CARGO_CFG_TARGET_ARCH").unwrap()
219219
));
220-
configure.arg(format!(
221-
"--target_os={}",
222-
env::var("CARGO_CFG_TARGET_OS").unwrap()
223-
));
220+
configure.arg(format!("--target_os={}", target_os));
224221
}
225222

226223
// control debug build
@@ -379,6 +376,18 @@ fn build() -> io::Result<()> {
379376
Ok(())
380377
}
381378

379+
fn os_from_triple(triple: &str) -> &str {
380+
let platform = triple.splitn(2, '-').nth(1).expect("bad triple");
381+
platform
382+
.trim_start_matches("unknown-")
383+
.trim_start_matches("pc-")
384+
.trim_start_matches("wrs-")
385+
.trim_start_matches("uwp-")
386+
.split('-')
387+
.next()
388+
.unwrap()
389+
}
390+
382391
#[cfg(not(target_env = "msvc"))]
383392
fn try_vcpkg(_statik: bool) -> Option<Vec<PathBuf>> {
384393
None
@@ -633,7 +642,8 @@ fn link_to_libraries(statik: bool, target_os: &str) {
633642

634643
fn main() {
635644
let statik = env::var("CARGO_FEATURE_STATIC").is_ok();
636-
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
645+
let target = env::var("TARGET").unwrap();
646+
let target_os = os_from_triple(&target); // it's different than Rust's target_os! but ./configure likes these better
637647

638648
let include_paths: Vec<PathBuf> = if env::var("CARGO_FEATURE_BUILD").is_ok() {
639649
println!(
@@ -644,7 +654,7 @@ fn main() {
644654
if fs::metadata(&search().join("lib").join("libavutil.a")).is_err() {
645655
fs::create_dir_all(&output()).expect("failed to create build directory");
646656
fetch().unwrap();
647-
build().unwrap();
657+
build(&target_os).unwrap();
648658
}
649659

650660
// Check additional required libraries.
@@ -730,7 +740,7 @@ fn main() {
730740
.include_paths
731741
};
732742

733-
if statik && target_os == "macos" {
743+
if statik && target_os == "darwin" {
734744
let frameworks = vec![
735745
"AppKit",
736746
"AudioToolbox",

0 commit comments

Comments
 (0)