Skip to content

handle --release flag separately for tools #136048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
handle release builds appropriately
Signed-off-by: onur-ozkan <work@onurozkan.dev>
  • Loading branch information
onur-ozkan committed Jan 25, 2025
commit ea159351b2c07756bd79f56af377e1bb358911c7
5 changes: 3 additions & 2 deletions src/bootstrap/src/core/build_steps/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,10 +790,11 @@ impl Step for Analysis {
return None;
}

let mode = Mode::Std;
let src = builder
.stage_out(compiler, Mode::Std)
.stage_out(compiler, mode)
.join(target)
.join(builder.cargo_dir())
.join(builder.cargo_dir(&mode))
.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 @@ -742,10 +742,11 @@ impl Step for Clippy {
let compiler = builder.compiler(stage, host);

builder.ensure(tool::Clippy { compiler, target: self.host });
let mode = Mode::ToolRustc;
let mut cargo = tool::prepare_tool_cargo(
builder,
compiler,
Mode::ToolRustc,
mode,
host,
Kind::Test,
"src/tools/clippy",
Expand All @@ -755,7 +756,7 @@ impl Step for Clippy {

cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
let host_libs = builder.stage_out(compiler, Mode::ToolRustc).join(builder.cargo_dir());
let host_libs = builder.stage_out(compiler, mode).join(builder.cargo_dir(&mode));
cargo.env("HOST_LIBS", host_libs);

cargo.add_rustc_lib_path(builder);
Expand Down
6 changes: 3 additions & 3 deletions src/bootstrap/src/core/builder/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,9 @@ impl Builder<'_> {
assert_eq!(target, compiler.host);
}

if 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)
if self.is_release_build(&mode) &&
// 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)
{
cargo.arg("--release");
}
Expand Down
15 changes: 12 additions & 3 deletions src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,10 +660,19 @@ impl Build {
features.join(" ")
}

fn is_release_build(&self, mode: &Mode) -> bool {
match mode {
Mode::Std | Mode::Rustc => self.config.rust_optimize.is_release(),
Mode::Codegen | Mode::ToolBootstrap | Mode::ToolStd | Mode::ToolRustc => {
self.config.enable_release_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 {
if self.is_release_build(mode) { "release" } else { "debug" }
}

fn tools_dir(&self, compiler: Compiler) -> PathBuf {
Expand Down Expand Up @@ -691,7 +700,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, compiler: Compiler, mode: Mode, target: TargetSelection) -> PathBuf {
self.stage_out(compiler, mode).join(target).join(self.cargo_dir())
self.stage_out(compiler, mode).join(target).join(self.cargo_dir(&mode))
}

/// Root output directory of LLVM for `target`
Expand Down