Skip to content

Commit 8df181d

Browse files
committed
Improve handing of env vars during bootstrap process
This CL modifies the handing of env vars during the bootstrap process in two ways: 1. Replaces '-' characters with '_' characters in target names to increase compatibility with different shells 2. Passes Stage0 snapshot compiler related env vars to early invocations of Cargo
1 parent a926696 commit 8df181d

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/bootstrap/bootstrap.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -732,19 +732,26 @@ def build_bootstrap(self, color):
732732
(os.pathsep + env["LIBRARY_PATH"]) \
733733
if "LIBRARY_PATH" in env else ""
734734

735+
# Export Stage0 snapshot compiler related env variables
736+
build_section = f"target.{self.build}"
737+
host_triple_sanitized = self.build.replace("-", "_")
738+
var_data = {
739+
"CC": "cc", "CXX": "cxx", "LD": "linker", "AR": "ar", "RANLIB": "ranlib"
740+
}
741+
for var_name, toml_key in var_data.items():
742+
toml_val = self.get_toml(toml_key, build_section)
743+
if toml_val != None:
744+
env[f"{var_name}_{host_triple_sanitized}"] = toml_val
745+
735746
# preserve existing RUSTFLAGS
736747
env.setdefault("RUSTFLAGS", "")
737-
build_section = "target.{}".format(self.build)
738748
target_features = []
739749
if self.get_toml("crt-static", build_section) == "true":
740750
target_features += ["+crt-static"]
741751
elif self.get_toml("crt-static", build_section) == "false":
742752
target_features += ["-crt-static"]
743753
if target_features:
744754
env["RUSTFLAGS"] += " -C target-feature=" + (",".join(target_features))
745-
target_linker = self.get_toml("linker", build_section)
746-
if target_linker is not None:
747-
env["RUSTFLAGS"] += " -C linker=" + target_linker
748755
env["RUSTFLAGS"] += " -Wrust_2018_idioms -Wunused_lifetimes"
749756
env["RUSTFLAGS"] += " -Wsemicolon_in_expressions_from_macros"
750757
if self.get_toml("deny-warnings", "rust") != "false":

src/bootstrap/builder.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1940,25 +1940,26 @@ impl<'a> Builder<'a> {
19401940
_ => s.display().to_string(),
19411941
}
19421942
};
1943+
let triple_underscored = target.triple.replace("-", "_");
19431944
let cc = ccacheify(&self.cc(target));
1944-
cargo.env(format!("CC_{}", target.triple), &cc);
1945+
cargo.env(format!("CC_{}", triple_underscored), &cc);
19451946

19461947
let cflags = self.cflags(target, GitRepo::Rustc, CLang::C).join(" ");
1947-
cargo.env(format!("CFLAGS_{}", target.triple), &cflags);
1948+
cargo.env(format!("CFLAGS_{}", triple_underscored), &cflags);
19481949

19491950
if let Some(ar) = self.ar(target) {
19501951
let ranlib = format!("{} s", ar.display());
19511952
cargo
1952-
.env(format!("AR_{}", target.triple), ar)
1953-
.env(format!("RANLIB_{}", target.triple), ranlib);
1953+
.env(format!("AR_{}", triple_underscored), ar)
1954+
.env(format!("RANLIB_{}", triple_underscored), ranlib);
19541955
}
19551956

19561957
if let Ok(cxx) = self.cxx(target) {
19571958
let cxx = ccacheify(&cxx);
19581959
let cxxflags = self.cflags(target, GitRepo::Rustc, CLang::Cxx).join(" ");
19591960
cargo
1960-
.env(format!("CXX_{}", target.triple), &cxx)
1961-
.env(format!("CXXFLAGS_{}", target.triple), cxxflags);
1961+
.env(format!("CXX_{}", triple_underscored), &cxx)
1962+
.env(format!("CXXFLAGS_{}", triple_underscored), cxxflags);
19621963
}
19631964
}
19641965

0 commit comments

Comments
 (0)