Skip to content

Commit

Permalink
Auto merge of rust-lang#128896 - bjorn3:sync_cg_clif-2024-08-09, r=bj…
Browse files Browse the repository at this point in the history
…orn3

Subtree sync for rustc_codegen_cranelift

The main highlight this time is support for raw-dylib on Windows thanks to `@dpaoliello.` Compiling the ring crate for arm64 macOS has been fixed too.

r? `@ghost`

`@rustbot` label +A-codegen +A-cranelift +T-compiler
  • Loading branch information
bors committed Aug 9, 2024
2 parents 19ebdce + 57dd967 commit ca5d25e
Show file tree
Hide file tree
Showing 30 changed files with 390 additions and 850 deletions.
13 changes: 9 additions & 4 deletions compiler/rustc_codegen_cranelift/.github/workflows/abi-cafe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ name: Abi-cafe

on:
- push
- pull_request

permissions: {}

jobs:
abi_cafe:
runs-on: ${{ matrix.os }}
timeout-minutes: 60
timeout-minutes: 30
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.os }}-${{ matrix.env.TARGET_TRIPLE }}
cancel-in-progress: true
Expand All @@ -27,12 +28,16 @@ jobs:
- os: macos-latest
env:
TARGET_TRIPLE: x86_64-apple-darwin
- os: windows-latest
- os: macos-latest
env:
TARGET_TRIPLE: x86_64-pc-windows-msvc
TARGET_TRIPLE: aarch64-apple-darwin
- os: windows-latest
env:
TARGET_TRIPLE: x86_64-pc-windows-gnu
TARGET_TRIPLE: x86_64-pc-windows-msvc
# FIXME Currently hangs. Re-enable once this is fixed or abi-cafe adds a timeout.
#- os: windows-latest
# env:
# TARGET_TRIPLE: x86_64-pc-windows-gnu

steps:
- uses: actions/checkout@v4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ jobs:
- uses: actions/checkout@v4
- run: |
sed -i 's/components.*/components = []/' rust-toolchain
echo 'profile = "minimal"' >> rust-toolchain
- uses: rustsec/audit-check@v1.4.1
with:
token: ${{ secrets.GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ jobs:
- name: Avoid installing rustc-dev
run: |
sed -i 's/components.*/components = ["rustfmt"]/' rust-toolchain
echo 'profile = "minimal"' >> rust-toolchain
rustfmt -v
- name: Rustfmt
Expand Down
68 changes: 68 additions & 0 deletions compiler/rustc_codegen_cranelift/.zed/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"format_on_save": "on",
"lsp": {
"rust-analyzer": {
"initialization_options": {
"diagnostics": {
// in case rustc.source is disabled for performance reasons; disable the errors about this
"disabled": ["unresolved-extern-crate", "unresolved-macro-call"]
},
"rustc": {
"source": "discover"
},
"imports": {
"granularity": {
"enforce": true,
"group": "module"
},
"prefix": "crate"
},
"cargo": {
"features": ["unstable-features"]
},
"linkedProjects": [
"./Cargo.toml",
"./build_system/Cargo.toml",
{
"crates": [
{
"root_module": "./example/mini_core.rs",
"edition": "2018",
"deps": [],
"cfg": []
},
{
"root_module": "./example/mini_core_hello_world.rs",
"edition": "2018",
"deps": [
{
"crate": 0,
"name": "mini_core"
}
],
"cfg": []
},
{
"root_module": "./example/mod_bench.rs",
"edition": "2018",
"deps": [],
"cfg": []
}
]
},
{
"sysroot_src": "./build/stdlib/library",
"crates": [
{
"root_module": "./example/std_example.rs",
"edition": "2015",
"deps": [],
"cfg": []
}
]
}
]
}
}
}
}
66 changes: 38 additions & 28 deletions compiler/rustc_codegen_cranelift/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,28 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"

[[package]]
name = "cranelift-bforest"
version = "0.109.0"
version = "0.110.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b6b33d7e757a887989eb18b35712b2a67d96171ec3149d1bfb657b29b7b367c"
checksum = "effa84ab2023f7138045ece6b326588c17447ca22e66db71ec15cb0a6c0c4ad2"
dependencies = [
"cranelift-entity",
]

[[package]]
name = "cranelift-bitset"
version = "0.110.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38a1dfc50dca188a15d938867c4400589530bcb0138f7022aae6d059d1d8c309"

[[package]]
name = "cranelift-codegen"
version = "0.109.0"
version = "0.110.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9acf15cb22be42d07c3b57d7856329cb228b7315d385346149df2566ad5e4aa"
checksum = "821c20c639350158ecca928dc2a244d0d1c9cef2377a378fc62a445a286eb1ca"
dependencies = [
"bumpalo",
"cranelift-bforest",
"cranelift-bitset",
"cranelift-codegen-meta",
"cranelift-codegen-shared",
"cranelift-control",
Expand All @@ -77,39 +84,42 @@ dependencies = [

[[package]]
name = "cranelift-codegen-meta"
version = "0.109.0"
version = "0.110.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e934d301392b73b3f8b0540391fb82465a0f179a3cee7c726482ac4727efcc97"
checksum = "064473f2fd59b44fa2c9aaa60de1f9c44db5e13521e28bc85d2b92ee535ef625"
dependencies = [
"cranelift-codegen-shared",
]

[[package]]
name = "cranelift-codegen-shared"
version = "0.109.0"
version = "0.110.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8afb2a2566b3d54b854dfb288b3b187f6d3d17d6f762c92898207eba302931da"
checksum = "d0f39b9ebfd2febdc2acfb9a0fca110665bcd5a6839502576307735ed07b2177"

[[package]]
name = "cranelift-control"
version = "0.109.0"
version = "0.110.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0100f33b704cdacd01ad66ff41f8c5030d57cbff078e2a4e49ab1822591299fa"
checksum = "94e125c189c3a1ca8dfe209fc6f46edba058a6d24e0b92aff69459a15f4711e7"
dependencies = [
"arbitrary",
]

[[package]]
name = "cranelift-entity"
version = "0.109.0"
version = "0.110.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8cfdc315e5d18997093e040a8d234bea1ac1e118a716d3e30f40d449e78207b"
checksum = "ea62eb109baec2247e1a6fa7b74c0f584b1e76e289cfd7017385b4b031fc8450"
dependencies = [
"cranelift-bitset",
]

[[package]]
name = "cranelift-frontend"
version = "0.109.0"
version = "0.110.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f74b84f16af2e982b0c0c72233503d9d55cbfe3865dbe807ca28dc6642a28b5"
checksum = "722b089357aacb6c7528b2e59a5fe00917d61ce63448b25a3e477a5b7819fac8"
dependencies = [
"cranelift-codegen",
"log",
Expand All @@ -119,15 +129,15 @@ dependencies = [

[[package]]
name = "cranelift-isle"
version = "0.109.0"
version = "0.110.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adf306d3dde705fb94bd48082f01d38c4ededc74293a4c007805f610bf08bc6e"
checksum = "c4b5005a48288e7fc2a2991a377831c534e26929b063c379c018060727785a9b"

[[package]]
name = "cranelift-jit"
version = "0.109.0"
version = "0.110.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f5c5cfb8bbd3339cd25cca30e7516ff8fe5cb1feeddde6980cc4d5ef34df97bb"
checksum = "f843932baf8d1025c5f114b929eda172d74b7163d058e0de2597c308b567c7e9"
dependencies = [
"anyhow",
"cranelift-codegen",
Expand All @@ -145,9 +155,9 @@ dependencies = [

[[package]]
name = "cranelift-module"
version = "0.109.0"
version = "0.110.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c9b0d4269b36fd858e6d8f20cd4938941186fb831488c361888cb2d6b33a9a6"
checksum = "449819ef1c4af139cf1b9717916fcaea0e23248853d3e95135139773a842d3eb"
dependencies = [
"anyhow",
"cranelift-codegen",
Expand All @@ -156,9 +166,9 @@ dependencies = [

[[package]]
name = "cranelift-native"
version = "0.109.0"
version = "0.110.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ea0ebdef7aff4a79bcbc8b6495f31315f16b3bf311152f472eaa8d679352581"
checksum = "3ae2d48f38081a9e679ad795bd36bb29bedeb5552fc1c195185bf9885fa1b16e"
dependencies = [
"cranelift-codegen",
"libc",
Expand All @@ -167,9 +177,9 @@ dependencies = [

[[package]]
name = "cranelift-object"
version = "0.109.0"
version = "0.110.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19e33439ec20db058bc7cc3410f9748ab1ad90a35cef713d625c736f43e3820d"
checksum = "3a39ee2cfd0ec485eca76f6b4dc17701a280fa406bc05137bb43f1635ed12c9f"
dependencies = [
"anyhow",
"cranelift-codegen",
Expand Down Expand Up @@ -279,9 +289,9 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"

[[package]]
name = "object"
version = "0.36.1"
version = "0.36.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "081b846d1d56ddfc18fdf1a922e4f6e07a11768ea1b92dec44e42b72712ccfce"
checksum = "3f203fa8daa7bb185f760ae12bd8e097f63d17041dcdcaf675ac54cdf863170e"
dependencies = [
"crc32fast",
"hashbrown 0.14.5",
Expand Down Expand Up @@ -411,9 +421,9 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"

[[package]]
name = "wasmtime-jit-icache-coherence"
version = "22.0.0"
version = "23.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5afe2f0499542f9a4bcfa1b55bfdda803b6ade4e7c93c6b99e0f39dba44b0a91"
checksum = "7fddf3e2980fb1d123d1fcac55189e417fdd3dba4f62139b5a0a1f9efe5669d5"
dependencies = [
"anyhow",
"cfg-if",
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_codegen_cranelift/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ crate-type = ["dylib"]

[dependencies]
# These have to be in sync with each other
cranelift-codegen = { version = "0.109.0", default-features = false, features = ["std", "unwind", "all-arch"] }
cranelift-frontend = { version = "0.109.0" }
cranelift-module = { version = "0.109.0" }
cranelift-native = { version = "0.109.0" }
cranelift-jit = { version = "0.109.0", optional = true }
cranelift-object = { version = "0.109.0" }
cranelift-codegen = { version = "0.110.1", default-features = false, features = ["std", "unwind", "all-arch"] }
cranelift-frontend = { version = "0.110.1" }
cranelift-module = { version = "0.110.1" }
cranelift-native = { version = "0.110.1" }
cranelift-jit = { version = "0.110.1", optional = true }
cranelift-object = { version = "0.110.1" }
target-lexicon = "0.12.0"
gimli = { version = "0.28", default-features = false, features = ["write"]}
object = { version = "0.36", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] }
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_codegen_cranelift/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ $ rustup component add rustc-codegen-cranelift-preview --toolchain nightly

Once it is installed, you can enable it with one of the following approaches:
- `CARGO_PROFILE_DEV_CODEGEN_BACKEND=cranelift cargo +nightly build -Zcodegen-backend`
- `RUSTFLAGS="-Zcodegen-backend=cranelift" cargo +nightly build`
- Add the following to `.cargo/config.toml`:
```toml
[unstable]
Expand Down
28 changes: 18 additions & 10 deletions compiler/rustc_codegen_cranelift/build_system/abi_cafe.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::path::Dirs;
use crate::path::{Dirs, RelPath};
use crate::prepare::GitRepo;
use crate::utils::{spawn_and_wait, CargoProject, Compiler};
use crate::{build_sysroot, CodegenBackend, SysrootKind};

static ABI_CAFE_REPO: GitRepo = GitRepo::github(
"Gankra",
"abi-cafe",
"4c6dc8c9c687e2b3a760ff2176ce236872b37212",
"588df6d66abbe105",
"f1220cfd13b57f5c0082c26529163865ee25e115",
"fe93a9acd461425d",
"abi-cafe",
);

Expand All @@ -21,6 +21,7 @@ pub(crate) fn run(
rustup_toolchain_name: Option<&str>,
bootstrap_host_compiler: &Compiler,
) {
RelPath::DOWNLOAD.ensure_exists(dirs);
ABI_CAFE_REPO.fetch(dirs);
ABI_CAFE_REPO.patch(dirs);

Expand All @@ -38,17 +39,23 @@ pub(crate) fn run(
eprintln!("Running abi-cafe");

let pairs = ["rustc_calls_cgclif", "cgclif_calls_rustc", "cgclif_calls_cc", "cc_calls_cgclif"];

let mut cmd = ABI_CAFE.run(bootstrap_host_compiler, dirs);
cmd.arg("--");
cmd.arg("--pairs");
cmd.args(
let pairs =
if cfg!(not(any(target_os = "macos", all(target_os = "windows", target_env = "msvc")))) {
&pairs[..]
} else {
&pairs[..2]
},
);
};

let mut cmd = ABI_CAFE.run(bootstrap_host_compiler, dirs);
cmd.arg("--");

// stdcall, vectorcall and such don't work yet
cmd.arg("--conventions").arg("c").arg("--conventions").arg("rust");

for pair in pairs {
cmd.arg("--pairs").arg(pair);
}

cmd.arg("--add-rustc-codegen-backend");
match cg_clif_dylib {
CodegenBackend::Local(path) => {
Expand All @@ -58,6 +65,7 @@ pub(crate) fn run(
cmd.arg(format!("cgclif:{name}"));
}
}

cmd.current_dir(ABI_CAFE.source_dir(dirs));

spawn_and_wait(cmd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ fn build_rtstartup(dirs: &Dirs, compiler: &Compiler) -> Option<SysrootTarget> {
let obj = RTSTARTUP_SYSROOT.to_path(dirs).join(format!("{file}.o"));
let mut build_rtstartup_cmd = Command::new(&compiler.rustc);
build_rtstartup_cmd
.arg("-Ainternal_features") // Missing #[allow(internal_features)]
.arg("--target")
.arg(&compiler.triple)
.arg("--emit=obj")
Expand Down
Loading

0 comments on commit ca5d25e

Please sign in to comment.