Skip to content

Build fails when RUSTC environment variable is set to nightly #68

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

Closed
tmvkrpxl0 opened this issue Apr 27, 2025 · 10 comments · Fixed by #69
Closed

Build fails when RUSTC environment variable is set to nightly #68

tmvkrpxl0 opened this issue Apr 27, 2025 · 10 comments · Fixed by #69

Comments

@tmvkrpxl0
Copy link
Contributor

tmvkrpxl0 commented Apr 27, 2025

I discovered that running cargo build with rustc environment variable is set to "/home/tmvkrpxl0/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc" (path to nightly rustc on my pc) fails with below error:

🦀 Running `spirv-builder-cli` to compile shader at /home/tmvkrpxl0/CLionProjects/beam/game...
error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `/home/tmvkrpxl0/.cargo/bin/sccache /home/tmvkrpxl0/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc - --crate-name ___ --print=file-names -Zcodegen-backend=/home/tmvkrpxl0/.cache/rust-gpu/spirv-builder-cli/_home_tmvkrpxl0_CLionProjects_rust-gpu+0_9_0+nightly-2024-11-22/librustc_codegen_spirv.so -Zbinary-dep-depinfo -Csymbol-mangling-version=v0 '-Zcrate-attr=feature(register_tool)' '-Zcrate-attr=register_tool(rust_gpu)' -Coverflow-checks=off -Cdebug-assertions=off -Zinline-mir=off -Zmir-enable-passes=-GVN --target /home/tmvkrpxl0/.cache/rust-gpu/target-specs/spirv-unknown-vulkan1.2.json --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=split-debuginfo --print=crate-name --print=cfg` (exit status: 1)
  --- stderr
  error: Error loading target specification: `unknown` os can only be used on particular targets; use `none` for bare-metal targets. Run `rustc --print target-list` for a list of built-in targets

thread 'main' panicked at src/main.rs:152:38:
called `Result::unwrap()` on an `Err` value: BuildFailed
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[2025-04-27T14:20:59Z ERROR cargo_gpu] build failed
Error: build failed

This is problematic on projects that uses nightly. My project is currently set up in this way:
root (workspace root that uses nightly rust):
ㄴ game (contains build.rs that runs cargo gpu command)
ㄴ macros
ㄴ shader-path (compiled by cargo-gpu)
ㄴ shader-rasterizer (compiled by cargo-gpu)
ㄴ types-shared
ㄴ utils

Since the workspace root uses nightly, it sets rustc version to nightly and fails to compile with same error.

@tmvkrpxl0
Copy link
Contributor Author

I'm sure this is caused by recent changes in nightly rust. This means that those changes probably would arrive in stable soon, so we should fix this before we have this problem on stable as well.

@tmvkrpxl0
Copy link
Contributor Author

I found the commit that this error was introduced:
rust-lang/rust#133409

Based on their intention, I think we should update our target specification json

@tmvkrpxl0
Copy link
Contributor Author

https://llvm.org/doxygen/classllvm_1_1Triple.html#a1778f5c464f88710033f7e11e84a9324a73b4a675dd734e1efcab33de0d217a37

Looking at LLVM's target triple lists, it has enum entries for shader stages in EnvironmentType enum and Vulkan entry in OSType
Should we explicitly support those?

@tmvkrpxl0
Copy link
Contributor Author

tmvkrpxl0 commented Apr 27, 2025

One workaround I found for potential fix is to set RUSTC environment variable before invoking spirv_builder_cli at here
https://github.com/Rust-GPU/cargo-gpu/blob/main/crates/cargo-gpu/src/build.rs#L71

Currently this works:

        let output = std::process::Command::new(spirv_builder_cli_path)
            .arg(arg)
            .stdout(std::process::Stdio::inherit())
            .stderr(std::process::Stdio::inherit())
            .env("RUSTC", "/home/tmvkrpxl0/.rustup/toolchains/nightly-2024-11-22-x86_64-unknown-linux-gnu/bin/rustc")
            .output()?;
        anyhow::ensure!(output.status.success(), "build failed");

If we can't update, we should set rustc version to whatever before that commit.
and I think setting it to same version as codegen backend would be good enough.

@tmvkrpxl0
Copy link
Contributor Author

I discovered that if I edit target specification under .cache directory and set the os to "vulkan" from "unknown", this error is printed:

error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `/home/tmvkrpxl0/.cargo/bin/sccache /home/tmvkrpxl0/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc - --crate-name ___ --print=file-names -Zcodegen-backend=/home/tmvkrpxl0/.cache/rust-gpu/spirv-builder-cli/_home_tmvkrpxl0_CLionProjects_rust-gpu+0_9_0+nightly-2024-11-22/librustc_codegen_spirv.so -Zbinary-dep-depinfo -Csymbol-mangling-version=v0 '-Zcrate-attr=feature(register_tool)' '-Zcrate-attr=register_tool(rust_gpu)' -Coverflow-checks=off -Cdebug-assertions=off -Zinline-mir=off -Zmir-enable-passes=-GVN -Cllvm-args=--spirv-metadata=full '-Ctarget-feature=+RuntimeDescriptorArray,+Int8,+InputAttachment,+SampledImageArrayNonUniformIndexing,+ext:SPV_EXT_descriptor_indexing' --target /home/tmvkrpxl0/.cache/rust-gpu/target-specs/spirv-vulkan-vulkan1.2.json --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=split-debuginfo --print=crate-name --print=cfg` (exit status: 1)
  --- stderr
  error: Error loading target specification: static CRT can be enabled but `crt_static_respected` is not set. Run `rustc --print target-list` for a list of built-in targets

thread 'main' panicked at src/main.rs:152:38:
called `Result::unwrap()` on an `Err` value: BuildFailed
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[2025-04-27T16:10:22Z ERROR cargo_gpu] build failed
Error: build failed

@tmvkrpxl0
Copy link
Contributor Author

tmvkrpxl0 commented Apr 27, 2025

Hmm, I discovered that manually setting RUSTC to latest nightly causes other part of build process to fail as well on fresh install.
Should we unset and ignore the environment variable entirely? Afaik it's supposed to be specified to whatever spirv codegen uses. And it wouldn't need to locate the exact rustc path.

@Firestar99
Copy link
Member

Firestar99 commented Apr 29, 2025

How did you set your RUSTC env var? Neither rustup default nightly nor cargo +nightly run install ... does that for me, I need to manually export RUSTC=... to repo this.

@Firestar99
Copy link
Member

@tmvkrpxl0
Copy link
Contributor Author

@Firestar99 If cargo gpu command is executed from build.rs, it is set

@tmvkrpxl0
Copy link
Contributor Author

@Firestar99 Just tested if "os: "none" works, and it's same as when I set it to "vulkan", it complains something about crt_static_respected

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

Successfully merging a pull request may close this issue.

2 participants