Do not pass --target if user is not using --target #121
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.
When
--target
flag is passed, cargo does not passRUSTFLAGS
to rustc when building proc-macro and build script even if the host and target triples are the same. Therefore, if we always pass--target
to cargo, tools such as coverage that requireRUSTFLAGS
do not work for tests run by trybuild.To avoid that problem, this patch change to not pass
--target
to cargo if we know that it has not been passed.Cargo does not have a way to tell the build script whether
--target
has been passed or not, so we use the following heuristic:RUSTFLAGS
is available when building the build script.Note that the second is when building, not when running. This is due to:
RUSTFLAGS
to the build script when running. (see also RUSTFLAGS is gone proc-macro2#293)CARGO_ENCODED_RUSTFLAGS
, which was introduced in Inform build scripts of rustc compiler context rust-lang/cargo#9601, cannot be used for this purpose because it contains the value ofRUSTFLAGS
even if --target is passed and the host and target triples are the same.Fixes #115
Tested with a case where using cargo-llvm-cov and a case where using llvm-cov directly without any third party tools. See taiki-e/cargo-llvm-cov#44 (comment) for one of the cases I actually tested.
I have not tested the other tools, but it is likely that they will need some change like taiki-e/cargo-llvm-cov#44 on their side.
I also tested a case of #90, with a way discripted in #90.