Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Ignore CARGO_BUILD_TARGET in tests #1010

Merged
merged 3 commits into from
Oct 28, 2024
Merged

Fix: Ignore CARGO_BUILD_TARGET in tests #1010

merged 3 commits into from
Oct 28, 2024

Conversation

bryango
Copy link
Contributor

@bryango bryango commented Oct 11, 2024

Related: NixOS/nixpkgs#298108

When build target triples are explicitly specified, the layout of the target directory is changed from target/... to target/<triple>/.... See: https://doc.rust-lang.org/cargo/guide/build-cache.html. This caused bin tests failures in tests/profile.rs.

For example, in nixpkgs CARGO_BUILD_TARGET is automatically set up, and we observe the following test failures:

rust-cbindgen>      Running tests/profile.rs (target/x86_64-unknown-linux-gnu/release/deps/profile-fec32decafabbade)
rust-cbindgen> running 3 tests
rust-cbindgen> test bin_explicit_release_build ... FAILED
rust-cbindgen> test bin_explicit_debug_build ... FAILED
rust-cbindgen> test bin_default_uses_debug_build ... FAILED
rust-cbindgen> failures:
rust-cbindgen> ---- bin_explicit_release_build stdout ----
rust-cbindgen> thread 'bin_explicit_release_build' panicked at tests/profile.rs:99:5:
rust-cbindgen> assertion `left == right` failed
rust-cbindgen>   left: ["release", "x86_64-unknown-linux-gnu"]
rust-cbindgen>  right: ["release"]
rust-cbindgen> note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
rust-cbindgen> ---- bin_explicit_debug_build stdout ----
rust-cbindgen> thread 'bin_explicit_debug_build' panicked at tests/profile.rs:93:5:
rust-cbindgen> assertion `left == right` failed
rust-cbindgen>   left: ["debug", "x86_64-unknown-linux-gnu"]
rust-cbindgen>  right: ["debug"]
rust-cbindgen> ---- bin_default_uses_debug_build stdout ----
rust-cbindgen> thread 'bin_default_uses_debug_build' panicked at tests/profile.rs:87:5:
rust-cbindgen> assertion `left == right` failed
rust-cbindgen>   left: ["debug", "x86_64-unknown-linux-gnu"]
rust-cbindgen>  right: ["debug"]
rust-cbindgen> failures:
rust-cbindgen>     bin_default_uses_debug_build
rust-cbindgen>     bin_explicit_debug_build
rust-cbindgen>     bin_explicit_release_build
rust-cbindgen> test result: FAILED. 0 passed; 3 failed; 0 ignored; 0 measured; 3 filtered out; finished in 0.59s
rust-cbindgen> error: test failed, to rerun pass `--test profile`

See: NixOS/nixpkgs#298108 (comment)

This patch proposes that we simply ignore the CARGO_BUILD_TARGET env var in tests to avoid such problems. A new test is introduced to ensure the correct behavior.

When build target triples are explicitly specified, the layout of the
target directory is changed from `target/...` to `target/<triple>/...`.

See: https://doc.rust-lang.org/cargo/guide/build-cache.html

This caused bin tests failures in `tests/profile.rs`. This patch
proposes that we simply ignore the `CARGO_BUILD_TARGET` env var in
tests to avoid such problems.

A new test is introduced to ensure the correct behavior.
Copy link
Collaborator

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks sensible.

This follows from the previous commit. It turns out that
`std::env::set_var` is unsafe: the `set_var` in bin tests leaked
through the threads and caused `lib` tests to fail.

To mitigate this problem we simply remove the `CARGO_BUILD_TARGET`
variable in lib tests as well. This also improves correctness.
Meanwhile we put `std::env::set_var` and `remove_var` in unsafe blocks
as it would be required by Rust 2024.
@bryango bryango marked this pull request as ready for review October 12, 2024 03:48
@bryango
Copy link
Contributor Author

bryango commented Oct 12, 2024

New commit: it turns out that std::env::set_var is unsafe: the set_var in bin tests in tests/profile.rs leaked through the threads and caused lib tests to fail.

To mitigate this problem we simply remove the CARGO_BUILD_TARGET variable in lib tests as well. This also improves correctness. Meanwhile we put std::env::set_var and remove_var in unsafe blocks as would be required by Rust 2024.

@bryango bryango requested a review from emilio October 14, 2024 10:54
@bryango
Copy link
Contributor Author

bryango commented Oct 14, 2024

Friendly ping @emilio for re-review 😆

Copy link
Collaborator

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, looks good with #[serial] added, thanks!

tests/profile.rs Show resolved Hide resolved
tests/profile.rs Outdated Show resolved Hide resolved
... also remove an unnecessary `assert`.
@bryango
Copy link
Contributor Author

bryango commented Oct 28, 2024

Indeed, thank you very much! Fixed in a new commit, awaiting CI!

@bryango bryango requested a review from emilio October 28, 2024 09:13
Copy link
Collaborator

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@emilio emilio added this pull request to the merge queue Oct 28, 2024
Merged via the queue into mozilla:master with commit d8432db Oct 28, 2024
2 checks passed
@bryango
Copy link
Contributor Author

bryango commented Oct 30, 2024

Thank you very much for merging! By the way, when would you expect to have the next point release? This information will help us downstream (such as nixpkgs) decide whether to update the patch or just wait for the next release 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants