-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
cargo test with a proc_macro tries to run a host test on the target #4336
Comments
Ah yeah I think, like doctests, we need to just disable unit tests on proc-macro crates for cross-compiled situations. |
It it possible to run these tests on the host even when cross-compiling? Otherwise it seems like for crates that are only ever cross compiled these sorts of tests would never be run. |
Hm true! Although I'd imagine that's covered by |
If you can invoke cargo test on the host. For magenta-rs I don't think that will work, as the host won't have the shared library needed to link. One could certainly work around it with config so that your crate can compile and run some tests on the host, but if it isn't hard to tell when a test is intended for the host even when cross compiling it seems better to not use that custom runner for those tests. |
Ah sorry I think I misinterpreted! |
Properly set for_host for proc-macro tests. Proc-macro tests are currently forced to run for the host target (by [this line of code](https://github.com/rust-lang/cargo/blob/898ccde7ac867ecdb62184714b379c4328409399/src/cargo/ops/cargo_compile.rs#L819)). However, the code that builds the dependency graph wasn't playing by the same rules, and was building the proc-macro test as-if it was "not for_host". This would cause the proc-macro test to pull in the wrong set of dependencies/features with the new feature resolver. Forcing proc-macro tests to run on host isn't 100% required, since most targets have the proc_macro crate available. However, I feel like it simplifies things to build for-host. I was thinking we could relax that requirement, but I'm not really sure. See also #4336 where there's an bug if you do specify `--target`. Tested with the wasmtime repo running `cargo test -Zfeatures=all -p wiggle-macro` with `doctest = false` commented out of `crates/wiggle/macro/Cargo.toml`. Fixes #8563.
When I cross-compile the attached crate's "proc-macro-test-derive" subcrate, cargo attempts to run tests compiled for the host. (This crate attempts to mirror the layout of the rand and rand-derive crates, which is how I discovered the issue.)
Setup
Running rustc 1.19.0 (0ade33941 2017-07-17), cargo 0.20.0 (a60d185 2017-07-13)
apt-get install libc6-dev-arm64-cross gcc-aarch64-linux-gnu
)apt-get install qemu-user-static
)Repro
This will attempt to run
target/debug/deps/proc_macro_test_derive-1f6a3cff88feb964
, which is compiled for the host rather than the target. Whencargo test
is run without a --target, this (empty) test succeeds and the intended testtarget/debug/deps/macros-659b3b1ec96599d4
is run.For --target aarch64-unknown-linux-gnu, I expect
target/aarch64-unknown-linux-gnu/debug/macros-da045a5e3c0e63ff
to be run.proc-macro-test.zip
The text was updated successfully, but these errors were encountered: