Skip to content

Commit

Permalink
avoid [&OsStr]::join for rust version compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewwhitehead committed Mar 23, 2023
1 parent ded3ab3 commit eafb6ee
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -330,16 +330,15 @@ 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::<Vec<_>>().join(OsStr::new(" ")),
);
configure.env("ARFLAGS", join_args(ar.get_args()));
}
let ranlib = cc.get_ranlib();
// OpenSSL does not support RANLIBFLAGS. Jam the flags in RANLIB.
let mut args = vec![ranlib.get_program()];
args.extend(ranlib.get_args());
configure.env("RANLIB", args.join(OsStr::new(" ")));
if ranlib.get_args().count() != 0 {
// OpenSSL does not support RANLIBFLAGS. Jam the flags in RANLIB.
let rancmd =
IntoIterator::into_iter([ranlib.get_program()]).chain(ranlib.get_args());
configure.env("RANLIB", join_args(rancmd));
}

// Make sure we pass extra flags like `-ffunction-sections` and
// other things like ARM codegen flags.
Expand Down Expand Up @@ -562,6 +561,17 @@ fn apply_patches_musl(target: &str, inner: &Path) {
fs::write(path, buf).unwrap();
}

fn join_args<'a>(args: impl Iterator<Item = &'a OsStr>) -> 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();
Expand Down

0 comments on commit eafb6ee

Please sign in to comment.