Skip to content

Commit 3beacc3

Browse files
committed
Auto merge of rust-lang#81746 - bjorn3:cg_clif_rustup_component, r=<try>
Distribute cg_clif as rustup component on the nightly channel This makes it possible to use cg_clif using: ```bash $ rustup component add rustc-codegen-cranelift-preview --toolchain nightly $ RUSTFLAGS="-Zcodegen-backend=cranelift" cargo +nightly build ``` Marking as draft because I haven't verified that it correctly produces the component. In addition it makes cg_clif compile by default. This may want to be moved to the CI configuration instead. cc rust-lang/compiler-team#405. r? `@Mark-Simulacrum`
2 parents 9372999 + 67a5f55 commit 3beacc3

File tree

9 files changed

+149
-28
lines changed

9 files changed

+149
-28
lines changed

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

+95-14
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
2727
use crate::core::config::TargetSelection;
2828
use crate::utils::cache::{Interned, INTERNER};
2929
use crate::utils::channel;
30-
use crate::utils::helpers::{exe, is_dylib, output, t, timeit};
30+
use crate::utils::helpers::{exe, is_dylib, output, t, target_supports_cranelift_backend, timeit};
3131
use crate::utils::tarball::{GeneratedTarball, OverlayKind, Tarball};
3232
use crate::{Compiler, DependencyType, Mode, LLVM_TOOLS};
3333

@@ -443,19 +443,6 @@ impl Step for Rustc {
443443
}
444444
}
445445

446-
// Copy over the codegen backends
447-
let backends_src = builder.sysroot_codegen_backends(compiler);
448-
let backends_rel = backends_src
449-
.strip_prefix(&src)
450-
.unwrap()
451-
.strip_prefix(builder.sysroot_libdir_relative(compiler))
452-
.unwrap();
453-
// Don't use custom libdir here because ^lib/ will be resolved again with installer
454-
let backends_dst = image.join("lib").join(&backends_rel);
455-
456-
t!(fs::create_dir_all(&backends_dst));
457-
builder.cp_r(&backends_src, &backends_dst);
458-
459446
// Copy libLLVM.so to the lib dir as well, if needed. While not
460447
// technically needed by rustc itself it's needed by lots of other
461448
// components like the llvm tools and LLD. LLD is included below and
@@ -1282,6 +1269,91 @@ impl Step for Miri {
12821269
}
12831270
}
12841271

1272+
#[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1273+
pub struct CodegenBackend {
1274+
pub compiler: Compiler,
1275+
pub backend: Interned<String>,
1276+
}
1277+
1278+
impl Step for CodegenBackend {
1279+
type Output = Option<GeneratedTarball>;
1280+
const DEFAULT: bool = true;
1281+
const ONLY_HOSTS: bool = true;
1282+
1283+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1284+
run.path("compiler/rustc_codegen_cranelift")
1285+
}
1286+
1287+
fn make_run(run: RunConfig<'_>) {
1288+
for &backend in &run.builder.config.rust_codegen_backends {
1289+
if backend == "llvm" {
1290+
continue; // Already built as part of rustc
1291+
}
1292+
1293+
run.builder.ensure(CodegenBackend {
1294+
compiler: run.builder.compiler(run.builder.top_stage, run.target),
1295+
backend,
1296+
});
1297+
}
1298+
}
1299+
1300+
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
1301+
// This prevents rustc_codegen_cranelift from being built for "dist"
1302+
// or "install" on the stable/beta channels. It is not yet stable and
1303+
// should not be included.
1304+
if !builder.build.unstable_features() {
1305+
return None;
1306+
}
1307+
1308+
if self.backend == "cranelift" {
1309+
if !target_supports_cranelift_backend(self.compiler.host) {
1310+
builder.info("target not supported by rustc_codegen_cranelift. skipping");
1311+
return None;
1312+
}
1313+
1314+
if self.compiler.host.contains("windows") {
1315+
builder.info(
1316+
"dist currently disabled for windows by rustc_codegen_cranelift. skipping",
1317+
);
1318+
return None;
1319+
}
1320+
}
1321+
1322+
let compiler = self.compiler;
1323+
let backend = self.backend;
1324+
1325+
let mut tarball =
1326+
Tarball::new(builder, &format!("rustc-codegen-{}", backend), &compiler.host.triple);
1327+
if backend == "cranelift" {
1328+
tarball.set_overlay(OverlayKind::RustcCodegenCranelift);
1329+
} else {
1330+
panic!("Unknown backend rustc_codegen_{}", backend);
1331+
}
1332+
tarball.is_preview(true);
1333+
tarball.add_legal_and_readme_to(format!("share/doc/rustc_codegen_{}", backend));
1334+
1335+
let src = builder.sysroot(compiler);
1336+
let backends_src = builder.sysroot_codegen_backends(compiler);
1337+
let backends_rel = backends_src
1338+
.strip_prefix(&src)
1339+
.unwrap()
1340+
.strip_prefix(builder.sysroot_libdir_relative(compiler))
1341+
.unwrap();
1342+
// Don't use custom libdir here because ^lib/ will be resolved again with installer
1343+
let backends_dst = PathBuf::from("lib").join(&backends_rel);
1344+
1345+
let backend_name = format!("rustc_codegen_{}", backend);
1346+
for backend in fs::read_dir(&backends_src).unwrap() {
1347+
let file_name = backend.unwrap().file_name();
1348+
if file_name.to_str().unwrap().contains(&backend_name) {
1349+
tarball.add_file(backends_src.join(file_name), &backends_dst, 0o644);
1350+
}
1351+
}
1352+
1353+
Some(tarball.generate())
1354+
}
1355+
}
1356+
12851357
#[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
12861358
pub struct Rustfmt {
12871359
pub compiler: Compiler,
@@ -1452,6 +1524,10 @@ impl Step for Extended {
14521524
add_component!("clippy" => Clippy { compiler, target });
14531525
add_component!("miri" => Miri { compiler, target });
14541526
add_component!("analysis" => Analysis { compiler, target });
1527+
add_component!("rustc-codegen-cranelift" => CodegenBackend {
1528+
compiler: builder.compiler(stage, target),
1529+
backend: INTERNER.intern_str("cranelift"),
1530+
});
14551531

14561532
let etc = builder.src.join("src/etc/installer");
14571533

@@ -1548,6 +1624,7 @@ impl Step for Extended {
15481624
prepare(tool);
15491625
}
15501626
}
1627+
prepare("rustc-codegen-cranelift");
15511628
// create an 'uninstall' package
15521629
builder.install(&etc.join("pkg/postinstall"), &pkg.join("uninstall"), 0o755);
15531630
pkgbuild("uninstall");
@@ -1587,6 +1664,10 @@ impl Step for Extended {
15871664
"rust-demangler-preview".to_string()
15881665
} else if name == "miri" {
15891666
"miri-preview".to_string()
1667+
} else if name == "rustc-codegen-cranelift" {
1668+
// FIXME add installer support for cg_clif once it is ready to be distributed on
1669+
// windows.
1670+
unreachable!("cg_clif shouldn't be built for windows");
15901671
} else {
15911672
name.to_string()
15921673
};

src/bootstrap/src/core/build_steps/install.rs

+14
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
1313
use crate::core::config::{Config, TargetSelection};
1414
use crate::utils::helpers::t;
1515
use crate::utils::tarball::GeneratedTarball;
16+
use crate::INTERNER;
1617
use crate::{Compiler, Kind};
1718

1819
#[cfg(target_os = "illumos")]
@@ -281,6 +282,19 @@ install!((self, builder, _config),
281282
});
282283
install_sh(builder, "rustc", self.compiler.stage, Some(self.target), &tarball);
283284
};
285+
RustcCodegenCranelift, alias = "rustc-codegen-cranelift", Self::should_build(_config), only_hosts: true, {
286+
if let Some(tarball) = builder.ensure(dist::CodegenBackend {
287+
compiler: self.compiler,
288+
backend: INTERNER.intern_str("cranelift"),
289+
}) {
290+
install_sh(builder, "rustc-codegen-cranelift", self.compiler.stage, Some(self.target), &tarball);
291+
} else {
292+
builder.info(
293+
&format!("skipping Install CodegenBackend(\"cranelift\") stage{} ({})",
294+
self.compiler.stage, self.target),
295+
);
296+
}
297+
};
284298
);
285299

286300
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]

src/bootstrap/src/core/build_steps/test.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ use crate::core::config::TargetSelection;
2828
use crate::utils;
2929
use crate::utils::cache::{Interned, INTERNER};
3030
use crate::utils::helpers::{
31-
self, add_link_lib_path, dylib_path, dylib_path_var, output, t, up_to_date,
31+
self, add_link_lib_path, dylib_path, dylib_path_var, output, t,
32+
target_supports_cranelift_backend, up_to_date,
3233
};
3334
use crate::utils::render_tests::{add_flags_and_try_run_tests, try_run_tests};
3435
use crate::{envify, CLang, DocTests, GitRepo, Mode};
@@ -2997,15 +2998,7 @@ impl Step for CodegenCranelift {
29972998
return;
29982999
}
29993000

3000-
let triple = run.target.triple;
3001-
let target_supported = if triple.contains("linux") {
3002-
triple.contains("x86_64") || triple.contains("aarch64") || triple.contains("s390x")
3003-
} else if triple.contains("darwin") || triple.contains("windows") {
3004-
triple.contains("x86_64")
3005-
} else {
3006-
false
3007-
};
3008-
if !target_supported {
3001+
if !target_supports_cranelift_backend(run.target) {
30093002
builder.info("target not supported by rustc_codegen_cranelift. skipping");
30103003
return;
30113004
}

src/bootstrap/src/core/builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@ impl<'a> Builder<'a> {
815815
dist::JsonDocs,
816816
dist::Mingw,
817817
dist::Rustc,
818+
dist::CodegenBackend,
818819
dist::Std,
819820
dist::RustcDev,
820821
dist::Analysis,

src/bootstrap/src/utils/helpers.rs

+10
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,16 @@ pub fn use_host_linker(target: TargetSelection) -> bool {
183183
|| target.contains("switch"))
184184
}
185185

186+
pub fn target_supports_cranelift_backend(target: TargetSelection) -> bool {
187+
if target.contains("linux") {
188+
target.contains("x86_64") || target.contains("aarch64") || target.contains("s390x")
189+
} else if target.contains("darwin") || target.contains("windows") {
190+
target.contains("x86_64")
191+
} else {
192+
false
193+
}
194+
}
195+
186196
pub fn is_valid_test_suite_arg<'a, P: AsRef<Path>>(
187197
path: &'a Path,
188198
suite_path: P,

src/bootstrap/src/utils/tarball.rs

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub(crate) enum OverlayKind {
1919
RustDemangler,
2020
RLS,
2121
RustAnalyzer,
22+
RustcCodegenCranelift,
2223
}
2324

2425
impl OverlayKind {
@@ -58,6 +59,11 @@ impl OverlayKind {
5859
"src/tools/rust-analyzer/LICENSE-APACHE",
5960
"src/tools/rust-analyzer/LICENSE-MIT",
6061
],
62+
OverlayKind::RustcCodegenCranelift => &[
63+
"compiler/rustc_codegen_cranelift/Readme.md",
64+
"compiler/rustc_codegen_cranelift/LICENSE-APACHE",
65+
"compiler/rustc_codegen_cranelift/LICENSE-MIT",
66+
],
6167
}
6268
}
6369

@@ -80,6 +86,7 @@ impl OverlayKind {
8086
OverlayKind::RustAnalyzer => builder
8187
.rust_analyzer_info
8288
.version(builder, &builder.release_num("rust-analyzer/crates/rust-analyzer")),
89+
OverlayKind::RustcCodegenCranelift => builder.rust_version(),
8390
}
8491
}
8592
}

src/ci/run.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ if [ "$DEPLOY$DEPLOY_ALT" = "1" ]; then
104104
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-llvm-assertions"
105105
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.verify-llvm-ir"
106106
fi
107+
108+
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.codegen-backends=llvm,cranelift"
107109
else
108110
# We almost always want debug assertions enabled, but sometimes this takes too
109111
# long for too little benefit, so we just turn them off.
@@ -124,7 +126,6 @@ else
124126

125127
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.verify-llvm-ir"
126128

127-
# Test the Cranelift backend in on CI, but don't ship it.
128129
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.codegen-backends=llvm,cranelift"
129130

130131
# We enable this for non-dist builders, since those aren't trying to produce

src/tools/build-manifest/src/main.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ static PKG_INSTALLERS: &[&str] = &["x86_64-apple-darwin", "aarch64-apple-darwin"
191191

192192
static MINGW: &[&str] = &["i686-pc-windows-gnu", "x86_64-pc-windows-gnu"];
193193

194-
static NIGHTLY_ONLY_COMPONENTS: &[PkgType] = &[PkgType::Miri, PkgType::JsonDocs];
194+
static NIGHTLY_ONLY_COMPONENTS: &[PkgType] =
195+
&[PkgType::Miri, PkgType::JsonDocs, PkgType::RustcCodegenCranelift];
195196

196197
macro_rules! t {
197198
($e:expr) => {
@@ -335,7 +336,15 @@ impl Builder {
335336

336337
// NOTE: this profile is effectively deprecated; do not add new components to it.
337338
let mut complete = default;
338-
complete.extend([Rls, RustAnalyzer, RustSrc, LlvmTools, RustAnalysis, Miri]);
339+
complete.extend([
340+
Rls,
341+
RustAnalyzer,
342+
RustSrc,
343+
LlvmTools,
344+
RustAnalysis,
345+
Miri,
346+
RustcCodegenCranelift,
347+
]);
339348
profile("complete", &complete);
340349

341350
// The compiler libraries are not stable for end users, and they're also huge, so we only
@@ -422,7 +431,8 @@ impl Builder {
422431
| PkgType::Rustfmt
423432
| PkgType::LlvmTools
424433
| PkgType::RustAnalysis
425-
| PkgType::JsonDocs => {
434+
| PkgType::JsonDocs
435+
| PkgType::RustcCodegenCranelift => {
426436
extensions.push(host_component(pkg));
427437
}
428438
PkgType::RustcDev | PkgType::RustcDocs => {

src/tools/build-manifest/src/versions.rs

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pkg_type! {
5757
LlvmTools = "llvm-tools"; preview = true,
5858
Miri = "miri"; preview = true,
5959
JsonDocs = "rust-docs-json"; preview = true,
60+
RustcCodegenCranelift = "rustc-codegen-cranelift"; preview = true,
6061
}
6162

6263
impl PkgType {
@@ -80,6 +81,7 @@ impl PkgType {
8081
PkgType::Rustfmt => false,
8182
PkgType::LlvmTools => false,
8283
PkgType::Miri => false,
84+
PkgType::RustcCodegenCranelift => false,
8385

8486
PkgType::Rust => true,
8587
PkgType::RustStd => true,
@@ -106,6 +108,8 @@ impl PkgType {
106108
ReproducibleArtifacts => HOSTS,
107109
RustcDocs => HOSTS,
108110
Cargo => HOSTS,
111+
// FIXME should this use the exact list of targets for which we build cg_clif?
112+
RustcCodegenCranelift => HOSTS,
109113
RustMingw => MINGW,
110114
RustStd => TARGETS,
111115
HtmlDocs => HOSTS,

0 commit comments

Comments
 (0)