Skip to content

Commit

Permalink
fix: Use better fix for macOS Catalina (#2)
Browse files Browse the repository at this point in the history
* Avoid use of undefined std::process::Command behavior

std::process::Command is known to be unpredictable when a relative path
is used together with `current_dir`, and outright fails on macOS
Catalina [0]. Absolutize paths before passing them to
std::process::Command to stay within the documented constraints of the
API.

[0]: rust-lang/rust#37868

* Revert "Fix build on macOS Catalina (#1)"

This reverts commit 9cb0245.

Signed-off-by: Alexander Rodin <[email protected]>
  • Loading branch information
a-rodin authored Oct 22, 2019
1 parent 9cb0245 commit 67ed830
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions rdkafka-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,21 @@ macro_rules! println_stderr(
} }
);

fn run_command_or_fail(dir: &str, cmd: &str, args: &[&str]) {
println_stderr!("Running command: \"{} {}\" in dir: {}", cmd, args.join(" "), dir);
fn run_command_or_fail<P>(dir: &str, cmd: P, args: &[&str])
where
P: AsRef<Path>,
{
let cmd = cmd.as_ref();
let cmd = if cmd.components().count() > 1 && cmd.is_relative() {
// If `cmd` is a relative path (and not a bare command that should be
// looked up in PATH), absolutize it relative to `dir`, as otherwise the
// behavior of std::process::Command is undefined.
// https://github.com/rust-lang/rust/issues/37868
PathBuf::from(dir).join(cmd).canonicalize().expect("canonicalization failed")
} else {
PathBuf::from(cmd)
};
println_stderr!("Running command: \"{} {}\" in dir: {}", cmd.display(), args.join(" "), dir);
let ret = Command::new(cmd).current_dir(dir).args(args).status();
match ret.map(|status| (status.success(), status.code())) {
Ok((true, _)) => { return },
Expand Down Expand Up @@ -109,7 +122,7 @@ fn build_librdkafka() {
}

println!("Configuring librdkafka");
run_command_or_fail("librdkafka", "sh", &[&["-c", "./configure"], configure_flags.as_slice()].concat());
run_command_or_fail("librdkafka", "./configure", configure_flags.as_slice());

println!("Compiling librdkafka");
make_librdkafka();
Expand Down

0 comments on commit 67ed830

Please sign in to comment.