Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions library/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,31 @@ rustflags = ["-Cpanic=abort"]
[profile.release.package.panic_abort]
rustflags = ["-Cpanic=abort"]

# The "dist" profile is used by bootstrap for prebuilt libstd artifacts
# These settings ensure that the prebuilt artifacts support a variety of features
# in the user's profile.
[profile.dist]
inherits = "release"
codegen-units = 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cargo_profile_var function will also need to be updated, so that it handles the dist profile (eventually we should make that a hard error, but for now it's some things for Std are configured through it).

debug = 1 # "limited"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this get unconditionally overridden by the value set for debuginfo-level-std?

rustflags = [
# Unconditionally embedding bitcode is necessary for when users enable LTO.
# Until Cargo can rebuild the standard library with the user profile's `lto`
# setting, Cargo will force this to be `no`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the last sentence here - should that be yes?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cargo forces -Cembed-bitcode=no when lto = false. The standard library has to be compiled with lto = false to support building user code without LTO, but it has to also use -Cembed-bitcode=yes to support building user code with LTO. Cargo doesn't have a builtin way to express this specific combination of flags.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in other words, Cargo will pass -Cembed-bitcode=no to locally built stdlib when lto = false, but this rustflags array will still override that to -Cembed-bitcode=yes, right? I just wanted the wording to be clearer, as I didn't understand what it means. "Force this to 'no'" sounds like it overrides the rustflags.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

"-Cembed-bitcode=yes",
# Enable frame pointers
"-Zunstable-options",
"-Cforce-frame-pointers=non-leaf",
]

[profile.dist.package.panic_abort]
rustflags = [
"-Cpanic=abort",
"-Cembed-bitcode=yes",
"-Zunstable-options",
"-Cforce-frame-pointers=non-leaf",
]

[patch.crates-io]
# See comments in `library/rustc-std-workspace-core/README.md` for what's going on here
rustc-std-workspace-core = { path = 'rustc-std-workspace-core' }
Expand Down
12 changes: 0 additions & 12 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,13 +673,6 @@ pub fn std_cargo(
}
}

// By default, rustc uses `-Cembed-bitcode=yes`, and Cargo overrides that
// with `-Cembed-bitcode=no` for non-LTO builds. However, libstd must be
// built with bitcode so that the produced rlibs can be used for both LTO
// builds (which use bitcode) and non-LTO builds (which use object code).
// So we override the override here!
cargo.rustflag("-Cembed-bitcode=yes");

if builder.config.rust_lto == RustcLto::Off {
cargo.rustflag("-Clto=off");
}
Expand All @@ -694,11 +687,6 @@ pub fn std_cargo(
cargo.rustflag("-Cforce-unwind-tables=yes");
}

// Enable frame pointers by default for the library. Note that they are still controlled by a
// separate setting for the compiler.
cargo.rustflag("-Zunstable-options");
cargo.rustflag("-Cforce-frame-pointers=non-leaf");

let html_root =
format!("-Zcrate-attr=doc(html_root_url=\"{}/\")", builder.doc_rust_lang_org_channel(),);
cargo.rustflag(&html_root);
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ impl Step for Analysis {
let src = builder
.stage_out(compiler, Mode::Std)
.join(target)
.join(builder.cargo_dir())
.join(builder.cargo_dir(Mode::Std))
.join("deps")
.join("save-analysis");

Expand Down
5 changes: 3 additions & 2 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,8 +887,9 @@ impl Step for Clippy {

cargo.env("RUSTC_TEST_SUITE", builder.rustc(build_compiler));
cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(build_compiler));
let host_libs =
builder.stage_out(build_compiler, Mode::ToolRustcPrivate).join(builder.cargo_dir());
let host_libs = builder
.stage_out(build_compiler, Mode::ToolRustcPrivate)
.join(builder.cargo_dir(Mode::ToolRustcPrivate));
cargo.env("HOST_LIBS", host_libs);

// Build the standard library that the tests can use.
Expand Down
29 changes: 21 additions & 8 deletions src/bootstrap/src/core/builder/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ pub struct Cargo {
rustdocflags: Rustflags,
hostflags: HostFlags,
allow_features: String,
release_build: bool,
build_compiler_stage: u32,
extra_rustflags: Vec<String>,
profile: Option<&'static str>,
}

impl Cargo {
Expand Down Expand Up @@ -134,7 +134,11 @@ impl Cargo {
}

pub fn release_build(&mut self, release_build: bool) {
self.release_build = release_build;
self.profile = if release_build { Some("release") } else { None };
}

pub fn profile(&mut self, profile: &'static str) {
self.profile = Some(profile)
}

pub fn compiler(&self) -> Compiler {
Expand Down Expand Up @@ -400,8 +404,8 @@ impl Cargo {

impl From<Cargo> for BootstrapCommand {
fn from(mut cargo: Cargo) -> BootstrapCommand {
if cargo.release_build {
cargo.args.insert(0, "--release".into());
if let Some(profile) = cargo.profile {
cargo.args.insert(0, format!("--profile={profile}").into());
}

for arg in &cargo.extra_rustflags {
Expand Down Expand Up @@ -1396,9 +1400,18 @@ impl Builder<'_> {
.unwrap_or(&self.config.rust_rustflags)
.clone();

let release_build = self.config.rust_optimize.is_release() &&
// cargo bench/install do not accept `--release` and miri doesn't want it
!matches!(cmd_kind, Kind::Bench | Kind::Install | Kind::Miri | Kind::MiriSetup | Kind::MiriTest);
let profile =
if matches!(cmd_kind, Kind::Bench | Kind::Miri | Kind::MiriSetup | Kind::MiriTest) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if matches!(cmd_kind, Kind::Bench | Kind::Miri | Kind::MiriSetup | Kind::MiriTest) {
if matches!(cmd_kind, Kind::Bench | Kind::Install | Kind::Miri | Kind::MiriSetup | Kind::MiriTest) {

Previously the code also handled Install, right?

// Use the default profile for bench/miri
None
} else {
match (mode, self.config.rust_optimize.is_release()) {
// Some std configuration exists in its own profile
(Mode::Std, true) => Some("dist"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The -Cembed-bitcode=yes has to also be enabled when the standard library is compiled without optimizations. Otherwise the resulting toolchain is unable to do LTO.

(_, true) => Some("release"),
(_, false) => Some("dev"),
}
};

Cargo {
command: cargo,
Expand All @@ -1409,9 +1422,9 @@ impl Builder<'_> {
rustdocflags,
hostflags,
allow_features,
release_build,
build_compiler_stage,
extra_rustflags,
profile,
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,8 +898,12 @@ impl Build {

/// Component directory that Cargo will produce output into (e.g.
/// release/debug)
fn cargo_dir(&self) -> &'static str {
if self.config.rust_optimize.is_release() { "release" } else { "debug" }
fn cargo_dir(&self, mode: Mode) -> &'static str {
match (mode, self.config.rust_optimize.is_release()) {
(Mode::Std, true) => "dist",
(_, true) => "release",
(_, false) => "debug",
}
}

fn tools_dir(&self, build_compiler: Compiler) -> PathBuf {
Expand Down Expand Up @@ -956,7 +960,7 @@ impl Build {
/// running a particular compiler, whether or not we're building the
/// standard library, and targeting the specified architecture.
fn cargo_out(&self, build_compiler: Compiler, mode: Mode, target: TargetSelection) -> PathBuf {
self.stage_out(build_compiler, mode).join(target).join(self.cargo_dir())
self.stage_out(build_compiler, mode).join(target).join(self.cargo_dir(mode))
}

/// Root output directory of LLVM for `target`
Expand Down
2 changes: 0 additions & 2 deletions src/ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ if [ "$DEPLOY$DEPLOY_ALT" = "1" ]; then

if [ "$DEPLOY_ALT" != "" ] && isLinux; then
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --debuginfo-level=2"
else
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --debuginfo-level-std=1"
fi

if [ "$NO_LLVM_ASSERTIONS" = "1" ]; then
Expand Down