rust-lang / rust-lang/rust

bootstrap ignores `{CC,CFLAGS}_$TARGET` env vars when target name contains a period

Open
#150,819 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug needs-triage T-bootstrap
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Summary

What the title says.

Command used
$ env CC_thumbv8m.main_none_eabihf=false ./x build --target thumbv8m.main-none-eabihf --stage 1 library/compiler-builtins && echo OK
(..)
OK
Expected behaviour

The step of building C code should fail because the C cross compiler is overridden to the false command.

Actual behaviour

The env var is ignored and the default C compiler is used.

Bootstrap configuration (bootstrap.toml)
profile = 'dist'

[llvm]
download-ci-llvm = true
Operating system

Ubuntu 22.04.5 LTS

HEAD

32fe406b5e71afbb0d8b95280e50e67d1549224c

Additional context

The override works when the target name does not have a period in the name. For example, this command fails as expected:

$ env CC_thumbv7em_none_eabihf=false ./x build --target thumbv7em-none-eabihf --stage 1 library/compiler-builtins
(..)
error occurred: Command "false" "-O3" (..)

The cc (v1.2.16) crate also respects the env var when used outside the bootstrap environment.

$ cargo new --lib repro
$ cd repro
$ tail -n2 Cargo.toml
[build-dependencies]
cc = "=1.2.16"

$ cat build.rs
fn main() {
    dbg!(cc::Build::new().get_compiler());
    panic!() // so we can inspect the build script output
}

$ env CC_thumbv8m.main_none_eabihf=false cargo b --target thumbv8m.main-none-eabihf
(..)
  [build.rs:2:5] cc::Build::new().get_compiler() = Tool {
      path: "false",

So possibly bootstrap is modifying the environment that it passes to the cc crate when building the compiler-builtins crate.


In the case of the CC_$TARGET env var, the target.$TARGET.cc setting in bootstrap.toml can be used. I don't know if there's an easy workaround for CFLAGS_$TARGET.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the provided bootstrap command and compare it with the working thumbv7em target case. Trace how bootstrap passes environment variables to cc while building compiler-builtins, using the bootstrap.toml target setting and the cc crate behavior as references. Done means CC_$TARGET and CFLAGS_$TARGET overrides still work when the target name contains a period.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.