Skip to content

Commit b215d16

Browse files
committed
Switch to the correct RISC-V toolchain
1 parent c0772d0 commit b215d16

File tree

2 files changed

+58
-8
lines changed

2 files changed

+58
-8
lines changed

build.sh

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,64 @@ set -euo pipefail
55
source config.sh
66

77
# 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++
8+
need_cmd riscv32-unknown-elf-clang
9+
need_cmd riscv32-unknown-elf-clang++
1010

1111
# Rust requires a custom target file to exist for our custom target as part of the bootstrap build,
1212
# but it doesn't actually look at the contents.
13-
touch /tmp/riscv32em-athena-zkvm-elf.json
13+
cat > /tmp/riscv32em-athena-zkvm-elf.json << EOF
14+
{
15+
"arch": "riscv32",
16+
"cpu": "generic-rv32",
17+
"crt-objects-fallback": "false",
18+
"data-layout": "e-m:e-p:32:32-i64:64-n32-S32",
19+
"eh-frame-header": false,
20+
"emit-debug-gdb-scripts": false,
21+
"features": "+e,+m",
22+
"linker": "rust-lld",
23+
"linker-flavor": "gnu-lld",
24+
"llvm-abiname": "ilp32e",
25+
"llvm-target": "riscv32",
26+
"max-atomic-width": 32,
27+
"os": "zkvm",
28+
"panic-strategy": "abort",
29+
"relocation-model": "static",
30+
"singlethread": true,
31+
"target-pointer-width": "32",
32+
"vendor": "athena",
33+
"options": {
34+
"c-flags": "-march=rv32e -mabi=ilp32e",
35+
"pre-link-args": {
36+
"gcc": [
37+
"-march=rv32e",
38+
"-mabi=ilp32e"
39+
]
40+
}
41+
}
42+
}
43+
EOF
44+
45+
# Set environment variables to override compiler flags
46+
export CC_riscv32em_athena_zkvm_elf="riscv32-unknown-elf-clang"
47+
export CXX_riscv32em_athena_zkvm_elf="riscv32-unknown-elf-clang++"
48+
export AR_riscv32em_athena_zkvm_elf="riscv32-unknown-elf-ar"
49+
50+
# Explicitly set CFLAGS without the problematic flags
51+
export CFLAGS_riscv32em_athena_zkvm_elf="-ffunction-sections -fdata-sections -fPIC -target riscv32-unknown-elf"
52+
export CXXFLAGS_riscv32em_athena_zkvm_elf="$CFLAGS_riscv32em_athena_zkvm_elf"
53+
54+
# Set Rust flags
55+
export CARGO_TARGET_RISCV32EM_ATHENA_ZKVM_ELF_RUSTFLAGS="-Cpasses=loweratomic -Clink-arg=-march=rv32em -Clink-arg=-mabi=ilp32e"
56+
57+
# Override the default target for compiler-rt
58+
export COMPILER_RT_DEFAULT_TARGET_TRIPLE="riscv32-unknown-elf"
59+
60+
# Force the use of our custom target spec
61+
export RUST_TARGET_PATH="/tmp"
62+
63+
# Prevent the build system from adding --target flag
64+
export RUSTC_TARGET_ARG=""
1465

1566
# Will create component archives (dists) ./rust/build/dist
1667
cd rust
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" \
2068
./x build --stage 2

patches/config.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ tools = ["cargo", "cargo-clippy", "clippy", "rustfmt"]
77
configure-args = []
88

99
[target.riscv32em-athena-zkvm-elf]
10-
cc = "riscv64-unknown-elf-gcc"
11-
cxx = "riscv64-unknown-elf-g++"
10+
cc = "riscv32-unknown-elf-clang"
11+
cxx = "riscv32-unknown-elf-clang++"
12+
linker = "riscv32-unknown-elf-gcc"
13+
ar = "riscv32-unknown-elf-ar"
1214

1315
[rust]
1416
lld = true

0 commit comments

Comments
 (0)