Skip to content

Commit 4235812

Browse files
committed
Review remarks
1 parent 0a3b2d7 commit 4235812

File tree

3 files changed

+35
-33
lines changed

3 files changed

+35
-33
lines changed

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,8 @@ impl Step for RustcLink {
15411541
}
15421542
}
15431543

1544+
pub const RUSTC_CODEGEN_GCC: &str = "rustc_codegen_gcc";
1545+
15441546
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
15451547
pub struct GccCodegenBackend {
15461548
compilers: RustcPrivateCompilers,
@@ -1551,7 +1553,7 @@ impl Step for GccCodegenBackend {
15511553
const ONLY_HOSTS: bool = true;
15521554

15531555
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1554-
run.alias("rustc_codegen_gcc").alias("cg_gcc")
1556+
run.alias(RUSTC_CODEGEN_GCC).alias("cg_gcc")
15551557
}
15561558

15571559
fn make_run(run: RunConfig<'_>) {
@@ -1610,7 +1612,7 @@ impl Step for GccCodegenBackend {
16101612
let _guard = builder.msg_rustc_tool(
16111613
Kind::Build,
16121614
build_compiler.stage,
1613-
format_args!("codegen backend gcc"),
1615+
"codegen backend gcc",
16141616
build_compiler.host,
16151617
target,
16161618
);
@@ -1620,12 +1622,14 @@ impl Step for GccCodegenBackend {
16201622

16211623
fn metadata(&self) -> Option<StepMetadata> {
16221624
Some(
1623-
StepMetadata::build("rustc_codegen_gcc", self.compilers.target())
1625+
StepMetadata::build(RUSTC_CODEGEN_GCC, self.compilers.target())
16241626
.built_by(self.compilers.build_compiler()),
16251627
)
16261628
}
16271629
}
16281630

1631+
pub const RUSTC_CODEGEN_CRANELIFT: &str = "rustc_codegen_cranelift";
1632+
16291633
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
16301634
pub struct CraneliftCodegenBackend {
16311635
pub compilers: RustcPrivateCompilers,
@@ -1636,7 +1640,7 @@ impl Step for CraneliftCodegenBackend {
16361640
const ONLY_HOSTS: bool = true;
16371641

16381642
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1639-
run.alias("rustc_codegen_cranelift").alias("cg_clif")
1643+
run.alias(RUSTC_CODEGEN_CRANELIFT).alias("cg_clif")
16401644
}
16411645

16421646
fn make_run(run: RunConfig<'_>) {
@@ -1688,13 +1692,13 @@ impl Step for CraneliftCodegenBackend {
16881692
);
16891693
cargo
16901694
.arg("--manifest-path")
1691-
.arg(builder.src.join("compiler/rustc_codegen_cranelift/Cargo.toml"));
1695+
.arg(builder.src.join(format!("compiler/{RUSTC_CODEGEN_CRANELIFT}/Cargo.toml")));
16921696
rustc_cargo_env(builder, &mut cargo, target);
16931697

16941698
let _guard = builder.msg_rustc_tool(
16951699
Kind::Build,
16961700
build_compiler.stage,
1697-
format_args!("codegen backend cranelift"),
1701+
"codegen backend cranelift",
16981702
build_compiler.host,
16991703
target,
17001704
);
@@ -1704,7 +1708,7 @@ impl Step for CraneliftCodegenBackend {
17041708

17051709
fn metadata(&self) -> Option<StepMetadata> {
17061710
Some(
1707-
StepMetadata::build("rustc_codegen_cranelift", self.compilers.target())
1711+
StepMetadata::build(RUSTC_CODEGEN_CRANELIFT, self.compilers.target())
17081712
.built_by(self.compilers.build_compiler()),
17091713
)
17101714
}
@@ -1716,32 +1720,28 @@ fn write_codegen_backend_stamp(
17161720
files: Vec<PathBuf>,
17171721
dry_run: bool,
17181722
) -> BuildStamp {
1719-
if !dry_run {
1720-
let mut files = files.into_iter().filter(|f| {
1721-
let filename = f.file_name().unwrap().to_str().unwrap();
1722-
is_dylib(f) && filename.contains("rustc_codegen_")
1723-
});
1724-
let codegen_backend = match files.next() {
1725-
Some(f) => f,
1726-
None => panic!("no dylibs built for codegen backend?"),
1727-
};
1728-
if let Some(f) = files.next() {
1729-
panic!(
1730-
"codegen backend built two dylibs:\n{}\n{}",
1731-
codegen_backend.display(),
1732-
f.display()
1733-
);
1734-
}
1723+
if dry_run {
1724+
return stamp;
1725+
}
17351726

1736-
let codegen_backend = codegen_backend.to_str().unwrap();
1737-
stamp = stamp.add_stamp(codegen_backend);
1738-
t!(stamp.write());
1727+
let mut files = files.into_iter().filter(|f| {
1728+
let filename = f.file_name().unwrap().to_str().unwrap();
1729+
is_dylib(f) && filename.contains("rustc_codegen_")
1730+
});
1731+
let codegen_backend = match files.next() {
1732+
Some(f) => f,
1733+
None => panic!("no dylibs built for codegen backend?"),
1734+
};
1735+
if let Some(f) = files.next() {
1736+
panic!("codegen backend built two dylibs:\n{}\n{}", codegen_backend.display(), f.display());
17391737
}
1738+
1739+
let codegen_backend = codegen_backend.to_str().unwrap();
1740+
stamp = stamp.add_stamp(codegen_backend);
1741+
t!(stamp.write());
17401742
stamp
17411743
}
17421744

1743-
pub(crate) const CODEGEN_BACKEND_PREFIX: &str = "rustc_codegen_";
1744-
17451745
/// Creates the `codegen-backends` folder for a compiler that's about to be
17461746
/// assembled as a complete compiler.
17471747
///

src/bootstrap/src/core/build_steps/dist.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use object::read::archive::ArchiveFile;
1919
#[cfg(feature = "tracing")]
2020
use tracing::instrument;
2121

22+
use crate::core::build_steps::compile::RUSTC_CODEGEN_CRANELIFT;
2223
use crate::core::build_steps::doc::DocumentationFormat;
2324
use crate::core::build_steps::tool::{self, RustcPrivateCompilers, Tool};
2425
use crate::core::build_steps::vendor::{VENDOR_DIR, Vendor};
@@ -1379,14 +1380,14 @@ impl Step for CraneliftCodegenBackend {
13791380
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
13801381
// We only want to build the cranelift backend in `x dist` if the backend was enabled
13811382
// in rust.codegen-backends.
1382-
// Sadly, we don't have access to the actual for which we're disting clif here..
1383+
// Sadly, we don't have access to the actual target for which we're disting clif here..
13831384
// So we just use the host target.
13841385
let clif_enabled_by_default = run
13851386
.builder
13861387
.config
13871388
.enabled_codegen_backends(run.builder.host_target)
13881389
.contains(&CodegenBackendKind::Cranelift);
1389-
run.alias("rustc_codegen_cranelift").default_condition(clif_enabled_by_default)
1390+
run.alias(RUSTC_CODEGEN_CRANELIFT).default_condition(clif_enabled_by_default)
13901391
}
13911392

13921393
fn make_run(run: RunConfig<'_>) {
@@ -1439,7 +1440,7 @@ impl Step for CraneliftCodegenBackend {
14391440
let mut found_backend = false;
14401441
for backend in fs::read_dir(&backends_src).unwrap() {
14411442
let file_name = backend.unwrap().file_name();
1442-
if file_name.to_str().unwrap().contains("rustc_codegen_cranelift") {
1443+
if file_name.to_str().unwrap().contains(RUSTC_CODEGEN_CRANELIFT) {
14431444
tarball.add_file(
14441445
backends_src.join(file_name),
14451446
&backends_dst,
@@ -1455,7 +1456,7 @@ impl Step for CraneliftCodegenBackend {
14551456

14561457
fn metadata(&self) -> Option<StepMetadata> {
14571458
Some(
1458-
StepMetadata::dist("rustc_codegen_cranelift", self.build_compiler.host)
1459+
StepMetadata::dist(RUSTC_CODEGEN_CRANELIFT, self.build_compiler.host)
14591460
.built_by(self.build_compiler),
14601461
)
14611462
}

src/bootstrap/src/core/config/toml/rust.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::str::FromStr;
55

66
use serde::{Deserialize, Deserializer};
77

8-
use crate::core::build_steps::compile::CODEGEN_BACKEND_PREFIX;
98
use crate::core::config::toml::TomlConfig;
109
use crate::core::config::{
1110
DebuginfoLevel, Merge, ReplaceOpt, RustcLto, StringOrBool, set, threads_from_config,
@@ -397,6 +396,8 @@ pub(crate) fn parse_codegen_backends(
397396
backends: Vec<String>,
398397
section: &str,
399398
) -> Vec<CodegenBackendKind> {
399+
const CODEGEN_BACKEND_PREFIX: &str = "rustc_codegen_";
400+
400401
let mut found_backends = vec![];
401402
for backend in &backends {
402403
if let Some(stripped) = backend.strip_prefix(CODEGEN_BACKEND_PREFIX) {

0 commit comments

Comments
 (0)