diff --git a/src/lib.rs b/src/lib.rs index 95a4052d..d91c57a4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ extern crate cc; use std::env; -use std::ffi::OsStr; +use std::ffi::{OsStr, OsString}; use std::fs; use std::path::{Path, PathBuf}; use std::process::Command; @@ -330,19 +330,13 @@ impl Build { // On some platforms (like emscripten on windows), the ar to use may not be a // single binary, but instead a multi-argument command like `cmd /c emar.bar`. // We can't convey that through `AR` alone, and so also need to set ARFLAGS. - configure.env( - "ARFLAGS", - ar.get_args().collect::>().join(OsStr::new(" ")), - ); + configure.env("ARFLAGS", join_args(ar.get_args())); } let ranlib = cc.get_ranlib(); configure.env("RANLIB", ranlib.get_program()); if ranlib.get_args().count() == 0 { // Same thing as for AR -- we may need to set RANLIBFLAGS - configure.env( - "RANLIBFLAGS", - ranlib.get_args().collect::>().join(OsStr::new(" ")), - ); + configure.env("RANLIBFLAGS", join_args(ranlib.get_args())); } // Make sure we pass extra flags like `-ffunction-sections` and @@ -566,6 +560,17 @@ fn apply_patches_musl(target: &str, inner: &Path) { fs::write(path, buf).unwrap(); } +fn join_args<'a>(args: impl Iterator) -> OsString { + let mut output = OsString::new(); + for arg in args { + if !output.is_empty() { + output.push(" "); + } + output.push(arg); + } + output +} + fn sanitize_sh(path: &Path) -> String { if !cfg!(windows) { return path.to_str().unwrap().to_string();