Skip to content

Regression: Trybuild doesn't pass on --target, even when needed #122

Description

@hannobraun

We're using Trybuild in LPC8xx HAL. We have a .cargo/config.toml there that sets the target to thumbv6m-none-eabi.

We override the target to run the Trybuild tests using --target in our build script (specifically these lines). This works perfectly with Trybuild 1.0.43 (and earlier), but fails with Trybuild 1.0.44:

     Running `/home/hanno/Projects/lpc-rs/lpc8xx-hal/target/x86_64-unknown-linux-gnu/debug/deps/compiletest-a70653e23af66043`

running 1 test
    Checking lpc8xx-hal-tests v0.0.0 (/home/hanno/Projects/lpc-rs/lpc8xx-hal/target/tests/lpc8xx-hal)
error[E0463]: can't find crate for `std`
  |
  = note: the `thumbv6m-none-eabi` target may not support the standard library
  = note: `std` is required by `lpc8xx_hal_tests` because it does not declare `#![no_std]`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: could not compile `lpc8xx-hal-tests`

To learn more, run the command again with --verbose.
test compile_test ... FAILED

failures:

---- compile_test stdout ----
thread 'compile_test' panicked at 'tests failed', /home/hanno/.cargo/registry/src/github.com-1ecc6299db9ec823/trybuild-1.0.44/src/run.rs:51:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    compile_test

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.40s

This error indicates that --target didn't take, and that the target from .cargo/config.toml is used.

#121 seems to be the culprit here. I think the code it added wrongly assumes that Trybuild doesn't need to pass --target, if the --target it receives is the same as the host. This is not true, if --target is used to override a target set in .cargo/config.toml/.cargo/config.

cc @taiki-e, @dtolnay

Activity

  1. changed the title [-]Regression: Trybuild doesn't respect `--target` in LPC8xx HAL build[/-] [+]Regression: Trybuild doesn't pass on `--target`, even when needed[/+] on Aug 10, 2021
  2. dtolnay commented on Aug 10, 2021

    @dtolnay
    Owner

    Thanks -- sorry about the breakage. I've yanked 1.0.44 until someone can send a fix.

  3. hannobraun commented on Aug 10, 2021

    @hannobraun
    ContributorAuthor

    No worries! Thank you for addressing this so quickly!

  4. taiki-e commented on Aug 10, 2021

    @taiki-e
    Contributor

    Sorry for the breakage! It seems the heuristic using RUSTFLAGS was not enough.

    On lpc-rs/lpc8xx-hal, If rustflags is not set, it will succeed.

    cargo +stable test +stable --features 82x,no-target-warning,trybuild --target x86_64-apple-darwin
    

    If rustflags is set, it will fail.

    RUSTFLAGS="-D warnings" cargo +stable test --features 82x,no-target-warning,trybuild --target x86_64-apple-darwin
    

    Therefore, it seems that my understanding here was incorrect (not only CARGO_ENCODED_RUSTFLAGS, but also RUSTFLAGS seems to have the same nature):

    trybuild/build.rs

    Lines 28 to 31 in 0b33c0b

    // - CARGO_ENCODED_RUSTFLAGS, which was introduced in rust-lang/cargo#9601,
    // cannot be used for this purpose because it contains the value of
    // RUSTFLAGS even if --target is passed and the host and target triples
    // are the same.

  5. taiki-e commented on Aug 10, 2021

    @taiki-e
    Contributor

    The best way for this seems to be rust-lang/cargo#9532, but it may take quite a while before it is merged.

  6. taiki-e commented on Aug 10, 2021

    @taiki-e
    Contributor

    #123 is not a perfect approach for this because it cannot detect automatically, but it is enough for #115 and #121's use cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions