Skip to content

Commit dc8212f

Browse files
authored
Auto merge of rust-lang#34779 - infinity0:master, r=alexcrichton
If local-rust is the same as the current version, then force a local-rebuild In Debian, we would like the option to build/rebuild the current release from *either* the current or previous stable release. So we use enable-local-rust instead of enable-local-rebuild, and read the bootstrap key dynamically from whatever is installed locally. In general, it does not make much sense to allow enable-local-rust without also setting the bootstrap key, since the build would fail otherwise. (The way I detect "the bootstrap key of [the local] rustc installation" is a bit hacky, suggestions welcome.)
2 parents c4788c2 + bbff336 commit dc8212f

File tree

5 files changed

+58
-26
lines changed

5 files changed

+58
-26
lines changed

configure

+1-1
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ opt debug-assertions 0 "build with debugging assertions"
600600
opt fast-make 0 "use .gitmodules as timestamp for submodule deps"
601601
opt ccache 0 "invoke gcc/clang via ccache to reuse object files between builds"
602602
opt local-rust 0 "use an installed rustc rather than downloading a snapshot"
603-
opt local-rebuild 0 "use an installed rustc matching the current version, for rebuilds"
603+
opt local-rebuild 0 "assume local-rust matches the current version, for rebuilds; implies local-rust, and is implied if local-rust already matches the current version"
604604
opt llvm-static-stdcpp 0 "statically link to libstdc++ for LLVM"
605605
opt rpath 1 "build rpaths into rustc itself"
606606
opt stage0-landing-pads 1 "enable landing pads during bootstrap with stage0"

mk/main.mk

+32-23
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,6 @@ CFG_RELEASE_NUM=1.12.0
2020
# versions (section 9)
2121
CFG_PRERELEASE_VERSION=.1
2222

23-
# Append a version-dependent hash to each library, so we can install different
24-
# versions in the same place
25-
CFG_FILENAME_EXTRA=$(shell printf '%s' $(CFG_RELEASE)$(CFG_EXTRA_FILENAME) | $(CFG_HASH_COMMAND))
26-
27-
# A magic value that allows the compiler to use unstable features during the
28-
# bootstrap even when doing so would normally be an error because of feature
29-
# staging or because the build turns on warnings-as-errors and unstable features
30-
# default to warnings. The build has to match this key in an env var.
31-
#
32-
# This value is keyed off the release to ensure that all compilers for one
33-
# particular release have the same bootstrap key. Note that this is
34-
# intentionally not "secure" by any definition, this is largely just a deterrent
35-
# from users enabling unstable features on the stable compiler.
36-
CFG_BOOTSTRAP_KEY=$(CFG_FILENAME_EXTRA)
37-
38-
# The stage0 compiler needs to use the previous key recorded in src/stage0.txt,
39-
# except for local-rebuild when it just uses the same current key.
40-
ifdef CFG_ENABLE_LOCAL_REBUILD
41-
CFG_BOOTSTRAP_KEY_STAGE0=$(CFG_BOOTSTRAP_KEY)
42-
else
43-
CFG_BOOTSTRAP_KEY_STAGE0=$(shell grep 'rustc_key' $(S)src/stage0.txt | sed 's/rustc_key: '//)
44-
endif
45-
4623
ifeq ($(CFG_RELEASE_CHANNEL),stable)
4724
# This is the normal semver version string, e.g. "0.12.0", "0.12.0-nightly"
4825
CFG_RELEASE=$(CFG_RELEASE_NUM)
@@ -72,6 +49,38 @@ CFG_RELEASE=$(CFG_RELEASE_NUM)-dev
7249
CFG_PACKAGE_VERS=$(CFG_RELEASE_NUM)-dev
7350
endif
7451

52+
# Append a version-dependent hash to each library, so we can install different
53+
# versions in the same place
54+
CFG_FILENAME_EXTRA=$(shell printf '%s' $(CFG_RELEASE)$(CFG_EXTRA_FILENAME) | $(CFG_HASH_COMMAND))
55+
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+
67+
# If local-rust is the same as the current version, then force a local-rebuild
68+
ifdef CFG_ENABLE_LOCAL_RUST
69+
ifeq ($(CFG_RELEASE),\
70+
$(shell $(S)src/etc/local_stage0.sh --print-rustc-release $(CFG_LOCAL_RUST_ROOT)))
71+
CFG_INFO := $(info cfg: auto-detected local-rebuild $(CFG_RELEASE))
72+
CFG_ENABLE_LOCAL_REBUILD = 1
73+
endif
74+
endif
75+
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+
7584
# The name of the package to use for creating tarballs, installers etc.
7685
CFG_PACKAGE_NAME=rustc-$(CFG_PACKAGE_VERS)
7786

mk/stage0.mk

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ endif
1111

1212
$(SNAPSHOT_RUSTC_POST_CLEANUP): \
1313
$(S)src/stage0.txt \
14+
$(S)src/etc/local_stage0.sh \
1415
$(S)src/etc/get-stage0.py $(MKFILE_DEPS) \
1516
| $(HBIN0_H_$(CFG_BUILD))/
1617
@$(call E, fetch: $@)

src/bootstrap/lib.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ pub struct Build {
118118
ver_date: Option<String>,
119119
version: String,
120120
package_vers: String,
121+
local_rebuild: bool,
121122
bootstrap_key: String,
122123
bootstrap_key_stage0: String,
123124

@@ -174,6 +175,7 @@ impl Build {
174175
Some(ref s) => PathBuf::from(s),
175176
None => stage0_root.join(exe("cargo", &config.build)),
176177
};
178+
let local_rebuild = config.local_rebuild;
177179

178180
Build {
179181
flags: flags,
@@ -189,6 +191,7 @@ impl Build {
189191
short_ver_hash: None,
190192
ver_date: None,
191193
version: String::new(),
194+
local_rebuild: local_rebuild,
192195
bootstrap_key: String::new(),
193196
bootstrap_key_stage0: String::new(),
194197
package_vers: String::new(),
@@ -219,6 +222,16 @@ impl Build {
219222
sanity::check(self);
220223
self.verbose("collecting channel variables");
221224
channel::collect(self);
225+
// If local-rust is the same as the current version, then force a local-rebuild
226+
let local_version_verbose = output(
227+
Command::new(&self.rustc).arg("--version").arg("--verbose"));
228+
let local_release = local_version_verbose
229+
.lines().filter(|x| x.starts_with("release:"))
230+
.next().unwrap().trim_left_matches("release:").trim();
231+
if local_release == self.release {
232+
self.verbose(&format!("auto-detected local-rebuild {}", self.release));
233+
self.local_rebuild = true;
234+
}
222235
self.verbose("updating submodules");
223236
self.update_submodules();
224237

@@ -525,7 +538,7 @@ impl Build {
525538
.arg("--target").arg(target);
526539

527540
let stage;
528-
if compiler.stage == 0 && self.config.local_rebuild {
541+
if compiler.stage == 0 && self.local_rebuild {
529542
// Assume the local-rebuild rustc already has stage1 features.
530543
stage = 1;
531544
} else {
@@ -766,7 +779,7 @@ impl Build {
766779
// In stage0 we're using a previously released stable compiler, so we
767780
// use the stage0 bootstrap key. Otherwise we use our own build's
768781
// bootstrap key.
769-
let bootstrap_key = if compiler.is_snapshot(self) && !self.config.local_rebuild {
782+
let bootstrap_key = if compiler.is_snapshot(self) && !self.local_rebuild {
770783
&self.bootstrap_key_stage0
771784
} else {
772785
&self.bootstrap_key

src/etc/local_stage0.sh

+9
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ if [ -z $TARG_DIR ]; then
4949
exit 1
5050
fi
5151

52+
case "$TARG_DIR" in
53+
--print-rustc-release)
54+
# not actually copying to TARG_DIR, just print the local rustc version and exit
55+
${PREFIX}/bin/rustc${BIN_SUF} --version --verbose | sed -ne 's/^release: //p'
56+
;;
57+
*)
58+
5259
cp ${PREFIX}/bin/rustc${BIN_SUF} ${TARG_DIR}/stage0/bin/
5360
cp ${PREFIX}/${LIB_DIR}/${RUSTLIBDIR}/${TARG_DIR}/${LIB_DIR}/* ${TARG_DIR}/stage0/${LIB_DIR}/
5461
cp ${PREFIX}/${LIB_DIR}/${LIB_PREFIX}extra*${LIB_SUF} ${TARG_DIR}/stage0/${LIB_DIR}/
@@ -66,3 +73,5 @@ cp ${PREFIX}/${LIB_DIR}/${LIB_PREFIX}term*${LIB_SUF} ${TARG_DIR}/stage0/${LIB_DI
6673

6774
# do not fail if one of the above fails, as all we need is a working rustc!
6875
exit 0
76+
77+
esac

0 commit comments

Comments
 (0)