Skip to content

rust: cargo and buildRustCrate disagree on escaping of rustc-env directives (and probably more) #199298

@Fuuzetsu

Description

@Fuuzetsu

Describe the bug

At start of Rust crate build, developers can emit various directives in build.rs that then impact the rest of the build.

It seems that cargo handling of these directives differs from the buildRustCrate handling we have when the values contain spaces.

Steps To Reproduce

Create build.rs like below:

fn main() {
    println!("cargo:rustc-env=SHOULD_BE_THREE_WORDS=first second third")
}

Simple src/main.rs

fn main() {
    let should_be_three_words = env!("SHOULD_BE_THREE_WORDS");
    println!("Expecting three words, got: {}", should_be_three_words);
}

Cargo.toml for completeness

[package]
name = "nix-rustc-env-escape-repro"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

Create a nix derivation for a create. I'm using crate2nix but you can use whatever, as long as it goes via buildRustCrate in the end.

$ crate2nix -- generate -f ./Cargo.toml

Finally, run both via cargo and via buildRustCrate and see the difference.

[nix-develop]$ $(nix-build -I nixpkgs=/home/shana/programming/nixpkgs Cargo.nix -A rootCrate.build  --no-out-link)/bin/nix-rustc-env-escape-repro
Expecting three words, got: first
[nix-develop]$ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/nix-rustc-env-escape-repro`
Expecting three words, got: first second third

Expected behavior

The nixpkgs builder should have the same semantics as the cargo one.

Notify maintainers

Unsure.

Metadata

nixpkgs 067c3ad

anything else should be irrelevant here

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions