Skip to content

Fail to build with master due to undefined cargo environment variables #143

Closed
@LegNeato

Description

@LegNeato

My code fails to compile because several environment variables set by Cargo (CARGO_PKG_NAME, CARGO_PKG_VERSION_MAJOR, CARGO_PKG_VERSION_MINOR, CARGO_PKG_VERSION_PATCH, and CARGO_PKG_VERSION) are unavailable.

An example error:

{"$message_type":"diagnostic","message":"environment variable CARGO_PKG_NAME not defined at compile time","code":null,"level":"error","spans":[{"file_name":"/Users/legnitto/.cargo/git/checkouts/rust-gpu-11142fd2aadc2318/0da80f8/crates/rustc_codegen_spirv/src/custom_insts.rs","byte_start":739,"byte_end":761,"line_start":16,"line_end":16,"column_start":63,"column_end":85,"is_primary":true,"text":[{"text":"pub const CUSTOM_EXT_INST_SET_PREFIX: &str = concat!(\"Rust.\", env!(\"CARGO_PKG_NAME\"), \".\");","highlight_start":63,"highlight_end":85}]

I'm not doing anything fancy but I'm sure I am doing something wrong...this code in rustc_codegen_spirv hasn't changed in a long time. the gpu crate builds fine on its own and the shared crate builds file on its own but the cpu crate fails. Even when I blank out all code except the build.rs for the cpu crate it still fails the same way.

Here is my layout:

├── Cargo.lock
├── Cargo.toml
├── benches
│   ├── Cargo.toml
│   └── src
│       └── matmul.rs
├── crates
│   ├── cpu
│   │   ├── Cargo.toml
│   │   ├── build.rs
│   │   └── src
│   │       ├── lib.rs
│   │       ├── vulkan.rs
│   │       └── wgpu.rs
│   ├── gpu
│   │   ├── Cargo.toml
│   │   └── src
│   │       └── lib.rs
│   └── shared
│       ├── Cargo.toml
│       └── src
│           └── lib.rs
├── rust-toolchain.toml
└── src
    └── main.rs

The build.rs:

use spirv_builder::{MetadataPrintout, SpirvBuilder};
use std::path::Path;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Specify the path to the `gpu` crate, which contains the shader code
    let gpu_crate_path = Path::new("../gpu");

    // Compile the shader crate with SpirvBuilder
    let result = SpirvBuilder::new(gpu_crate_path, "spirv-unknown-vulkan1.3)
        .print_metadata(MetadataPrintout::Full)
        .build()?;

    // Set an environment variable for the compiled shader path
    println!(
        "cargo:rustc-env=SHADER_PATH={}",
        result.module.unwrap_single()
    );

    println!("cargo:rerun-if-changed=crates/gpu/src/");
    println!("cargo:rerun-if-changed=crates/shared/src/");

    println!("{result:#?}");
    result
}

I'm not sure how to debug this...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions