Skip to content

Commit 2d3a5d8

Browse files
committed
Allow bootstrapping without a key. Fixes rust-lang#36548
This will make it easier for packagers to bootstrap rustc when they happen to have a bootstrap compiler with a slightly different version number. It's not ok for anything other than the build system to set this environment variable.
1 parent f7686a5 commit 2d3a5d8

File tree

7 files changed

+19
-66
lines changed

7 files changed

+19
-66
lines changed

mk/main.mk

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,6 @@ endif
5353
# versions in the same place
5454
CFG_FILENAME_EXTRA=$(shell printf '%s' $(CFG_RELEASE)$(CFG_EXTRA_FILENAME) | $(CFG_HASH_COMMAND))
5555

56-
# A magic value that allows the compiler to use unstable features during the
57-
# bootstrap even when doing so would normally be an error because of feature
58-
# staging or because the build turns on warnings-as-errors and unstable features
59-
# default to warnings. The build has to match this key in an env var.
60-
#
61-
# This value is keyed off the release to ensure that all compilers for one
62-
# particular release have the same bootstrap key. Note that this is
63-
# intentionally not "secure" by any definition, this is largely just a deterrent
64-
# from users enabling unstable features on the stable compiler.
65-
CFG_BOOTSTRAP_KEY=$(CFG_FILENAME_EXTRA)
66-
6756
# If local-rust is the same as the current version, then force a local-rebuild
6857
ifdef CFG_ENABLE_LOCAL_RUST
6958
ifeq ($(CFG_RELEASE),\
@@ -73,14 +62,6 @@ ifeq ($(CFG_RELEASE),\
7362
endif
7463
endif
7564

76-
# The stage0 compiler needs to use the previous key recorded in src/stage0.txt,
77-
# except for local-rebuild when it just uses the same current key.
78-
ifdef CFG_ENABLE_LOCAL_REBUILD
79-
CFG_BOOTSTRAP_KEY_STAGE0=$(CFG_BOOTSTRAP_KEY)
80-
else
81-
CFG_BOOTSTRAP_KEY_STAGE0=$(shell sed -ne 's/^rustc_key: //p' $(S)src/stage0.txt)
82-
endif
83-
8465
# The name of the package to use for creating tarballs, installers etc.
8566
CFG_PACKAGE_NAME=rustc-$(CFG_PACKAGE_VERS)
8667

@@ -387,13 +368,16 @@ CFG_INFO := $(info cfg: disabling unstable features (CFG_DISABLE_UNSTABLE_FEATUR
387368
# Turn on feature-staging
388369
export CFG_DISABLE_UNSTABLE_FEATURES
389370
# Subvert unstable feature lints to do the self-build
390-
export RUSTC_BOOTSTRAP_KEY:=$(CFG_BOOTSTRAP_KEY)
371+
export RUSTC_BOOTSTRAP
391372
endif
392-
export CFG_BOOTSTRAP_KEY
393373
ifdef CFG_MUSL_ROOT
394374
export CFG_MUSL_ROOT
395375
endif
396376

377+
# FIXME: Transitionary measure to bootstrap using the old bootstrap logic.
378+
# Remove this once the bootstrap compiler uses the new login in Issue #36548.
379+
export RUSTC_BOOTSTRAP_KEY=5c6cf767
380+
397381
######################################################################
398382
# Per-stage targets and runner
399383
######################################################################

mk/target.mk

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,6 @@ $(foreach host,$(CFG_HOST), \
4242
$(foreach crate,$(CRATES), \
4343
$(eval $(call RUST_CRATE_FULLDEPS,$(stage),$(target),$(host),$(crate)))))))
4444

45-
# $(1) stage
46-
# $(2) target
47-
# $(3) host
48-
define DEFINE_BOOTSTRAP_KEY
49-
BOOTSTRAP_KEY$(1)_T_$(2)_H_$(3) := $$(CFG_BOOTSTRAP_KEY)
50-
ifeq ($(1),0)
51-
ifeq ($(3),$$(CFG_BUILD))
52-
BOOTSTRAP_KEY$(1)_T_$(2)_H_$(3) := $$(CFG_BOOTSTRAP_KEY_STAGE0)
53-
endif
54-
endif
55-
endef
56-
57-
$(foreach host,$(CFG_TARGET), \
58-
$(foreach target,$(CFG_TARGET), \
59-
$(foreach stage,$(STAGES), \
60-
$(eval $(call DEFINE_BOOTSTRAP_KEY,$(stage),$(target),$(host))))))
61-
6245
# RUST_TARGET_STAGE_N template: This defines how target artifacts are built
6346
# for all stage/target architecture combinations. This is one giant rule which
6447
# works as follows:
@@ -83,8 +66,6 @@ $(foreach host,$(CFG_TARGET), \
8366
define RUST_TARGET_STAGE_N
8467

8568
$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): CFG_COMPILER_HOST_TRIPLE = $(2)
86-
$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): \
87-
export RUSTC_BOOTSTRAP_KEY := $$(BOOTSTRAP_KEY$(1)_T_$(2)_H_$(3))
8869
$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): \
8970
$$(CRATEFILE_$(4)) \
9071
$$(CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4)) \
@@ -132,8 +113,6 @@ endef
132113
# $(4) - name of the tool being built
133114
define TARGET_TOOL
134115

135-
$$(TBIN$(1)_T_$(2)_H_$(3))/$(4)$$(X_$(2)): \
136-
export RUSTC_BOOTSTRAP_KEY := $$(BOOTSTRAP_KEY$(1)_T_$(2)_H_$(3))
137116
$$(TBIN$(1)_T_$(2)_H_$(3))/$(4)$$(X_$(2)): \
138117
$$(TOOL_SOURCE_$(4)) \
139118
$$(TOOL_INPUTS_$(4)) \

src/bootstrap/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ pub fn compiletest(build: &Build,
185185
}
186186
}
187187
}
188-
build.add_bootstrap_key(compiler, &mut cmd);
188+
build.add_bootstrap_key(&mut cmd);
189189

190190
cmd.arg("--adb-path").arg("adb");
191191
cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);

src/bootstrap/compile.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ fn build_startup_objects(build: &Build, target: &str, into: &Path) {
133133
for file in t!(fs::read_dir(build.src.join("src/rtstartup"))) {
134134
let file = t!(file);
135135
let mut cmd = Command::new(&compiler_path);
136-
build.add_bootstrap_key(&compiler, &mut cmd);
136+
build.add_bootstrap_key(&mut cmd);
137137
build.run(cmd.arg("--target").arg(target)
138138
.arg("--emit=obj")
139139
.arg("--out-dir").arg(into)
@@ -199,7 +199,6 @@ pub fn rustc<'a>(build: &'a Build, target: &str, compiler: &Compiler<'a>) {
199199
cargo.env("CFG_RELEASE", &build.release)
200200
.env("CFG_RELEASE_CHANNEL", &build.config.channel)
201201
.env("CFG_VERSION", &build.version)
202-
.env("CFG_BOOTSTRAP_KEY", &build.bootstrap_key)
203202
.env("CFG_PREFIX", build.config.prefix.clone().unwrap_or(String::new()))
204203
.env("CFG_LIBDIR_RELATIVE", "lib");
205204

src/bootstrap/lib.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ impl Build {
647647
.env("RUSTDOC_REAL", self.rustdoc(compiler))
648648
.env("RUSTC_FLAGS", self.rustc_flags(target).join(" "));
649649

650-
self.add_bootstrap_key(compiler, &mut cargo);
650+
self.add_bootstrap_key(&mut cargo);
651651

652652
// Specify some various options for build scripts used throughout
653653
// the build.
@@ -862,16 +862,11 @@ impl Build {
862862
}
863863

864864
/// Adds the compiler's bootstrap key to the environment of `cmd`.
865-
fn add_bootstrap_key(&self, compiler: &Compiler, cmd: &mut Command) {
866-
// In stage0 we're using a previously released stable compiler, so we
867-
// use the stage0 bootstrap key. Otherwise we use our own build's
868-
// bootstrap key.
869-
let bootstrap_key = if compiler.is_snapshot(self) && !self.local_rebuild {
870-
&self.bootstrap_key_stage0
871-
} else {
872-
&self.bootstrap_key
873-
};
874-
cmd.env("RUSTC_BOOTSTRAP_KEY", bootstrap_key);
865+
fn add_bootstrap_key(&self, cmd: &mut Command) {
866+
cmd.env("RUSTC_BOOTSTRAP", "");
867+
// FIXME: Transitionary measure to bootstrap using the old bootstrap logic.
868+
// Remove this once the bootstrap compiler uses the new login in Issue #36548.
869+
cmd.env("RUSTC_BOOTSTRAP_KEY", "5c6cf767");
875870
}
876871

877872
/// Returns the compiler's libdir where it stores the dynamic libraries that

src/libsyntax/feature_gate.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,15 +1296,12 @@ impl UnstableFeatures {
12961296
pub fn from_environment() -> UnstableFeatures {
12971297
// Whether this is a feature-staged build, i.e. on the beta or stable channel
12981298
let disable_unstable_features = option_env!("CFG_DISABLE_UNSTABLE_FEATURES").is_some();
1299-
// The secret key needed to get through the rustc build itself by
1300-
// subverting the unstable features lints
1301-
let bootstrap_secret_key = option_env!("CFG_BOOTSTRAP_KEY");
1302-
// The matching key to the above, only known by the build system
1303-
let bootstrap_provided_key = env::var("RUSTC_BOOTSTRAP_KEY").ok();
1304-
match (disable_unstable_features, bootstrap_secret_key, bootstrap_provided_key) {
1305-
(_, Some(ref s), Some(ref p)) if s == p => UnstableFeatures::Cheat,
1306-
(true, _, _) => UnstableFeatures::Disallow,
1307-
(false, _, _) => UnstableFeatures::Allow
1299+
// Whether we should enable unstable features for bootstrapping
1300+
let bootstrap = env::var("RUSTC_BOOTSTRAP").is_ok();
1301+
match (disable_unstable_features, bootstrap) {
1302+
(_, true) => UnstableFeatures::Cheat,
1303+
(true, _) => UnstableFeatures::Disallow,
1304+
(false, _) => UnstableFeatures::Allow
13081305
}
13091306
}
13101307

src/stage0.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@
1313
# released on `$date`
1414

1515
rustc: 1.12.1-2016-10-20
16-
rustc_key: 5c6cf767
1716
cargo: nightly-2016-08-21

0 commit comments

Comments
 (0)