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

Some RUSTFLAGS Force Cargo Use on the Host #903

Closed
2 of 11 tasks
Alexhuszagh opened this issue Jul 2, 2022 · 4 comments · Fixed by #904
Closed
2 of 11 tasks

Some RUSTFLAGS Force Cargo Use on the Host #903

Alexhuszagh opened this issue Jul 2, 2022 · 4 comments · Fixed by #904
Assignees
Labels

Comments

@Alexhuszagh
Copy link
Contributor

Alexhuszagh commented Jul 2, 2022

Checklist

Describe your issue

Attempting to run the following causes cross to assume that we do not need docker support, and therefore fallback to the host:

$ CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUSTFLAGS="-Zsanitizer=leak" \
    cross +nightly build --target aarch64-unknown-linux-gnu -Z build-std -vv
+ cargo metadata --format-version 1 --filter-platform aarch64-unknown-linux-gnu                                                                                                                     
Warning: Falling back to `cargo` on the host.                                                                                                                                                       
+ cargo +nightly build --target aarch64-unknown-linux-gnu -Z build-std -vv                                                                                                                          
   Compiling compiler_builtins v0.1.73

I believe this affects every image. Not every rustflag however affects this: only unstable -Z flags are affected. For example, this works:

$  CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUSTFLAGS="-C panic=abort" \
    cross +nightly build --target aarch64-unknown-linux-gnu -Z build-std -vv

Note that this does not occur when using cross rustc and passing the options: the following works as expected:

$ cross +nightly rustc --target x86_64-unknown-linux-gnu -- -Zself-profile -Zsanitizer=leak

What target(s) are you cross-compiling for?

aarch64-unknown-linux-gnu

Which operating system is the host (e.g computer cross is on) running?

  • macOS
  • Windows
  • Linux / BSD
  • other OS (specify in description)

What architecture is the host?

  • x86_64 / AMD64
  • arm32
  • arm64 (including Mac M1)

What container engine is cross using?

  • docker
  • podman
  • other container engine (specify in description)

cross version

cross 0.2.2 and latest main

Example

No response

Additional information / notes

This affected cross prior to #869 being merged, so this is not related to that.

@Alexhuszagh
Copy link
Contributor Author

Alexhuszagh commented Jul 2, 2022

The issue relates to cargo_metadata_with_args not returning, likely because it does not use the current channel. A solution would be to ensure the channel is passed to cargo.

Update: that's exactly the issue:

$ CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUSTFLAGS="-Zself-profile" cargo metadata --format-version 1 --filter-platform aarch64-unknown-linux-gnu
error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `rustc - --crate-name ___ --print=file-names -Zself-profile --target aarch64-unknown-linux-gnu --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=cfg` (exit status: 1)
  --- stderr
  error: the option `Z` is only accepted on the nightly compiler

We should also likely print stderr getting cargo metadata fails.

@Emilgardis
Copy link
Member

There's a nice little todo for that here

// TODO: logging

shell::warning should work well for that, however it would mean two warnings when running cargo in current context/path would fail

@Alexhuszagh
Copy link
Contributor Author

Alexhuszagh commented Jul 2, 2022

I've added this code to replace the TODO, so we have good logging: both the cargo metadata error and the cross warning:

    if !output.status.success() {
        shell::warn("unable to get metadata for package", msg_info)?;
        shell::status(String::from_utf8(output.stderr.clone())?, msg_info)?;
        return Ok(None);
    }

This produces output like the following:

CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUSTFLAGS="-Zself-profile" /home/ahuszagh/git/cross/target/debug/cross +nightly build --target aarch64-unknown-linux-gnu -vv
+ cargo +nightly metadata --format-version 1 --filter-platform aarch64-unknown-linux-gnu
[cross] warning: unable to get metadata for package
error: could not find `Cargo.toml` in `/home/ahuszagh/Desktop/cross` or any parent directory

[cross] note: Falling back to `cargo` on the host.
+ cargo +nightly build --target aarch64-unknown-linux-gnu -vv
error: could not find `Cargo.toml` in `/home/ahuszagh/Desktop/cross` or any parent directory

Unfortunately, this might duplicate the error output in some cases. Maybe we should suppress the logging, and just have the warning?

@Emilgardis
Copy link
Member

what about surpressing it when in normal verbosity, but keep it in verbose mode.

Also, should probably pretty format it with section (e.g use indented) to make it more distinct

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

Successfully merging a pull request may close this issue.

2 participants