cuviper / autocfg

Automatic cfg for Rust compiler features
Apache License 2.0
95 stars 24 forks source link

Try to determine if --target was passed to Cargo #25

Closed adamreichold closed 4 years ago

adamreichold commented 4 years ago

This checks the output directory for the $CARGO_TARGET_DIR/$TARGET pattern making use of MAIN_SEPARATOR to try to handle Windows. It will also fail if either the path or that pattern are not valid UFT-8, but it will then fall back to the current behavior. (So this basically tries to implement https://github.com/cuviper/autocfg/pull/10#issuecomment-527575030.)

adamreichold commented 4 years ago

Out of curiosity, does this solve any real-world problems for you? If so, can you describe that?

Yes, we just changed the atomic crate to use autocfg to probe for the availability of the Atomic{U,I}{8,16,32,64,128} in core. For amd64, one needs to set RUSTFLAGS=-Ctarget-feature=+cx16 -Zcrate-attr=feature(integer_atomics) to get access to the Atomic{U,I}128 types which is currently not possible as this is not a cross build scenario w.r.t. the current definition even if --target is given explicitly and hence we had to resort to build for AArch64 to test this.

adamreichold commented 4 years ago

@cuviper Just a friendly ping if there is anything that still needs to be changed here?

cuviper commented 4 years ago

This looks good, although I wish we had a test. I'm not sure how we would do that though -- maybe a workspace crate that can use a real build script, driving with and without --target in the CI script?

I hope you have at least verified that it works in your scenario?

adamreichold commented 4 years ago

I hope you have at least verified that it works in your scenario?

Yes, I have checked that this allows me to pass RUSTFLAGS into the probes using cargo --target ${HOST} but ...

This looks good, although I wish we had a test. I'm not sure how we would do that though -- maybe a workspace crate that can use a real build script, driving with and without --target in the CI script?

... I will add a unit test by factoring out the detection logic. I think the direct feedback during development is more important than the accuracy of testing an actual Cargo invocation.

cuviper commented 4 years ago

I think the direct feedback during development is more important than the accuracy of testing an actual Cargo invocation.

Fair -- I probably lean too often on black-box testing.

cuviper commented 4 years ago

Thanks! I'll go ahead and publish 1.0.1 from here.

bors r+

bors[bot] commented 4 years ago

Build succeeded: