Avoid clang wrapper scripts and pass --target instead #106
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm just sharing this as a draft PR to show another attempt at solving #92 based on the approach currently used in
ndk-build
, but as you can see from the description below this actually ends up being a lot more complex that it appears on the surface. I tried to even jump the extra hurdles to parse the cargo config files to read configured rustflags but I think this approach would be too fragile to adopt. Notably, for my own use case this solution doesn't work because our project configures rustflags via.cargo/config.toml
, includingtarget.<cfg>.rustflags
which are the the most problematic to handle hereCc: @MarijnS95
--
This is an alternative fix for #92 that avoids hitting command line length limitations and avoids needing to use
cargo-ndk
as a spring board for runningclang
, which avoids needing temporary hard links or copying thecargo-ndk
binary to the target/ directory.This takes a similar approach to
ndk-build
here: rust-mobile/ndk#306 but also tries to be more thorough with reading configured rustflags.Although this solution initially looked like it would be much simpler it soon became apparent that for it to work reliably it needs to be able to read the user's configured rustflags before adding the required
-Clink-arg=--target
rustflag (otherwise we would potentially discard rustflags needed by the project).Unfortunately it turns out to be practically impossible to reliably read configured rustflags from outside cargo!
Rustflags are read by cargo from one of four, mutually-exclusive, places:
(cargo also supports --config command line options that can set these)
Although we can easily handle the first two environment variables, the second two involve:
This experimental patch handles the first two cases and by adding a dependency on the
cargo
crate will even attempt to handle the second two options, with these caveats: