Skip to content

Commit 0b14d5a

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 ``` cc rust-lang/compiler-team#405. r? `@Mark-Simulacrum`
2 parents 964ff01 + 07c3bd2 commit 0b14d5a

File tree

14 files changed

+189
-82
lines changed

14 files changed

+189
-82
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ jobs:
553553
strategy:
554554
matrix:
555555
include:
556-
- name: dist-x86_64-linux
556+
- name: dist-arm-linux
557557
os: ubuntu-20.04-16core-64gb
558558
env: {}
559559
timeout-minutes: 600

compiler/rustc_codegen_cranelift/Cargo.lock

+30-43
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
2121

2222
[[package]]
2323
name = "arbitrary"
24-
version = "1.3.0"
24+
version = "1.3.1"
2525
source = "registry+https://github.com/rust-lang/crates.io-index"
26-
checksum = "e2d098ff73c1ca148721f37baad5ea6a465a13f9573aba8641fbbbae8164a54e"
26+
checksum = "a2e1373abdaa212b704512ec2bd8b26bd0b7d5c3f70117411a5d9a451383c859"
2727

2828
[[package]]
2929
name = "bitflags"
@@ -45,18 +45,16 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
4545

4646
[[package]]
4747
name = "cranelift-bforest"
48-
version = "0.101.1"
49-
source = "registry+https://github.com/rust-lang/crates.io-index"
50-
checksum = "c1512c3bb6b13018e7109fc3ac964bc87b329eaf3a77825d337558d0c7f6f1be"
48+
version = "0.102.0"
49+
source = "git+https://github.com/bjorn3/wasmtime.git?branch=allow_disabling_host_arch#abf01050f66d6e1565cbd2094e805135ecac81e3"
5150
dependencies = [
5251
"cranelift-entity",
5352
]
5453

5554
[[package]]
5655
name = "cranelift-codegen"
57-
version = "0.101.1"
58-
source = "registry+https://github.com/rust-lang/crates.io-index"
59-
checksum = "16cb8fb9220a6ea7a226705a273ab905309ee546267bdf34948d57932d7f0396"
56+
version = "0.102.0"
57+
source = "git+https://github.com/bjorn3/wasmtime.git?branch=allow_disabling_host_arch#abf01050f66d6e1565cbd2094e805135ecac81e3"
6058
dependencies = [
6159
"bumpalo",
6260
"cranelift-bforest",
@@ -75,39 +73,34 @@ dependencies = [
7573

7674
[[package]]
7775
name = "cranelift-codegen-meta"
78-
version = "0.101.1"
79-
source = "registry+https://github.com/rust-lang/crates.io-index"
80-
checksum = "ab3a8d3b0d4745b183da5ea0792b13d79f5c23d6e69ac04761728e2532b56649"
76+
version = "0.102.0"
77+
source = "git+https://github.com/bjorn3/wasmtime.git?branch=allow_disabling_host_arch#abf01050f66d6e1565cbd2094e805135ecac81e3"
8178
dependencies = [
8279
"cranelift-codegen-shared",
8380
]
8481

8582
[[package]]
8683
name = "cranelift-codegen-shared"
87-
version = "0.101.1"
88-
source = "registry+https://github.com/rust-lang/crates.io-index"
89-
checksum = "524141c8e68f2abc2043de4c2b31f6d9dd42432738c246431d0572a1422a4a84"
84+
version = "0.102.0"
85+
source = "git+https://github.com/bjorn3/wasmtime.git?branch=allow_disabling_host_arch#abf01050f66d6e1565cbd2094e805135ecac81e3"
9086

9187
[[package]]
9288
name = "cranelift-control"
93-
version = "0.101.1"
94-
source = "registry+https://github.com/rust-lang/crates.io-index"
95-
checksum = "97513b57c961c713789a03886a57b43e14ebcd204cbaa8ae50ca6c70a8e716b3"
89+
version = "0.102.0"
90+
source = "git+https://github.com/bjorn3/wasmtime.git?branch=allow_disabling_host_arch#abf01050f66d6e1565cbd2094e805135ecac81e3"
9691
dependencies = [
9792
"arbitrary",
9893
]
9994

10095
[[package]]
10196
name = "cranelift-entity"
102-
version = "0.101.1"
103-
source = "registry+https://github.com/rust-lang/crates.io-index"
104-
checksum = "e3f23d3cf3afa7e45f239702612c76d87964f652a55e28d13ed6d7e20f3479dd"
97+
version = "0.102.0"
98+
source = "git+https://github.com/bjorn3/wasmtime.git?branch=allow_disabling_host_arch#abf01050f66d6e1565cbd2094e805135ecac81e3"
10599

106100
[[package]]
107101
name = "cranelift-frontend"
108-
version = "0.101.1"
109-
source = "registry+https://github.com/rust-lang/crates.io-index"
110-
checksum = "554cd4947ec9209b58bf9ae5bf83581b5ddf9128bd967208e334b504a57db54e"
102+
version = "0.102.0"
103+
source = "git+https://github.com/bjorn3/wasmtime.git?branch=allow_disabling_host_arch#abf01050f66d6e1565cbd2094e805135ecac81e3"
111104
dependencies = [
112105
"cranelift-codegen",
113106
"log",
@@ -117,15 +110,13 @@ dependencies = [
117110

118111
[[package]]
119112
name = "cranelift-isle"
120-
version = "0.101.1"
121-
source = "registry+https://github.com/rust-lang/crates.io-index"
122-
checksum = "6c1892a439696b6413cb54083806f5fd9fc431768b8de74864b3d9e8b93b124f"
113+
version = "0.102.0"
114+
source = "git+https://github.com/bjorn3/wasmtime.git?branch=allow_disabling_host_arch#abf01050f66d6e1565cbd2094e805135ecac81e3"
123115

124116
[[package]]
125117
name = "cranelift-jit"
126-
version = "0.101.1"
127-
source = "registry+https://github.com/rust-lang/crates.io-index"
128-
checksum = "32209252fb38acaf1662ccd0397907bbe0e92bdb13b6ddbfd2f74e437f83e685"
118+
version = "0.102.0"
119+
source = "git+https://github.com/bjorn3/wasmtime.git?branch=allow_disabling_host_arch#abf01050f66d6e1565cbd2094e805135ecac81e3"
129120
dependencies = [
130121
"anyhow",
131122
"cranelift-codegen",
@@ -143,9 +134,8 @@ dependencies = [
143134

144135
[[package]]
145136
name = "cranelift-module"
146-
version = "0.101.1"
147-
source = "registry+https://github.com/rust-lang/crates.io-index"
148-
checksum = "bf42656f5f6df7bfafc4dd7b63a1888b0627c07b43b2cb9aa54e13843fed39eb"
137+
version = "0.102.0"
138+
source = "git+https://github.com/bjorn3/wasmtime.git?branch=allow_disabling_host_arch#abf01050f66d6e1565cbd2094e805135ecac81e3"
149139
dependencies = [
150140
"anyhow",
151141
"cranelift-codegen",
@@ -154,9 +144,8 @@ dependencies = [
154144

155145
[[package]]
156146
name = "cranelift-native"
157-
version = "0.101.1"
158-
source = "registry+https://github.com/rust-lang/crates.io-index"
159-
checksum = "e0c2d3badd4b9690865f5bb68a71fa94de592fa2df3f3d11a5a062c60c0a107a"
147+
version = "0.102.0"
148+
source = "git+https://github.com/bjorn3/wasmtime.git?branch=allow_disabling_host_arch#abf01050f66d6e1565cbd2094e805135ecac81e3"
160149
dependencies = [
161150
"cranelift-codegen",
162151
"libc",
@@ -165,9 +154,8 @@ dependencies = [
165154

166155
[[package]]
167156
name = "cranelift-object"
168-
version = "0.101.1"
169-
source = "registry+https://github.com/rust-lang/crates.io-index"
170-
checksum = "88eca54bbecea3170035168357306e9c779d4a63d8bf036c9e16bd21fdaa69b5"
157+
version = "0.102.0"
158+
source = "git+https://github.com/bjorn3/wasmtime.git?branch=allow_disabling_host_arch#abf01050f66d6e1565cbd2094e805135ecac81e3"
171159
dependencies = [
172160
"anyhow",
173161
"cranelift-codegen",
@@ -295,9 +283,9 @@ checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
295283

296284
[[package]]
297285
name = "regalloc2"
298-
version = "0.9.2"
286+
version = "0.9.3"
299287
source = "registry+https://github.com/rust-lang/crates.io-index"
300-
checksum = "5b4dcbd3a2ae7fb94b5813fa0e957c6ab51bf5d0a8ee1b69e0c2d0f1e6eb8485"
288+
checksum = "ad156d539c879b7a24a363a2016d77961786e71f48f2e2fc8302a92abd2429a6"
301289
dependencies = [
302290
"hashbrown 0.13.2",
303291
"log",
@@ -374,9 +362,8 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
374362

375363
[[package]]
376364
name = "wasmtime-jit-icache-coherence"
377-
version = "14.0.1"
378-
source = "registry+https://github.com/rust-lang/crates.io-index"
379-
checksum = "9aaf2fa8fd2d6b65abae9b92edfe69254cc5d6b166e342364036c3e347de8da9"
365+
version = "15.0.0"
366+
source = "git+https://github.com/bjorn3/wasmtime.git?branch=allow_disabling_host_arch#abf01050f66d6e1565cbd2094e805135ecac81e3"
380367
dependencies = [
381368
"cfg-if",
382369
"libc",

compiler/rustc_codegen_cranelift/Cargo.toml

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ crate-type = ["dylib"]
88

99
[dependencies]
1010
# These have to be in sync with each other
11-
cranelift-codegen = { version = "0.101.1", features = ["unwind", "all-arch"] }
12-
cranelift-frontend = { version = "0.101.1" }
13-
cranelift-module = { version = "0.101.1" }
14-
cranelift-native = { version = "0.101.1" }
15-
cranelift-jit = { version = "0.101.1", optional = true }
16-
cranelift-object = { version = "0.101.1" }
11+
cranelift-codegen = { git = "https://github.com/bjorn3/wasmtime.git", branch = "allow_disabling_host_arch", version = "0.102", default-features = false, features = ["std", "unwind", "all-arch"] }
12+
cranelift-frontend = { git = "https://github.com/bjorn3/wasmtime.git", branch = "allow_disabling_host_arch", version = "0.102" }
13+
cranelift-module = { git = "https://github.com/bjorn3/wasmtime.git", branch = "allow_disabling_host_arch", version = "0.102" }
14+
cranelift-native = { git = "https://github.com/bjorn3/wasmtime.git", branch = "allow_disabling_host_arch", version = "0.102" }
15+
cranelift-jit = { git = "https://github.com/bjorn3/wasmtime.git", branch = "allow_disabling_host_arch", version = "0.102", optional = true }
16+
cranelift-object = { git = "https://github.com/bjorn3/wasmtime.git", branch = "allow_disabling_host_arch", version = "0.102" }
1717
target-lexicon = "0.12.0"
1818
gimli = { version = "0.28", default-features = false, features = ["write"]}
1919
object = { version = "0.32", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] }

compiler/rustc_codegen_cranelift/src/pretty_clif.rs

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ impl FuncWriter for &'_ CommentWriter {
155155
_func: &Function,
156156
entity: AnyEntity,
157157
value: &dyn fmt::Display,
158+
_fact: Option<&cranelift_codegen::ir::pcc::Fact>,
158159
) -> fmt::Result {
159160
write!(w, " {} = {}", entity, value)?;
160161

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)]

0 commit comments

Comments
 (0)