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

cargo test with a proc_macro tries to run a host test on the target #4336

Open
tkilbourn opened this issue Jul 28, 2017 · 5 comments
Open

cargo test with a proc_macro tries to run a host test on the target #4336

tkilbourn opened this issue Jul 28, 2017 · 5 comments
Labels
Command-test S-triage Status: This issue is waiting on initial triage.

Comments

@tkilbourn
Copy link

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)

  1. Install a cross-compiler (e.g., on ubuntu trusty: apt-get install libc6-dev-arm64-cross gcc-aarch64-linux-gnu)
  2. Install qemu (ubuntu trusty: apt-get install qemu-user-static)
  3. Set a linker and runner for the target in ~/.cargo/config:
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
runner = "qemu-aarch64-static -L /usr/aarch64-linux-gnu"

Repro

cd proc-macro-test-derive
cargo test --target aarch64-unknown-linux-gnu

This will attempt to run target/debug/deps/proc_macro_test_derive-1f6a3cff88feb964, which is compiled for the host rather than the target. When cargo test is run without a --target, this (empty) test succeeds and the intended test target/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

@alexcrichton
Copy link
Member

Ah yeah I think, like doctests, we need to just disable unit tests on proc-macro crates for cross-compiled situations.

@rtsuk
Copy link

rtsuk commented Jul 28, 2017

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.

@alexcrichton
Copy link
Member

Hm true! Although I'd imagine that's covered by cargo test, right?

@rtsuk
Copy link

rtsuk commented Jul 28, 2017

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.

@alexcrichton
Copy link
Member

Ah sorry I think I misinterpreted!

bors added a commit that referenced this issue Sep 29, 2020
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.
@epage epage added the S-triage Status: This issue is waiting on initial triage. label Oct 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Command-test S-triage Status: This issue is waiting on initial triage.
Projects
Status: No status
Development

No branches or pull requests

4 participants