Skip to content

Commit 9b29b66

Browse files
authored
Merge pull request #5 from athenavm/rust-1.80.0
Upgrade Rust and add macOS support
2 parents b6c3690 + 5ae09a5 commit 9b29b66

File tree

10 files changed

+99
-104
lines changed

10 files changed

+99
-104
lines changed

.github/workflows/build_and_release.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ jobs:
4040
4141
build-and-release:
4242
needs: prepare
43+
timeout-minutes: 120
4344
runs-on: ${{ matrix.os }}
4445

4546
strategy:
4647
matrix:
4748
os:
49+
# self-hosted ARM macOS runner
50+
- self-hosted
4851
- ubuntu-latest
49-
# - macos-latest
5052

5153
steps:
5254
- name: Free Disk Space (Ubuntu)
@@ -63,16 +65,18 @@ jobs:
6365

6466
- uses: actions/checkout@v4
6567

66-
- name: Install ninja
68+
- name: Install ninja and riscv-tools
6769
if: matrix.os == 'ubuntu-latest'
6870
run: |
6971
sudo apt update
70-
sudo apt-get -y install ninja-build
72+
sudo apt-get -y install ninja-build gcc-riscv64-unknown-elf
7173
72-
- name: Install ninja
74+
- name: Install ninja and riscv-tools
7375
if: contains(matrix.os, 'macos')
7476
run: |
7577
brew install ninja
78+
brew tap riscv-software-src/riscv
79+
brew install riscv-tools
7680
7781
- name: Download source
7882
run: ./clone.sh

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ jobs:
1212
include:
1313
- os: ubuntu-latest
1414
triple: x86_64-unknown-linux-gnu
15-
# - os: macos-14
16-
# triple: aarch64-apple-darwin
17-
# - os: macos-13
18-
# triple: x86_64-apple-darwin
15+
- os: macos-14
16+
triple: aarch64-apple-darwin
17+
- os: macos-13
18+
triple: x86_64-apple-darwin
1919
# - os: buildjet-32vcpu-ubuntu-2004
2020
# triple: x86_64-unknown-linux-gnu
2121
# - os: buildjet-32vcpu-ubuntu-2204-arm

build.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ set -euo pipefail
44

55
source config.sh
66

7+
# Fail fast if these tools aren't properly installed and in the path
8+
need_cmd riscv64-unknown-elf-gcc
9+
need_cmd riscv64-unknown-elf-g++
10+
11+
# Rust requires a custom target file to exist for our custom target as part of the bootstrap build,
12+
# but it doesn't actually look at the contents.
13+
touch /tmp/riscv32em-athena-zkvm-elf.json
14+
715
# Will create component archives (dists) ./rust/build/dist
816
cd rust
9-
CARGO_TARGET_RISCV32EM_ATHENA_ZKVM_ELF_RUSTFLAGS="-Cpasses=loweratomic" ./x build --stage 2
17+
RUST_TARGET_PATH="/tmp" \
18+
CARGO_TARGET_RISCV32EM_ATHENA_ZKVM_ELF_RUSTFLAGS="-Cpasses=loweratomic" \
19+
CFLAGS_riscv32em_athena_zkvm_elf="-ffunction-sections -fdata-sections -fPIC -march=rv32em -mabi=ilp32e" \
20+
./x build --stage 2

config.sh

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
param1=${1:-}
44

5-
export RUST_COMMIT=9b00956e56009bab2aa15d7bff10916599e3d6d6
5+
export RUST_COMMIT=051478957371ee0084a7c0913941d2a8c4757bb9
66

77
# If -rust_commit specified then only export the rust commit variable
88
if [ "$param1" == "-rust_commit" ]; then
@@ -17,3 +17,26 @@ export ARTIFACT_NAME=athena-rust-toolchain-$TOOLCHAIN_HOST_TRIPLET
1717
if [ "$param1" == "-artifact_name" ]; then
1818
echo "ARTIFACT_NAME=$ARTIFACT_NAME" >> $GITHUB_ENV
1919
fi
20+
21+
need_cmd() {
22+
if ! check_cmd "$1"; then
23+
err "need '$1' (command not found)"
24+
fi
25+
}
26+
27+
check_cmd() {
28+
command -v "$1" &>/dev/null
29+
}
30+
31+
say() {
32+
printf "rustc-rv32e-toolchain: %s\n" "$1"
33+
}
34+
35+
warn() {
36+
say "warning: ${1}" >&2
37+
}
38+
39+
err() {
40+
say "$1" >&2
41+
exit 1
42+
}

package.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,17 @@ set -euo pipefail
55
source config.sh
66

77
TOOLCHAIN_DIR=rust/build/$TOOLCHAIN_HOST_TRIPLET/stage2
8-
cp -n rust/build/$TOOLCHAIN_HOST_TRIPLET/stage2-tools-bin/* $TOOLCHAIN_DIR/bin
8+
TOOLS_BIN_DIR=rust/build/$TOOLCHAIN_HOST_TRIPLET/stage2-tools-bin
9+
10+
# Function to copy files, ignoring errors if destination exists
11+
copy_ignore_existing() {
12+
cp "$1" "$2" 2>/dev/null || true
13+
}
14+
15+
# Copy files from stage2-tools-bin to stage2/bin, ignoring if they already exist
16+
for file in "$TOOLS_BIN_DIR"/*; do
17+
copy_ignore_existing "$file" "$TOOLCHAIN_DIR/bin/"
18+
done
19+
20+
# Create tarball
921
tar --exclude lib/rustlib/src --exclude lib/rustlib/rustc-src -hczvf $ARTIFACT_NAME.tar.gz -C $TOOLCHAIN_DIR .

patch.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ set -euo pipefail
55
cd rust
66
patch -p1 < ../patches/rust.patch
77
cp ../patches/config.toml ./
8+
9+
cd src/llvm-project
10+
patch -p1 < ../../../patches/llvm.patch

patches/config.ci.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
change-id = 121754
1+
change-id = 125535
22

33
[build]
44
target = ["riscv32em-athena-zkvm-elf"]
@@ -7,6 +7,10 @@ tools = ["cargo", "cargo-clippy", "clippy", "rustfmt"]
77
configure-args = []
88
cargo-native-static = true
99

10+
[target.riscv32em-athena-zkvm-elf]
11+
cc = "riscv64-unknown-elf-gcc"
12+
cxx = "riscv64-unknown-elf-g++"
13+
1014
[rust]
1115
lld = true
1216
llvm-tools = true

patches/config.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
change-id = 121754
1+
change-id = 125535
22

33
[build]
44
target = ["riscv32em-athena-zkvm-elf"]
55
extended = true
66
tools = ["cargo", "cargo-clippy", "clippy", "rustfmt"]
77
configure-args = []
88

9+
[target.riscv32em-athena-zkvm-elf]
10+
cc = "riscv64-unknown-elf-gcc"
11+
cxx = "riscv64-unknown-elf-g++"
12+
913
[rust]
1014
lld = true
1115
llvm-tools = true

patches/llvm.patch

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt
2+
index 28ded8766..b51ebe8ea 100644
3+
--- a/compiler-rt/lib/builtins/CMakeLists.txt
4+
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
5+
@@ -849,9 +849,9 @@ else ()
6+
7+
# For RISCV32, we must force enable int128 for compiling long
8+
# double routines.
9+
- if(COMPILER_RT_ENABLE_SOFTWARE_INT128 OR "${arch}" STREQUAL "riscv32")
10+
- list(APPEND BUILTIN_CFLAGS_${arch} -fforce-enable-int128)
11+
- endif()
12+
+ #if(COMPILER_RT_ENABLE_SOFTWARE_INT128 OR "${arch}" STREQUAL "riscv32")
13+
+ # list(APPEND BUILTIN_CFLAGS_${arch} -fforce-enable-int128)
14+
+ #endif()
15+
16+
add_compiler_rt_runtime(clang_rt.builtins
17+
STATIC

patches/rust.patch

Lines changed: 8 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,8 @@
1-
diff --git a/Cargo.lock b/Cargo.lock
2-
index 927e93f2..dfbe7db5 100644
3-
--- a/Cargo.lock
4-
+++ b/Cargo.lock
5-
@@ -734,9 +734,8 @@ checksum = "55b672471b4e9f9e95499ea597ff64941a309b2cdbffcc46f2cc5e2d971fd335"
6-
7-
[[package]]
8-
name = "compiler_builtins"
9-
-version = "0.1.108"
10-
-source = "registry+https://github.com/rust-lang/crates.io-index"
11-
-checksum = "d68bc55329711cd719c2687bb147bc06211b0521f97ef398280108ccb23227e9"
12-
+version = "0.1.105"
13-
+source = "git+https://github.com/rust-lang/compiler-builtins?rev=0.1.105#80ed5f8c3ddbea7986c4a8243e42b963cb954b42"
14-
dependencies = [
15-
"cc",
16-
"rustc-std-workspace-core",
17-
diff --git a/Cargo.toml b/Cargo.toml
18-
index 5dd315ef2f7..680fb821c4c 100644
19-
--- a/Cargo.toml
20-
+++ b/Cargo.toml
21-
@@ -120,6 +120,7 @@ strip = true
22-
rustc-std-workspace-core = { path = 'library/rustc-std-workspace-core' }
23-
rustc-std-workspace-alloc = { path = 'library/rustc-std-workspace-alloc' }
24-
rustc-std-workspace-std = { path = 'library/rustc-std-workspace-std' }
25-
+compiler_builtins = { git = "https://github.com/rust-lang/compiler-builtins", rev = "0.1.105" }
26-
27-
[patch."https://github.com/rust-lang/rust-clippy"]
28-
clippy_lints = { path = "src/tools/clippy/clippy_lints" }
291
diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs
30-
index 941d767b..1b4004c4 100644
2+
index fe07d1167..07e786b6c 100644
313
--- a/compiler/rustc_target/src/spec/mod.rs
324
+++ b/compiler/rustc_target/src/spec/mod.rs
33-
@@ -1618,6 +1618,7 @@ fn $module() {
5+
@@ -1731,6 +1731,7 @@ fn $module() {
346

357
("x86_64-unikraft-linux-musl", x86_64_unikraft_linux_musl),
368

@@ -39,25 +11,25 @@ index 941d767b..1b4004c4 100644
3911
("riscv32im-risc0-zkvm-elf", riscv32im_risc0_zkvm_elf),
4012
("riscv32im-unknown-none-elf", riscv32im_unknown_none_elf),
4113
diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs
42-
index 5ed6b357e20..a31645ab6e7 100644
14+
index cde090637..07c9c5758 100644
4315
--- a/src/bootstrap/src/lib.rs
4416
+++ b/src/bootstrap/src/lib.rs
45-
@@ -91,6 +91,10 @@
17+
@@ -95,6 +95,10 @@
4618
/* Extra values not defined in the built-in targets yet, but used in std */
4719
(Some(Mode::Std), "target_env", Some(&["libnx", "p2"])),
48-
// (Some(Mode::Std), "target_os", Some(&[])),
20+
(Some(Mode::Std), "target_os", Some(&["visionos"])),
4921
+ // #[cfg(bootstrap)] zkvm
5022
+ (Some(Mode::Std), "target_os", Some(&["zkvm"])),
5123
+ // #[cfg(bootstrap)] athena
5224
+ (Some(Mode::Std), "target_vendor", Some(&["athena", "succinct"])),
5325
(Some(Mode::Std), "target_arch", Some(&["arm64ec", "spirv", "nvptx", "xtensa"])),
26+
(Some(Mode::ToolStd), "target_os", Some(&["visionos"])),
5427
/* Extra names used by dependencies */
55-
// FIXME: Used by serde_json, but we should not be triggering on external dependencies.
5628
diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs
57-
index eab9138b..60507063 100644
29+
index bed76263b..121843a30 100644
5830
--- a/src/tools/build-manifest/src/main.rs
5931
+++ b/src/tools/build-manifest/src/main.rs
60-
@@ -123,6 +123,7 @@
32+
@@ -125,6 +125,7 @@
6133
"powerpc-unknown-linux-gnu",
6234
"powerpc64-unknown-linux-gnu",
6335
"powerpc64le-unknown-linux-gnu",
@@ -115,58 +87,3 @@ index 00000000..a84f76c2
11587
+ }
11688
+}
11789
+
118-
diff --git a/library/std/src/sys/pal/zkvm/args.rs b/library/std/src/sys/pal/zkvm/args.rs
119-
index 7753cf63840..583c16e3a47 100644
120-
--- a/library/std/src/sys/pal/zkvm/args.rs
121-
+++ b/library/std/src/sys/pal/zkvm/args.rs
122-
@@ -1,6 +1,7 @@
123-
use super::{abi, WORD_SIZE};
124-
use crate::ffi::OsString;
125-
use crate::fmt;
126-
+use crate::sys::os_str;
127-
use crate::sys_common::FromInner;
128-
129-
pub struct Args {
130-
@@ -33,7 +34,7 @@ fn argv(i: usize) -> OsString {
131-
// "os_str".
132-
let arg_bytes: &[u8] =
133-
unsafe { crate::slice::from_raw_parts(words.cast() as *const u8, arg_len) };
134-
- OsString::from_inner(super::os_str::Buf { inner: arg_bytes.to_vec() })
135-
+ OsString::from_inner(os_str::Buf { inner: arg_bytes.to_vec() })
136-
}
137-
}
138-
139-
diff --git a/library/std/src/sys/pal/zkvm/mod.rs b/library/std/src/sys/pal/zkvm/mod.rs
140-
index 228a976dbab..c5a1843d5ff 100644
141-
--- a/library/std/src/sys/pal/zkvm/mod.rs
142-
+++ b/library/std/src/sys/pal/zkvm/mod.rs
143-
@@ -12,8 +12,6 @@
144-
pub mod alloc;
145-
#[path = "../zkvm/args.rs"]
146-
pub mod args;
147-
-#[path = "../unix/cmath.rs"]
148-
-pub mod cmath;
149-
pub mod env;
150-
#[path = "../unsupported/fs.rs"]
151-
pub mod fs;
152-
diff --git a/library/std/src/sys/pal/zkvm/os.rs b/library/std/src/sys/pal/zkvm/os.rs
153-
index d8739ee3824..759beb2d306 100644
154-
--- a/library/std/src/sys/pal/zkvm/os.rs
155-
+++ b/library/std/src/sys/pal/zkvm/os.rs
156-
@@ -5,6 +5,7 @@
157-
use crate::io;
158-
use crate::marker::PhantomData;
159-
use crate::path::{self, PathBuf};
160-
+use crate::sys::os_str;
161-
use crate::sys_common::FromInner;
162-
163-
pub fn errno() -> i32 {
164-
@@ -111,7 +112,7 @@ pub fn getenv(varname: &OsStr) -> Option<OsString> {
165-
// reimplement "os_str" instead of just using the generic unix
166-
// "os_str".
167-
let u8s: &[u8] = unsafe { crate::slice::from_raw_parts(words.cast() as *const u8, nbytes) };
168-
- Some(OsString::from_inner(super::os_str::Buf { inner: u8s.to_vec() }))
169-
+ Some(OsString::from_inner(os_str::Buf { inner: u8s.to_vec() }))
170-
}
171-
172-
pub fn setenv(_: &OsStr, _: &OsStr) -> io::Result<()> {

0 commit comments

Comments
 (0)