Skip to content

Commit 8bbfc08

Browse files
authored
Add e, em, ec (#6)
* rust=1.77.2 * Add backends for e, ec, em * Refactor Justfile * test.sh: add backends * Debug image: install tools earlier
1 parent ffb1b4c commit 8bbfc08

10 files changed

+243
-30
lines changed

Containerfile

+8-6
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,17 @@ RUN apt install -y \
7272
# Clone the Rust compiler
7373
WORKDIR /opt/
7474
RUN \
75-
git clone --single-branch https://github.com/rust-lang/rust && \
76-
cd rust && \
77-
git checkout bf3c6c5bed498f41ad815641319a1ad9bcecb8e8
75+
git clone --branch 1.77.2 --depth 1 https://github.com/rust-lang/rust && \
76+
cd rust
7877

79-
# Apply patch & configure Rust for build
78+
# Apply patches & configure Rust for build
8079
WORKDIR /opt/rust/
81-
COPY 01_riscv32emc_target.patch .
82-
RUN git apply 01_riscv32emc_target.patch
8380
COPY config.toml .
81+
COPY patches .
82+
83+
RUN git config --global user.name "$(git --no-pager log --format=format:'%an' -n 1)" && \
84+
git config --global user.email "$(git --no-pager log --format=format:'%ae' -n 1)" && \
85+
git am --committer-date-is-author-date *.patch
8486

8587
# Build the Rust compiler
8688
RUN ./x build library

Justfile

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
ver := "0.2"
2+
13
build-debug:
2-
podman build -t rust-rv32e:0.2-debug -f Containerfile -f debug.Containerfile --target debug
4+
#!/usr/bin/env bash
5+
set -euo pipefail
6+
tag=rust-rv32e:{{ver}}-debug
7+
podman build -t ${tag} -f Containerfile -f debug.Containerfile --target debug
38

49
build-minimal:
5-
podman build -t rust-rv32e:0.2-minimal -f Containerfile --target minimal
10+
#!/usr/bin/env bash
11+
set -euo pipefail
12+
tag=rust-rv32e:{{ver}}-minimal
13+
podman build -t ${tag} -f Containerfile --target minimal
614

715
build-devel:
8-
podman build -t rust-rv32e:0.2-devel -f Containerfile --target devel
16+
#!/usr/bin/env bash
17+
set -euo pipefail
18+
tag=rust-rv32e:{{ver}}-devel
19+
podman build -t ${tag} -f Containerfile --target devel

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Rust for rv32emc-unknown-none-elf (Docker)
22

3-
A Docker container for a Rust compiler targeting rv32{e,i}mc-unknown-none-elf.
3+
A Docker container for a Rust compiler targeting rv32emc-unknown-none-elf.
44

55
## Requirements
66

config.toml

+12
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,25 @@ llvm-config = "/opt/llvm/bin/llvm-config"
88
[target.riscv32imc-unknown-none-elf]
99
llvm-config = "/opt/llvm/bin/llvm-config"
1010

11+
[target.riscv32e-unknown-none-elf]
12+
llvm-config = "/opt/llvm/bin/llvm-config"
13+
14+
[target.riscv32ec-unknown-none-elf]
15+
llvm-config = "/opt/llvm/bin/llvm-config"
16+
17+
[target.riscv32em-unknown-none-elf]
18+
llvm-config = "/opt/llvm/bin/llvm-config"
19+
1120
[target.riscv32emc-unknown-none-elf]
1221
llvm-config = "/opt/llvm/bin/llvm-config"
1322

1423
[build]
1524
target = [
1625
"x86_64-unknown-linux-gnu",
1726
"riscv32imc-unknown-none-elf",
27+
"riscv32e-unknown-none-elf",
28+
"riscv32ec-unknown-none-elf",
29+
"riscv32em-unknown-none-elf",
1830
"riscv32emc-unknown-none-elf",
1931
]
2032
# Building docs for no_std targets seems to fail here

debug.Containerfile

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
# This image is much larger than the release image, and is not intended for end-use
44
FROM builder AS debug
55

6+
# Add tools for end-user
7+
RUN apt install -y \
8+
binutils \
9+
git \
10+
tmux \
11+
vim \
12+
zsh
13+
614
WORKDIR /root/
715

816
# Add RISC-V to path
@@ -23,11 +31,3 @@ RUN \
2331
COPY scripts/test_riscv32emc_compile.sh .
2432
RUN chmod u+x test_riscv32emc_compile.sh && \
2533
./test_riscv32emc_compile.sh
26-
27-
# Add tools for end-user
28-
RUN apt install -y \
29-
binutils \
30-
git \
31-
tmux \
32-
vim \
33-
zsh

patches/0001-riscv32e.patch

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
From 2a0bd7325e66cf35d488ae51a6e3991b8a00d613 Mon Sep 17 00:00:00 2001
2+
From: Henri Lunnikivi <[email protected]>
3+
Date: Mon, 29 Apr 2024 13:01:10 +0300
4+
Subject: [PATCH 1/4] riscv32e
5+
6+
---
7+
compiler/rustc_target/src/spec/mod.rs | 2 ++
8+
.../spec/targets/riscv32e_unknown_none_elf.rs | 24 +++++++++++++++++++
9+
2 files changed, 26 insertions(+)
10+
create mode 100644 compiler/rustc_target/src/spec/targets/riscv32e_unknown_none_elf.rs
11+
12+
diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs
13+
index 6c698c5b..a7bb6d0c 100644
14+
--- a/compiler/rustc_target/src/spec/mod.rs
15+
+++ b/compiler/rustc_target/src/spec/mod.rs
16+
@@ -1614,6 +1614,8 @@ fn $module() {
17+
("riscv64gc-unknown-linux-gnu", riscv64gc_unknown_linux_gnu),
18+
("riscv64gc-unknown-linux-musl", riscv64gc_unknown_linux_musl),
19+
20+
+ ("riscv32e-unknown-none-elf", riscv32e_unknown_none_elf),
21+
+
22+
("sparc-unknown-none-elf", sparc_unknown_none_elf),
23+
24+
("loongarch64-unknown-none", loongarch64_unknown_none),
25+
diff --git a/compiler/rustc_target/src/spec/targets/riscv32e_unknown_none_elf.rs b/compiler/rustc_target/src/spec/targets/riscv32e_unknown_none_elf.rs
26+
new file mode 100644
27+
index 00000000..60134ff4
28+
--- /dev/null
29+
+++ b/compiler/rustc_target/src/spec/targets/riscv32e_unknown_none_elf.rs
30+
@@ -0,0 +1,24 @@
31+
+use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, TargetOptions};
32+
+
33+
+pub fn target() -> Target {
34+
+ Target {
35+
+ data_layout: "e-m:e-p:32:32-i64:64-n32-S128".into(),
36+
+ llvm_target: "riscv32".into(),
37+
+ pointer_width: 32,
38+
+ arch: "riscv32".into(),
39+
+
40+
+ options: TargetOptions {
41+
+ linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
42+
+ linker: Some("rust-lld".into()),
43+
+ cpu: "generic-rv32".into(),
44+
+ max_atomic_width: Some(32),
45+
+ atomic_cas: false,
46+
+ features: "+e,+forced-atomics".into(),
47+
+ panic_strategy: PanicStrategy::Abort,
48+
+ relocation_model: RelocModel::Static,
49+
+ emit_debug_gdb_scripts: false,
50+
+ eh_frame_header: false,
51+
+ ..Default::default()
52+
+ },
53+
+ }
54+
+}
55+
--
56+
2.37.3.windows.1
57+

patches/0002-riscv32ec.patch

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
From 819e15e797dfe15321cab63418e0bbab16156fb3 Mon Sep 17 00:00:00 2001
2+
From: Henri Lunnikivi <[email protected]>
3+
Date: Mon, 29 Apr 2024 13:01:26 +0300
4+
Subject: [PATCH 2/4] riscv32ec
5+
6+
---
7+
compiler/rustc_target/src/spec/mod.rs | 1 +
8+
.../targets/riscv32ec_unknown_none_elf.rs | 24 +++++++++++++++++++
9+
2 files changed, 25 insertions(+)
10+
create mode 100644 compiler/rustc_target/src/spec/targets/riscv32ec_unknown_none_elf.rs
11+
12+
diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs
13+
index a7bb6d0c..06771c11 100644
14+
--- a/compiler/rustc_target/src/spec/mod.rs
15+
+++ b/compiler/rustc_target/src/spec/mod.rs
16+
@@ -1615,6 +1615,7 @@ fn $module() {
17+
("riscv64gc-unknown-linux-musl", riscv64gc_unknown_linux_musl),
18+
19+
("riscv32e-unknown-none-elf", riscv32e_unknown_none_elf),
20+
+ ("riscv32ec-unknown-none-elf", riscv32ec_unknown_none_elf),
21+
22+
("sparc-unknown-none-elf", sparc_unknown_none_elf),
23+
24+
diff --git a/compiler/rustc_target/src/spec/targets/riscv32ec_unknown_none_elf.rs b/compiler/rustc_target/src/spec/targets/riscv32ec_unknown_none_elf.rs
25+
new file mode 100644
26+
index 00000000..19d29585
27+
--- /dev/null
28+
+++ b/compiler/rustc_target/src/spec/targets/riscv32ec_unknown_none_elf.rs
29+
@@ -0,0 +1,24 @@
30+
+use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, TargetOptions};
31+
+
32+
+pub fn target() -> Target {
33+
+ Target {
34+
+ data_layout: "e-m:e-p:32:32-i64:64-n32-S128".into(),
35+
+ llvm_target: "riscv32".into(),
36+
+ pointer_width: 32,
37+
+ arch: "riscv32".into(),
38+
+
39+
+ options: TargetOptions {
40+
+ linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
41+
+ linker: Some("rust-lld".into()),
42+
+ cpu: "generic-rv32".into(),
43+
+ max_atomic_width: Some(32),
44+
+ atomic_cas: false,
45+
+ features: "+e,+c,+forced-atomics".into(),
46+
+ panic_strategy: PanicStrategy::Abort,
47+
+ relocation_model: RelocModel::Static,
48+
+ emit_debug_gdb_scripts: false,
49+
+ eh_frame_header: false,
50+
+ ..Default::default()
51+
+ },
52+
+ }
53+
+}
54+
--
55+
2.37.3.windows.1
56+

patches/0003-riscv32em.patch

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
From 871677560f8925a5c4cf4643446ee14929b12538 Mon Sep 17 00:00:00 2001
2+
From: Henri Lunnikivi <[email protected]>
3+
Date: Mon, 29 Apr 2024 13:01:47 +0300
4+
Subject: [PATCH 3/4] riscv32em
5+
6+
---
7+
compiler/rustc_target/src/spec/mod.rs | 1 +
8+
.../targets/riscv32em_unknown_none_elf.rs | 24 +++++++++++++++++++
9+
2 files changed, 25 insertions(+)
10+
create mode 100644 compiler/rustc_target/src/spec/targets/riscv32em_unknown_none_elf.rs
11+
12+
diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs
13+
index 06771c11..f00525f2 100644
14+
--- a/compiler/rustc_target/src/spec/mod.rs
15+
+++ b/compiler/rustc_target/src/spec/mod.rs
16+
@@ -1616,6 +1616,7 @@ fn $module() {
17+
18+
("riscv32e-unknown-none-elf", riscv32e_unknown_none_elf),
19+
("riscv32ec-unknown-none-elf", riscv32ec_unknown_none_elf),
20+
+ ("riscv32em-unknown-none-elf", riscv32em_unknown_none_elf),
21+
22+
("sparc-unknown-none-elf", sparc_unknown_none_elf),
23+
24+
diff --git a/compiler/rustc_target/src/spec/targets/riscv32em_unknown_none_elf.rs b/compiler/rustc_target/src/spec/targets/riscv32em_unknown_none_elf.rs
25+
new file mode 100644
26+
index 00000000..b2ca27dd
27+
--- /dev/null
28+
+++ b/compiler/rustc_target/src/spec/targets/riscv32em_unknown_none_elf.rs
29+
@@ -0,0 +1,24 @@
30+
+use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, TargetOptions};
31+
+
32+
+pub fn target() -> Target {
33+
+ Target {
34+
+ data_layout: "e-m:e-p:32:32-i64:64-n32-S128".into(),
35+
+ llvm_target: "riscv32".into(),
36+
+ pointer_width: 32,
37+
+ arch: "riscv32".into(),
38+
+
39+
+ options: TargetOptions {
40+
+ linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
41+
+ linker: Some("rust-lld".into()),
42+
+ cpu: "generic-rv32".into(),
43+
+ max_atomic_width: Some(32),
44+
+ atomic_cas: false,
45+
+ features: "+e,+m,+forced-atomics".into(),
46+
+ panic_strategy: PanicStrategy::Abort,
47+
+ relocation_model: RelocModel::Static,
48+
+ emit_debug_gdb_scripts: false,
49+
+ eh_frame_header: false,
50+
+ ..Default::default()
51+
+ },
52+
+ }
53+
+}
54+
--
55+
2.37.3.windows.1
56+

01_riscv32emc_target.patch patches/0004-riscv32emc.patch

+24-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
1+
From f86a580effd97a8e66e35438f1e8637bb99a74de Mon Sep 17 00:00:00 2001
2+
From: Henri Lunnikivi <[email protected]>
3+
Date: Mon, 29 Apr 2024 13:01:55 +0300
4+
Subject: [PATCH 4/4] riscv32emc
5+
6+
---
7+
compiler/rustc_target/src/spec/mod.rs | 1 +
8+
.../targets/riscv32emc_unknown_none_elf.rs | 24 +++++++++++++++++++
9+
2 files changed, 25 insertions(+)
10+
create mode 100644 compiler/rustc_target/src/spec/targets/riscv32emc_unknown_none_elf.rs
11+
112
diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs
2-
index 6c698c5b01d..ca66bcc6873 100644
13+
index f00525f2..e4de621c 100644
314
--- a/compiler/rustc_target/src/spec/mod.rs
415
+++ b/compiler/rustc_target/src/spec/mod.rs
5-
@@ -1600,6 +1600,7 @@ fn $module() {
6-
("riscv32im-risc0-zkvm-elf", riscv32im_risc0_zkvm_elf),
7-
("riscv32im-unknown-none-elf", riscv32im_unknown_none_elf),
8-
("riscv32imc-unknown-none-elf", riscv32imc_unknown_none_elf),
16+
@@ -1617,6 +1617,7 @@ fn $module() {
17+
("riscv32e-unknown-none-elf", riscv32e_unknown_none_elf),
18+
("riscv32ec-unknown-none-elf", riscv32ec_unknown_none_elf),
19+
("riscv32em-unknown-none-elf", riscv32em_unknown_none_elf),
920
+ ("riscv32emc-unknown-none-elf", riscv32emc_unknown_none_elf),
10-
("riscv32imc-esp-espidf", riscv32imc_esp_espidf),
11-
("riscv32imac-esp-espidf", riscv32imac_esp_espidf),
12-
("riscv32imafc-esp-espidf", riscv32imafc_esp_espidf),
21+
22+
("sparc-unknown-none-elf", sparc_unknown_none_elf),
23+
1324
diff --git a/compiler/rustc_target/src/spec/targets/riscv32emc_unknown_none_elf.rs b/compiler/rustc_target/src/spec/targets/riscv32emc_unknown_none_elf.rs
1425
new file mode 100644
15-
index 00000000000..7ce0361a148
26+
index 00000000..b469a663
1627
--- /dev/null
1728
+++ b/compiler/rustc_target/src/spec/targets/riscv32emc_unknown_none_elf.rs
1829
@@ -0,0 +1,24 @@
@@ -31,7 +42,7 @@ index 00000000000..7ce0361a148
3142
+ cpu: "generic-rv32".into(),
3243
+ max_atomic_width: Some(32),
3344
+ atomic_cas: false,
34-
+ features: "+m,+c,+e,+forced-atomics".into(),
45+
+ features: "+e,+m,+c,+forced-atomics".into(),
3546
+ panic_strategy: PanicStrategy::Abort,
3647
+ relocation_model: RelocModel::Static,
3748
+ emit_debug_gdb_scripts: false,
@@ -40,3 +51,6 @@ index 00000000000..7ce0361a148
4051
+ },
4152
+ }
4253
+}
54+
--
55+
2.37.3.windows.1
56+

scripts/test_riscv32emc_compile.sh

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
#!/bin/bash
2+
set -euxo pipefail
23

3-
# Run compiler on container to test that it works
4+
# Run compilers on container to test that they work
45

56
git clone --depth=1 --branch=feat/rve https://github.com/hegza/riscv
67
cd riscv/riscv-rt
78

8-
RUSTFLAGS="-C linker=riscv32-unknown-elf-gcc -C link-arg=-nostartfiles -C link-arg=-Triscv-rt/examples/device.x" cargo build --target riscv32emc-unknown-none-elf --examples
9+
export RUSTFLAGS="-C linker=riscv32-unknown-elf-gcc -C link-arg=-nostartfiles -C link-arg=-Triscv-rt/examples/device.x"
10+
cargo build --target riscv32e-unknown-none-elf --examples
11+
cargo build --target riscv32em-unknown-none-elf --examples
12+
cargo build --target riscv32ec-unknown-none-elf --examples
13+
cargo build --target riscv32emc-unknown-none-elf --examples

0 commit comments

Comments
 (0)