Skip to content

Commit

Permalink
ndk-build: Switch NDK r23 -lgcc workaround to `CARGO_ENCODED_RUSTFLAG…
Browse files Browse the repository at this point in the history
…S` env var for paths with spaces

On Windows, user paths usually include people's full name, with a space.
If they check out a git repository under this name `cargo` fails to
parse the workaround path:

    process didn't exit successfully: `rustc - --crate-name ___ --print=file-names -L '"C:\Users\Bla' 'Haj\Desktop\Breda\target\cargo-apk-temp-extra-link-libraries"' ... (exit code: 1)

As per the [documentation for `RUSTFLAGS`] it is split by a very simple
`.split(" ")` argument without caring for quotation delimiters or escape
characters. To retain backwards compatibility this has been implemented
in a new environment variable named `CARGO_ENCODED_RUSTFLAGS`, which
separates by ASCII Unit Separators (`0x1f`)instead.

[documentation for `RUSTFLAGS`]: https://doc.rust-lang.org/cargo/reference/environment-variables.html
  • Loading branch information
EmilioLaiso committed Jun 16, 2022
1 parent 60e34d1 commit b53978c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions ndk-build/src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,21 @@ pub fn cargo_ndk(
// forwarded to the final compiler invocation rendering our workaround ineffective.
// The cargo page documenting this discrepancy (https://doc.rust-lang.org/cargo/commands/cargo-rustc.html)
// suggests to resort to RUSTFLAGS, which are updated below:
let mut rustflags = match std::env::var("RUSTFLAGS") {
let mut rustflags = match std::env::var("CARGO_ENCODED_RUSTFLAGS") {
Ok(val) => val,
Err(std::env::VarError::NotPresent) => "".to_string(),
Err(std::env::VarError::NotUnicode(_)) => {
panic!("RUSTFLAGS environment variable contains non-unicode characters")
}
};
rustflags += " -L ";
if !rustflags.is_empty() {
rustflags.push('\x1f');
}
rustflags += "-L\x1f";
rustflags += cargo_apk_link_dir
.to_str()
.expect("Target dir must be valid UTF-8");
cargo.env("RUSTFLAGS", rustflags);
cargo.env("CARGO_ENCODED_RUSTFLAGS", rustflags);
}

Ok(cargo)
Expand Down

0 comments on commit b53978c

Please sign in to comment.