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

-Zbuild-std is appended in the wrong position #1141

Closed
4 of 11 tasks
guihkx opened this issue Nov 19, 2022 · 5 comments · Fixed by #1142
Closed
4 of 11 tasks

-Zbuild-std is appended in the wrong position #1141

guihkx opened this issue Nov 19, 2022 · 5 comments · Fixed by #1142
Assignees
Labels
Milestone

Comments

@guihkx
Copy link
Contributor

guihkx commented Nov 19, 2022

Checklist

Describe your issue

Trying to pass extra arguments to clippy on a target with no std (x86_64-unknown-dragonfly, in my case), fails:

$ cross -v +nightly clippy --target x86_64-unknown-dragonfly -- -D warnings
+ cargo +nightly metadata --format-version 1 --filter-platform x86_64-unknown-dragonfly
+ rustc --print sysroot
+ /usr/bin/podman
+ /usr/bin/podman version -f '{{ .Server.Os }},,,{{ .Server.Arch }}'
+ /usr/bin/podman info -f '{{ .Version.OsArch }}'
+ rustup toolchain list
+ rustup target list --toolchain nightly-x86_64-unknown-linux-gnu
[cross] warning: using newer rustc `1.67.0-nightly (b833ad56f 2022-11-18)` for the target. Current active rustc on the host is `rustc 1.65.0 (897e37553 2022-11-02)`.
 > Update with `rustup update`
+ rustup component list --toolchain nightly-x86_64-unknown-linux-gnu
+ rustup component list --toolchain nightly-x86_64-unknown-linux-gnu
+ /usr/bin/podman run --userns host -e 'PKG_CONFIG_ALLOW_CROSS=1' -e 'XARGO_HOME=/home/gui/.xargo' -e 'CARGO_HOME=/home/gui/.local/share/cargo' -e 'CROSS_RUST_SYSROOT=/home/gui/.local/share/rustup/toolchains/nightly-x86_64-unknown-linux-gnu' -e 'CARGO_TARGET_DIR=/target' -e 'CROSS_RUNNER=' -e TERM -e 'USER=gui' -e 'CROSS_RUSTC_MAJOR_VERSION=1' -e 'CROSS_RUSTC_MINOR_VERSION=67' -e 'CROSS_RUSTC_PATCH_VERSION=0' --name cross-nightly-x86_64-unknown-linux-gnu-94e8e-b833ad56f-x86_64-unknown-dragonfly-ca725-1668874801982 --rm -v /home/gui/.xargo:/home/gui/.xargo:z -v /home/gui/.local/share/cargo:/home/gui/.local/share/cargo:z -v /home/gui/.local/share/cargo/bin -v /home/gui/dev/topgrade:/home/gui/dev/topgrade:z -v /home/gui/.local/share/rustup/toolchains/nightly-x86_64-unknown-linux-gnu:/home/gui/.local/share/rustup/toolchains/nightly-x86_64-unknown-linux-gnu:z,ro -v /home/gui/dev/topgrade/target:/target:z -w /home/gui/dev/topgrade -t ghcr.io/cross-rs/x86_64-unknown-dragonfly:main sh -c 'PATH="$PATH":"/home/gui/.local/share/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin" cargo -v clippy --target x86_64-unknown-dragonfly -- -D warnings -Zbuild-std'
error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `/home/gui/.local/share/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/clippy-driver rustc - --crate-name ___ --print=file-names --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: unknown unstable option: `build-std`

+ rustup component list --toolchain nightly-x86_64-unknown-linux-gnu
[cross] warning: rust-std is not available for x86_64-unknown-dragonfly
[cross] note: you may need to build components for the target via `-Z build-std=<components>` or in your cross configuration specify `target.x86_64-unknown-dragonfly.build-std`
              the available components are core, std, alloc, and proc_macro

I believe the issue is caused due to cross passing -Zbuild-std to clippy instead of cargo.

My Cross.toml:

[target.x86_64-unknown-dragonfly]
build-std = true

I've also tried without using Cross.toml, i.e. by setting RUSTFLAGS=-Zbuild-std manually, but I think I confused cross even further?

$ export RUSTFLAGS='-Zbuild-std'
$ cross -v +nightly clippy --target x86_64-unknown-dragonfly -- -D warnings
+ cargo +nightly metadata --format-version 1 --filter-platform x86_64-unknown-dragonfly
[cross] warning: unable to get metadata for package
        error: failed to run `rustc` to learn about target-specific information                Caused by:          process didn't exit successfully: `rustc - --crate-name ___ --print=file-names -Zbuild-std --target x86_64-unknown-dragonfly --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: unknown unstable option: `build-std`        
[cross] note: Falling back to `cargo` on the host.
+ cargo -v +nightly clippy --target x86_64-unknown-dragonfly -- -D warnings
error: no such subcommand: `+nightly`

	Cargo does not handle `+toolchain` directives.
	Did you mean to invoke `cargo` through `rustup` instead?

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

other (specify in description)

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.4 (6635e20 2022-11-16)

Example

git clone https://github.com/guihkx/topgrade.git -b ci-dragonfly
cd topgrade
cross -v +nightly clippy --target x86_64-unknown-dragonfly -- -D warnings

Additional information / notes

No response

@Alexhuszagh Alexhuszagh added this to the v0.3.0 milestone Nov 19, 2022
@Alexhuszagh
Copy link
Contributor

Related to #1049. We can probably have an additional_args, so we add it to args but not to additional_args and then append -Zbuild-std to args and add additional_args later.

@Alexhuszagh
Copy link
Contributor

This should be closed in #1142, if you'd like to test to ensure it works that would be wonderful. The above example now works for me:

$ cross -v +nightly clippy --target x86_64-unknown-dragonfly -- -D warnings
+ cargo +nightly metadata --format-version 1 --filter-platform x86_64-unknown-dragonfly
+ rustc --print sysroot
+ /usr/bin/docker
+ /usr/bin/docker version -f '{{ .Server.Os }},,,{{ .Server.Arch }}'
+ rustup toolchain list
+ rustup target list --toolchain nightly-x86_64-unknown-linux-gnu
[cross] warning: using newer rustc `1.67.0-nightly (6284998a2 2022-11-12)` for the target. Current active rustc on the host is `rustc 1.62.0 (a8314ef7d 2022-06-27)`.
 > Update with `rustup update`
+ rustup component list --toolchain nightly-x86_64-unknown-linux-gnu
+ rustup component list --toolchain nightly-x86_64-unknown-linux-gnu
+ /usr/bin/docker run --userns host -e 'PKG_CONFIG_ALLOW_CROSS=1' -e 'XARGO_HOME=/home/ahuszagh/.xargo' -e 'CARGO_HOME=/home/ahuszagh/.cargo' -e 'CROSS_RUST_SYSROOT=/home/ahuszagh/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu' -e 'CARGO_TARGET_DIR=/target' -e 'CROSS_RUNNER=' -e TERM -e 'USER=ahuszagh' -e 'CROSS_RUSTC_MAJOR_VERSION=1' -e 'CROSS_RUSTC_MINOR_VERSION=67' -e 'CROSS_RUSTC_PATCH_VERSION=0' --name cross-nightly-x86_64-unknown-linux-gnu-de1a6-6284998a2-x86_64-unknown-dragonfly-2a8a9-1668878982010 --rm --user 1000:1000 -v /home/ahuszagh/.xargo:/home/ahuszagh/.xargo:z -v /home/ahuszagh/.cargo:/home/ahuszagh/.cargo:z -v /home/ahuszagh/.cargo/bin -v /home/ahuszagh/Desktop/cross/hello:/home/ahuszagh/Desktop/cross/hello:z -v /home/ahuszagh/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu:/home/ahuszagh/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu:z,ro -v /home/ahuszagh/Desktop/cross/hello/target:/target:z -w /home/ahuszagh/Desktop/cross/hello -t ghcr.io/cross-rs/x86_64-unknown-dragonfly:main sh -c 'PATH="$PATH":"/home/ahuszagh/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin" cargo -v clippy --target x86_64-unknown-dragonfly -Zbuild-std -- -D warnings'
    Finished dev [unoptimized + debuginfo] target(s) in 0.16

So, the invoked command inside the container is now cargo -v clippy --target x86_64-unknown-dragonfly -Zbuild-std -- -D warnings.

@Alexhuszagh Alexhuszagh self-assigned this Nov 19, 2022
@guihkx
Copy link
Contributor Author

guihkx commented Nov 19, 2022

That was fast! And yeah, it worked perfectly for me as well. Thank you!

One question, is my second example incorrect? Because

$ RUSTFLAGS='-Zbuild-std' cross -v +nightly clippy --target x86_64-unknown-dragonfly -- -D warnings
+ cargo +nightly metadata --format-version 1 --filter-platform x86_64-unknown-dragonfly
[cross] warning: unable to get metadata for package
        error: failed to run `rustc` to learn about target-specific information                Caused by:          process didn't exit successfully: `rustc - --crate-name ___ --print=file-names -Zbuild-std --target x86_64-unknown-dragonfly --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: unknown unstable option: `build-std`        
[cross] note: Falling back to `cargo` on the host.
+ cargo -v +nightly clippy --target x86_64-unknown-dragonfly -- -D warnings
error: no such subcommand: `+nightly`

	Cargo does not handle `+toolchain` directives.
	Did you mean to invoke `cargo` through `rustup` instead?

Still fails...🤔

@Alexhuszagh
Copy link
Contributor

Yes it is invalid, I believe. -Z build-std is a cargo option, not a rustc one, and therefore it would be an unknown option. This also makes sense conceptually, since rustc is the raw compiler, not the package manager, so it has no real concept of "building" std: you can build it externally and provide a path to link to it, but that's outside of the scope of rustc.

https://doc.rust-lang.org/cargo/reference/unstable.html

@guihkx
Copy link
Contributor Author

guihkx commented Nov 19, 2022

Makes sense! Thanks again.

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