Skip to content

Commit dd6e8d4

Browse files
committed
Auto merge of #33787 - cuviper:local-rebuild, r=alexcrichton
Add --enable-local-rebuild to bootstrap from the current release In Linux distributions, it is often necessary to rebuild packages for cases like applying new patches or linking against new system libraries. In this scenario, the rustc in the distro build environment may already match the current release that we're trying to rebuild. Thus we don't want to use the prior release's bootstrap key, nor `--cfg stage0` for the prior unstable features. The new `configure --enable-local-rebuild` option specifies that we are rebuilding from the current release. The current bootstrap key is used for the local rustc, and current stage1 features are also assumed. Both the makefiles and rustbuild support this configuration. Fixes #29556 r? @alexcrichton
2 parents 57ef015 + 0ca7d3d commit dd6e8d4

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

configure

+11
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ opt debug-assertions 0 "build with debugging assertions"
599599
opt fast-make 0 "use .gitmodules as timestamp for submodule deps"
600600
opt ccache 0 "invoke gcc/clang via ccache to reuse object files between builds"
601601
opt local-rust 0 "use an installed rustc rather than downloading a snapshot"
602+
opt local-rebuild 0 "use an installed rustc matching the current version, for rebuilds"
602603
opt llvm-static-stdcpp 0 "statically link to libstdc++ for LLVM"
603604
opt rpath 1 "build rpaths into rustc itself"
604605
opt stage0-landing-pads 1 "enable landing pads during bootstrap with stage0"
@@ -847,6 +848,16 @@ then
847848
BIN_SUF=.exe
848849
fi
849850

851+
# --enable-local-rebuild implies --enable-local-rust too
852+
if [ -n "$CFG_ENABLE_LOCAL_REBUILD" ]
853+
then
854+
if [ -z "$CFG_ENABLE_LOCAL_RUST" ]
855+
then
856+
CFG_ENABLE_LOCAL_RUST=1
857+
putvar CFG_ENABLE_LOCAL_RUST
858+
fi
859+
fi
860+
850861
if [ -n "$CFG_ENABLE_LOCAL_RUST" ]
851862
then
852863
system_rustc=$(which rustc)

mk/main.mk

+12
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,14 @@ CFG_FILENAME_EXTRA=$(shell printf '%s' $(CFG_RELEASE)$(CFG_EXTRA_FILENAME) | $(C
3434
# intentionally not "secure" by any definition, this is largely just a deterrent
3535
# from users enabling unstable features on the stable compiler.
3636
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
3743
CFG_BOOTSTRAP_KEY_STAGE0=$(shell grep 'rustc_key' $(S)src/stage0.txt | sed 's/rustc_key: '//)
44+
endif
3845

3946
ifeq ($(CFG_RELEASE_CHANNEL),stable)
4047
# This is the normal semver version string, e.g. "0.12.0", "0.12.0-nightly"
@@ -526,6 +533,11 @@ ifneq ($(strip $(CFG_BUILD)),$(strip $(3)))
526533
CFGFLAG$(1)_T_$(2)_H_$(3) = stage1
527534

528535
RPATH_VAR$(1)_T_$(2)_H_$(3) := $$(TARGET_RPATH_VAR1_T_$(2)_H_$$(CFG_BUILD))
536+
else
537+
ifdef CFG_ENABLE_LOCAL_REBUILD
538+
# Assume the local-rebuild rustc already has stage1 features too.
539+
CFGFLAG$(1)_T_$(2)_H_$(3) = stage1
540+
endif
529541
endif
530542
endif
531543

src/bootstrap/build/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ pub struct Config {
6767
pub target: Vec<String>,
6868
pub rustc: Option<String>,
6969
pub cargo: Option<String>,
70+
pub local_rebuild: bool,
7071

7172
// libstd features
7273
pub debug_jemalloc: bool,
@@ -315,6 +316,7 @@ impl Config {
315316
("RPATH", self.rust_rpath),
316317
("OPTIMIZE_TESTS", self.rust_optimize_tests),
317318
("DEBUGINFO_TESTS", self.rust_debuginfo_tests),
319+
("LOCAL_REBUILD", self.local_rebuild),
318320
}
319321

320322
match key {

src/bootstrap/build/mod.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,14 @@ impl Build {
510510
.arg("-j").arg(self.jobs().to_string())
511511
.arg("--target").arg(target);
512512

513+
let stage;
514+
if compiler.stage == 0 && self.config.local_rebuild {
515+
// Assume the local-rebuild rustc already has stage1 features.
516+
stage = 1;
517+
} else {
518+
stage = compiler.stage;
519+
}
520+
513521
// Customize the compiler we're running. Specify the compiler to cargo
514522
// as our shim and then pass it some various options used to configure
515523
// how the actual compiler itself is called.
@@ -518,7 +526,7 @@ impl Build {
518526
// src/bootstrap/{rustc,rustdoc.rs}
519527
cargo.env("RUSTC", self.out.join("bootstrap/debug/rustc"))
520528
.env("RUSTC_REAL", self.compiler_path(compiler))
521-
.env("RUSTC_STAGE", compiler.stage.to_string())
529+
.env("RUSTC_STAGE", stage.to_string())
522530
.env("RUSTC_DEBUGINFO", self.config.rust_debuginfo.to_string())
523531
.env("RUSTC_CODEGEN_UNITS",
524532
self.config.rust_codegen_units.to_string())
@@ -744,7 +752,7 @@ impl Build {
744752
// In stage0 we're using a previously released stable compiler, so we
745753
// use the stage0 bootstrap key. Otherwise we use our own build's
746754
// bootstrap key.
747-
let bootstrap_key = if compiler.is_snapshot(self) {
755+
let bootstrap_key = if compiler.is_snapshot(self) && !self.config.local_rebuild {
748756
&self.bootstrap_key_stage0
749757
} else {
750758
&self.bootstrap_key

0 commit comments

Comments
 (0)