Skip to content

Commit 42e1761

Browse files
committed
Auto merge of rust-lang#97057 - bjorn3:sync_cg_clif-2022-05-15, r=bjorn3
Sync rustc_codegen_cranelift Since the last sync there have mostly been fixes of various sorts. I also changed cg_clif from using a custom driver to `-Zcodegen-backend` when built as separate project. When built as part of rust it was already using `-Zcodegen-backend`. r? `@ghost` `@rustbot` label +A-codegen +A-cranelift +T-compiler
2 parents 29e972d + ecd8fa1 commit 42e1761

28 files changed

+269
-425
lines changed

compiler/rustc_codegen_cranelift/.github/workflows/main.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
timeout-minutes: 10
1111

1212
steps:
13-
- uses: actions/checkout@v2
13+
- uses: actions/checkout@v3
1414

1515
- name: Install rustfmt
1616
run: |
@@ -39,7 +39,7 @@ jobs:
3939
TARGET_TRIPLE: aarch64-unknown-linux-gnu
4040

4141
steps:
42-
- uses: actions/checkout@v2
42+
- uses: actions/checkout@v3
4343

4444
- name: Cache cargo installed crates
4545
uses: actions/cache@v2
@@ -127,7 +127,7 @@ jobs:
127127
timeout-minutes: 60
128128

129129
steps:
130-
- uses: actions/checkout@v2
130+
- uses: actions/checkout@v3
131131

132132
#- name: Cache cargo installed crates
133133
# uses: actions/cache@v2

compiler/rustc_codegen_cranelift/.github/workflows/nightly-cranelift.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
timeout-minutes: 60
1212

1313
steps:
14-
- uses: actions/checkout@v2
14+
- uses: actions/checkout@v3
1515

1616
- name: Cache cargo installed crates
1717
uses: actions/cache@v2
@@ -34,7 +34,7 @@ jobs:
3434
sed -i 's/cranelift-jit = { version = "\w*.\w*.\w*", optional = true }/cranelift-jit = { git = "https:\/\/github.com\/bytecodealliance\/wasmtime.git", optional = true }/' Cargo.toml
3535
sed -i 's/cranelift-object = "\w*.\w*.\w*"/cranelift-object = { git = "https:\/\/github.com\/bytecodealliance\/wasmtime.git" }/' Cargo.toml
3636
37-
sed -i 's/gimli = { version = "0.25.0", default-features = false, features = \["write"\]}/gimli = { version = "0.26.1", default-features = false, features = ["write"] }/' Cargo.toml
37+
sed -i 's/object = { version = "0.27.0"/object = { version = "0.28.0"/' Cargo.toml
3838
3939
cat Cargo.toml
4040

compiler/rustc_codegen_cranelift/.github/workflows/rustc.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- uses: actions/checkout@v2
11+
- uses: actions/checkout@v3
1212

1313
- name: Cache cargo installed crates
1414
uses: actions/cache@v2
@@ -46,7 +46,7 @@ jobs:
4646
runs-on: ubuntu-latest
4747

4848
steps:
49-
- uses: actions/checkout@v2
49+
- uses: actions/checkout@v3
5050

5151
- name: Cache cargo installed crates
5252
uses: actions/cache@v2

compiler/rustc_codegen_cranelift/.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"rust-analyzer.assist.importEnforceGranularity": true,
66
"rust-analyzer.assist.importPrefix": "crate",
77
"rust-analyzer.cargo.runBuildScripts": true,
8-
"rust-analyzer.cargo.features": ["unstable-features"]
8+
"rust-analyzer.cargo.features": ["unstable-features"],
99
"rust-analyzer.linkedProjects": [
1010
"./Cargo.toml",
1111
//"./build_sysroot/sysroot_src/src/libstd/Cargo.toml",

compiler/rustc_codegen_cranelift/Cargo.toml

-10
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,5 @@ unstable-features = ["jit", "inline_asm"]
4141
jit = ["cranelift-jit", "libloading"]
4242
inline_asm = []
4343

44-
# Disable optimizations and debuginfo of build scripts and some of the heavy build deps, as the
45-
# execution time of build scripts is so fast that optimizing them slows down the total build time.
46-
[profile.release.build-override]
47-
opt-level = 0
48-
debug = false
49-
50-
[profile.release.package.cranelift-codegen-meta]
51-
opt-level = 0
52-
debug = false
53-
5444
[package.metadata.rust-analyzer]
5545
rustc_private = true

compiler/rustc_codegen_cranelift/build_sysroot/Cargo.lock

+6-6
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ dependencies = [
112112

113113
[[package]]
114114
name = "hashbrown"
115-
version = "0.12.0"
115+
version = "0.12.1"
116116
source = "registry+https://github.com/rust-lang/crates.io-index"
117-
checksum = "8c21d40587b92fa6a6c6e3c1bdbf87d75511db5672f9c93175574b3a00df1758"
117+
checksum = "db0d4cf898abf0081f964436dc980e96670a0f36863e4b83aaacdb65c9d7ccc3"
118118
dependencies = [
119119
"compiler_builtins",
120120
"rustc-std-workspace-alloc",
@@ -134,18 +134,18 @@ dependencies = [
134134

135135
[[package]]
136136
name = "libc"
137-
version = "0.2.124"
137+
version = "0.2.125"
138138
source = "registry+https://github.com/rust-lang/crates.io-index"
139-
checksum = "21a41fed9d98f27ab1c6d161da622a4fa35e8a54a8adc24bbf3ddd0ef70b0e50"
139+
checksum = "5916d2ae698f6de9bfb891ad7a8d65c09d232dc58cc4ac433c7da3b2fd84bc2b"
140140
dependencies = [
141141
"rustc-std-workspace-core",
142142
]
143143

144144
[[package]]
145145
name = "memchr"
146-
version = "2.4.1"
146+
version = "2.5.0"
147147
source = "registry+https://github.com/rust-lang/crates.io-index"
148-
checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
148+
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
149149
dependencies = [
150150
"compiler_builtins",
151151
"rustc-std-workspace-core",

compiler/rustc_codegen_cranelift/build_system/build_backend.rs

-12
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,6 @@ pub(crate) fn build_backend(
3434
_ => unreachable!(),
3535
}
3636

37-
// Set the rpath to make the cg_clif executable find librustc_codegen_cranelift without changing
38-
// LD_LIBRARY_PATH
39-
if cfg!(unix) {
40-
if cfg!(target_os = "macos") {
41-
rustflags += " -Csplit-debuginfo=unpacked \
42-
-Clink-arg=-Wl,-rpath,@loader_path/../lib \
43-
-Zosx-rpath-install-name";
44-
} else {
45-
rustflags += " -Clink-arg=-Wl,-rpath=$ORIGIN/../lib ";
46-
}
47-
}
48-
4937
cmd.env("RUSTFLAGS", rustflags);
5038

5139
eprintln!("[BUILD] rustc_codegen_cranelift");

compiler/rustc_codegen_cranelift/build_system/build_sysroot.rs

+44-42
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::env;
21
use std::fs;
32
use std::path::{Path, PathBuf};
43
use std::process::{self, Command};
@@ -22,35 +21,28 @@ pub(crate) fn build_sysroot(
2221
fs::create_dir_all(target_dir.join("lib")).unwrap();
2322

2423
// Copy the backend
25-
for file in ["cg_clif", "cg_clif_build_sysroot"] {
26-
try_hard_link(
27-
cg_clif_build_dir.join(get_file_name(file, "bin")),
28-
target_dir.join("bin").join(get_file_name(file, "bin")),
29-
);
30-
}
31-
3224
let cg_clif_dylib = get_file_name("rustc_codegen_cranelift", "dylib");
33-
try_hard_link(
34-
cg_clif_build_dir.join(&cg_clif_dylib),
35-
target_dir
36-
.join(if cfg!(windows) {
37-
// Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the
38-
// binaries.
39-
"bin"
40-
} else {
41-
"lib"
42-
})
43-
.join(cg_clif_dylib),
44-
);
45-
46-
// Build and copy cargo wrapper
47-
let mut build_cargo_wrapper_cmd = Command::new("rustc");
48-
build_cargo_wrapper_cmd
49-
.arg("scripts/cargo-clif.rs")
50-
.arg("-o")
51-
.arg(target_dir.join("cargo-clif"))
52-
.arg("-g");
53-
spawn_and_wait(build_cargo_wrapper_cmd);
25+
let cg_clif_dylib_path = target_dir
26+
.join(if cfg!(windows) {
27+
// Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the
28+
// binaries.
29+
"bin"
30+
} else {
31+
"lib"
32+
})
33+
.join(&cg_clif_dylib);
34+
try_hard_link(cg_clif_build_dir.join(cg_clif_dylib), &cg_clif_dylib_path);
35+
36+
// Build and copy rustc and cargo wrappers
37+
for wrapper in ["rustc-clif", "cargo-clif"] {
38+
let mut build_cargo_wrapper_cmd = Command::new("rustc");
39+
build_cargo_wrapper_cmd
40+
.arg(PathBuf::from("scripts").join(format!("{wrapper}.rs")))
41+
.arg("-o")
42+
.arg(target_dir.join(wrapper))
43+
.arg("-g");
44+
spawn_and_wait(build_cargo_wrapper_cmd);
45+
}
5446

5547
let default_sysroot = super::rustc_info::get_default_sysroot();
5648

@@ -117,7 +109,13 @@ pub(crate) fn build_sysroot(
117109
}
118110
}
119111
SysrootKind::Clif => {
120-
build_clif_sysroot_for_triple(channel, target_dir, host_triple, None);
112+
build_clif_sysroot_for_triple(
113+
channel,
114+
target_dir,
115+
host_triple,
116+
&cg_clif_dylib_path,
117+
None,
118+
);
121119

122120
if host_triple != target_triple {
123121
// When cross-compiling it is often necessary to manually pick the right linker
@@ -126,14 +124,21 @@ pub(crate) fn build_sysroot(
126124
} else {
127125
None
128126
};
129-
build_clif_sysroot_for_triple(channel, target_dir, target_triple, linker);
127+
build_clif_sysroot_for_triple(
128+
channel,
129+
target_dir,
130+
target_triple,
131+
&cg_clif_dylib_path,
132+
linker,
133+
);
130134
}
131135

132136
// Copy std for the host to the lib dir. This is necessary for the jit mode to find
133137
// libstd.
134138
for file in fs::read_dir(host_rustlib_lib).unwrap() {
135139
let file = file.unwrap().path();
136-
if file.file_name().unwrap().to_str().unwrap().contains("std-") {
140+
let filename = file.file_name().unwrap().to_str().unwrap();
141+
if filename.contains("std-") && !filename.contains(".rlib") {
137142
try_hard_link(&file, target_dir.join("lib").join(file.file_name().unwrap()));
138143
}
139144
}
@@ -145,6 +150,7 @@ fn build_clif_sysroot_for_triple(
145150
channel: &str,
146151
target_dir: &Path,
147152
triple: &str,
153+
cg_clif_dylib_path: &Path,
148154
linker: Option<&str>,
149155
) {
150156
match fs::read_to_string(Path::new("build_sysroot").join("rustc_version")) {
@@ -168,18 +174,18 @@ fn build_clif_sysroot_for_triple(
168174
let build_dir = Path::new("build_sysroot").join("target").join(triple).join(channel);
169175

170176
if !super::config::get_bool("keep_sysroot") {
171-
// Cleanup the target dir with the exception of build scripts and the incremental cache
172-
for dir in ["build", "deps", "examples", "native"] {
173-
if build_dir.join(dir).exists() {
174-
fs::remove_dir_all(build_dir.join(dir)).unwrap();
175-
}
177+
// Cleanup the deps dir, but keep build scripts and the incremental cache for faster
178+
// recompilation as they are not affected by changes in cg_clif.
179+
if build_dir.join("deps").exists() {
180+
fs::remove_dir_all(build_dir.join("deps")).unwrap();
176181
}
177182
}
178183

179184
// Build sysroot
180185
let mut build_cmd = Command::new("cargo");
181186
build_cmd.arg("build").arg("--target").arg(triple).current_dir("build_sysroot");
182-
let mut rustflags = "--clif -Zforce-unstable-if-unmarked".to_string();
187+
let mut rustflags = "-Zforce-unstable-if-unmarked -Cpanic=abort".to_string();
188+
rustflags.push_str(&format!(" -Zcodegen-backend={}", cg_clif_dylib_path.to_str().unwrap()));
183189
if channel == "release" {
184190
build_cmd.arg("--release");
185191
rustflags.push_str(" -Zmir-opt-level=3");
@@ -189,10 +195,6 @@ fn build_clif_sysroot_for_triple(
189195
write!(rustflags, " -Clinker={}", linker).unwrap();
190196
}
191197
build_cmd.env("RUSTFLAGS", rustflags);
192-
build_cmd.env(
193-
"RUSTC",
194-
env::current_dir().unwrap().join(target_dir).join("bin").join("cg_clif_build_sysroot"),
195-
);
196198
build_cmd.env("__CARGO_DEFAULT_LIB_METADATA", "cg_clif");
197199
spawn_and_wait(build_cmd);
198200

compiler/rustc_codegen_cranelift/build_system/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ pub fn main() {
8686
arg => arg_error!("Unexpected argument {}", arg),
8787
}
8888
}
89+
target_dir = std::env::current_dir().unwrap().join(target_dir);
8990

9091
let host_triple = if let Ok(host_triple) = std::env::var("HOST_TRIPLE") {
9192
host_triple

compiler/rustc_codegen_cranelift/docs/usage.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ This will build your project with rustc_codegen_cranelift instead of the usual L
1919
> You should prefer using the Cargo method.
2020
2121
```bash
22-
$ $cg_clif_dir/build/bin/cg_clif my_crate.rs
22+
$ $cg_clif_dir/build/rustc-clif my_crate.rs
2323
```
2424

2525
## Jit mode
@@ -38,7 +38,7 @@ $ $cg_clif_dir/build/cargo-clif jit
3838
or
3939

4040
```bash
41-
$ $cg_clif_dir/build/bin/cg_clif -Zunstable-features -Cllvm-args=mode=jit -Cprefer-dynamic my_crate.rs
41+
$ $cg_clif_dir/build/rustc-clif -Zunstable-features -Cllvm-args=mode=jit -Cprefer-dynamic my_crate.rs
4242
```
4343

4444
There is also an experimental lazy jit mode. In this mode functions are only compiled once they are
@@ -54,7 +54,7 @@ These are a few functions that allow you to easily run rust code from the shell
5454

5555
```bash
5656
function jit_naked() {
57-
echo "$@" | $cg_clif_dir/build/bin/cg_clif - -Zunstable-features -Cllvm-args=mode=jit -Cprefer-dynamic
57+
echo "$@" | $cg_clif_dir/build/rustc-clif - -Zunstable-features -Cllvm-args=mode=jit -Cprefer-dynamic
5858
}
5959

6060
function jit() {

compiler/rustc_codegen_cranelift/patches/0027-sysroot-128bit-atomic-operations.patch

+6-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ index 092b7cf..158cf71 100644
2121
-#[cfg(target_has_atomic_load_store = "128")]
2222
-#[unstable(feature = "integer_atomics", issue = "32976")]
2323
-impl RefUnwindSafe for crate::sync::atomic::AtomicI128 {}
24-
24+
2525
#[cfg(target_has_atomic_load_store = "ptr")]
2626
#[stable(feature = "unwind_safe_atomic_refs", since = "1.14.0")]
2727
@@ -235,9 +232,6 @@ impl RefUnwindSafe for crate::sync::atomic::AtomicU32 {}
@@ -31,14 +31,14 @@ index 092b7cf..158cf71 100644
3131
-#[cfg(target_has_atomic_load_store = "128")]
3232
-#[unstable(feature = "integer_atomics", issue = "32976")]
3333
-impl RefUnwindSafe for crate::sync::atomic::AtomicU128 {}
34-
34+
3535
#[cfg(target_has_atomic_load_store = "8")]
3636
#[stable(feature = "unwind_safe_atomic_refs", since = "1.14.0")]
3737
diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs
3838
index d9de37e..8293fce 100644
3939
--- a/library/core/src/sync/atomic.rs
4040
+++ b/library/core/src/sync/atomic.rs
41-
@@ -2234,44 +2234,6 @@ atomic_int! {
41+
@@ -2234,46 +2234,6 @@ atomic_int! {
4242
"AtomicU64::new(0)",
4343
u64 AtomicU64 ATOMIC_U64_INIT
4444
}
@@ -54,6 +54,7 @@ index d9de37e..8293fce 100644
5454
- unstable(feature = "integer_atomics", issue = "32976"),
5555
- rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"),
5656
- unstable(feature = "integer_atomics", issue = "32976"),
57+
- cfg_attr(not(test), rustc_diagnostic_item = "AtomicI128"),
5758
- "i128",
5859
- "#![feature(integer_atomics)]\n\n",
5960
- atomic_min, atomic_max,
@@ -73,6 +74,7 @@ index d9de37e..8293fce 100644
7374
- unstable(feature = "integer_atomics", issue = "32976"),
7475
- rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"),
7576
- unstable(feature = "integer_atomics", issue = "32976"),
77+
- cfg_attr(not(test), rustc_diagnostic_item = "AtomicU128"),
7678
- "u128",
7779
- "#![feature(integer_atomics)]\n\n",
7880
- atomic_umin, atomic_umax,
@@ -98,6 +100,6 @@ index b735957..ea728b6 100644
98100
#[cfg(target_has_atomic = "ptr")]
99101
assert_eq!(align_of::<AtomicUsize>(), size_of::<AtomicUsize>());
100102
#[cfg(target_has_atomic = "ptr")]
101-
--
103+
--
102104
2.26.2.7.g19db9cfb68
103105

Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2022-04-21"
2+
channel = "nightly-2022-05-15"
33
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]

0 commit comments

Comments
 (0)