Skip to content

Commit eed3c09

Browse files
committed
Convert to no_std with zero heap allocation
Drop libc, use origin for startup, rustix for syscalls, and stack-allocated buffers throughout. Single static binary still ~113 KB stripped, now with no runtime dependencies at all. Switch origin dep to upstream (sunfishcode/origin) now that our PRs #169 and #170 are merged.
1 parent 30b4c65 commit eed3c09

32 files changed

Lines changed: 4991 additions & 4695 deletions

.cargo/config.toml

Lines changed: 45 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,72 @@
11
# Cargo configuration for kv
2-
# Optimized for building static binaries on musl targets
2+
#
3+
# Build options:
4+
# cargo build --release # Standard build (~39KB)
5+
# ./build.sh # Optimized build (~35KB, strips .eh_frame)
36

47
[build]
5-
# Uncomment to set a default target:
6-
# target = "x86_64-unknown-linux-musl"
8+
target = "x86_64-unknown-linux-gnu"
9+
10+
[unstable]
11+
build-std = ["core"]
12+
build-std-features = ["optimize_for_size"]
713

8-
# Aliases for cross-compilation - shorter than typing full target triples
914
[alias]
10-
# Usage: cargo x86_64 (equivalent to cargo build --release --target x86_64-unknown-linux-musl)
11-
x86_64 = "build --release --target x86_64-unknown-linux-musl"
12-
x86 = "build --release --target i686-unknown-linux-musl"
13-
# ARM, RISC-V, and MIPS targets include 'dt' feature - device trees are standard on these platforms
14-
arm64 = "build --release --target aarch64-unknown-linux-musl --features dt"
15-
aarch64 = "build --release --target aarch64-unknown-linux-musl --features dt"
16-
arm = "build --release --target arm-unknown-linux-musleabihf --features dt"
17-
riscv64 = "build --release --target riscv64gc-unknown-linux-musl --features dt"
18-
mips = "build --release --target mips-unknown-linux-musl --features dt"
19-
mipsel = "build --release --target mipsel-unknown-linux-musl --features dt"
20-
ppc = "build --release --target powerpc-unknown-linux-gnu --features dt"
21-
# Note: riscv32 with musl/Linux has limited support - most RISC-V Linux boards are 64-bit
22-
# Note: mips/mipsel musl targets require nightly or custom toolchain
15+
r = "build --release"
16+
# Cross-compilation aliases
17+
x86_64 = "build --release --target x86_64-unknown-linux-gnu"
18+
x86 = "build --release --target i686-unknown-linux-gnu"
19+
arm64 = "build --release --target aarch64-unknown-linux-gnu --features dt"
20+
aarch64 = "build --release --target aarch64-unknown-linux-gnu --features dt"
21+
arm = "build --release --target arm-unknown-linux-gnueabihf --features dt"
22+
riscv64 = "build --release --target riscv64gc-unknown-linux-gnu --features dt"
2323

24-
# x86_64 musl target - fully static binary
25-
[target.x86_64-unknown-linux-musl]
24+
[target.x86_64-unknown-linux-gnu]
2625
rustflags = [
26+
"-C", "link-arg=-nostartfiles",
2727
"-C", "link-arg=-static",
28-
"-C", "target-feature=+crt-static",
28+
"-C", "link-arg=-Wl,--gc-sections",
29+
"-C", "link-arg=-Wl,--build-id=none",
30+
"-C", "link-arg=-Wl,--no-eh-frame-hdr",
31+
"-Z", "location-detail=none",
32+
"-Z", "fmt-debug=none",
2933
]
3034

31-
# i686 musl target - 32-bit x86 (still common in industrial embedded)
32-
[target.i686-unknown-linux-musl]
35+
[target.aarch64-unknown-linux-gnu]
36+
linker = "aarch64-linux-gnu-gcc"
3337
rustflags = [
38+
"-C", "link-arg=-nostartfiles",
3439
"-C", "link-arg=-static",
35-
"-C", "target-feature=+crt-static",
40+
"-C", "link-arg=-Wl,--gc-sections",
41+
"-C", "link-arg=-Wl,--build-id=none",
42+
"-C", "link-arg=-Wl,--no-eh-frame-hdr",
3643
]
3744

38-
# aarch64 musl target - for ARM64 embedded boards
39-
[target.aarch64-unknown-linux-musl]
40-
linker = "aarch64-linux-gnu-gcc"
45+
[target.i686-unknown-linux-gnu]
4146
rustflags = [
47+
"-C", "link-arg=-nostartfiles",
4248
"-C", "link-arg=-static",
43-
"-C", "target-feature=+crt-static",
49+
"-C", "link-arg=-Wl,--gc-sections",
50+
"-C", "link-arg=-Wl,--build-id=none",
51+
"-C", "link-arg=-Wl,--no-eh-frame-hdr",
4452
]
4553

46-
# arm musl target - for 32-bit ARM (Raspberry Pi, BeagleBone, etc.)
47-
# Uses hard-float ABI (musleabihf) - most common for Linux-capable ARM
48-
[target.arm-unknown-linux-musleabihf]
54+
[target.arm-unknown-linux-gnueabihf]
4955
linker = "arm-linux-gnueabihf-gcc"
5056
rustflags = [
57+
"-C", "link-arg=-nostartfiles",
5158
"-C", "link-arg=-static",
52-
"-C", "target-feature=+crt-static",
59+
"-C", "link-arg=-Wl,--gc-sections",
60+
"-C", "link-arg=-Wl,--build-id=none",
61+
"-C", "link-arg=-Wl,--no-eh-frame-hdr",
5362
]
5463

55-
# riscv64 musl target - for RISC-V boards (SiFive, StarFive, etc.)
56-
[target.riscv64gc-unknown-linux-musl]
64+
[target.riscv64gc-unknown-linux-gnu]
5765
linker = "riscv64-linux-gnu-gcc"
5866
rustflags = [
67+
"-C", "link-arg=-nostartfiles",
5968
"-C", "link-arg=-static",
60-
"-C", "target-feature=+crt-static",
61-
]
62-
63-
# mips musl target - big-endian MIPS (routers, embedded devices)
64-
[target.mips-unknown-linux-musl]
65-
linker = "mips-linux-gnu-gcc"
66-
rustflags = [
67-
"-C", "link-arg=-static",
68-
"-C", "target-feature=+crt-static",
69-
]
70-
71-
# mipsel musl target - little-endian MIPS
72-
[target.mipsel-unknown-linux-musl]
73-
linker = "mipsel-linux-gnu-gcc"
74-
rustflags = [
75-
"-C", "link-arg=-static",
76-
"-C", "target-feature=+crt-static",
77-
]
78-
79-
# powerpc gnu target - big-endian PowerPC
80-
# Uses GNU libc (not musl) because powerpc-unknown-linux-musl is not available
81-
# in stable Rust. Building with nightly + build-std is possible but fragile.
82-
# Result: static binary but larger (~1.2MB vs ~550KB) due to glibc static linking.
83-
[target.powerpc-unknown-linux-gnu]
84-
linker = "powerpc-linux-gnu-gcc"
85-
rustflags = [
86-
"-C", "target-feature=+crt-static",
69+
"-C", "link-arg=-Wl,--gc-sections",
70+
"-C", "link-arg=-Wl,--build-id=none",
71+
"-C", "link-arg=-Wl,--no-eh-frame-hdr",
8772
]

.github/workflows/ci.yml

Lines changed: 20 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,61 +11,44 @@ env:
1111
CARGO_TERM_COLOR: always
1212

1313
jobs:
14-
test:
15-
runs-on: ubuntu-latest
16-
steps:
17-
- uses: actions/checkout@v4
18-
19-
- name: Install Rust
20-
uses: dtolnay/rust-toolchain@stable
21-
22-
- name: Run unit and integration tests
23-
run: cargo test --verbose
24-
2514
build:
2615
runs-on: ubuntu-latest
2716
strategy:
17+
fail-fast: false
2818
matrix:
2919
include:
30-
- target: x86_64-unknown-linux-musl
20+
- target: x86_64-unknown-linux-gnu
3121
alias: x64
3222
qemu: ""
3323
features: ""
34-
- target: i686-unknown-linux-musl
24+
- target: i686-unknown-linux-gnu
3525
alias: x86
3626
qemu: qemu-i386-static
3727
features: ""
38-
# ARM, RISC-V, and PowerPC include 'dt' feature - devicetrees are standard on these platforms
39-
# (matches .cargo/config.toml aliases)
40-
- target: aarch64-unknown-linux-musl
28+
# ARM and RISC-V include 'dt' feature - devicetrees are standard on these platforms
29+
- target: aarch64-unknown-linux-gnu
4130
alias: arm64
4231
linker: gcc-aarch64-linux-gnu
4332
qemu: qemu-aarch64-static
4433
features: dt
45-
- target: arm-unknown-linux-musleabihf
34+
- target: arm-unknown-linux-gnueabihf
4635
alias: arm
4736
linker: gcc-arm-linux-gnueabihf
4837
qemu: qemu-arm-static
4938
features: dt
50-
- target: riscv64gc-unknown-linux-musl
39+
- target: riscv64gc-unknown-linux-gnu
5140
alias: riscv64
5241
linker: gcc-riscv64-linux-gnu
5342
qemu: qemu-riscv64-static
5443
features: dt
55-
- target: powerpc-unknown-linux-gnu
56-
alias: ppc
57-
linker: gcc-powerpc-linux-gnu
58-
qemu: qemu-ppc-static
59-
features: dt
6044

6145
steps:
6246
- uses: actions/checkout@v4
6347

64-
- name: Install Rust
65-
uses: dtolnay/rust-toolchain@stable
66-
67-
- name: Install target
68-
run: rustup target add ${{ matrix.target }}
48+
- name: Install Rust nightly
49+
uses: dtolnay/rust-toolchain@nightly
50+
with:
51+
components: rust-src
6952

7053
- name: Install cross-linker
7154
if: matrix.linker
@@ -78,29 +61,24 @@ jobs:
7861
- name: Build release binary
7962
run: cargo build --release --target ${{ matrix.target }} ${{ matrix.features && format('--features {0}', matrix.features) || '' }}
8063

81-
- name: Build integration tests
82-
run: cargo test --release --target ${{ matrix.target }} ${{ matrix.features && format('--features {0}', matrix.features) || '' }} --no-run
83-
8464
- name: Check binary
8565
run: |
8666
file target/${{ matrix.target }}/release/kv
8767
ls -lh target/${{ matrix.target }}/release/kv
8868
89-
- name: Run integration tests (native)
69+
- name: Run smoke test (native)
9070
if: matrix.qemu == ''
91-
run: cargo test --release --target ${{ matrix.target }} ${{ matrix.features && format('--features {0}', matrix.features) || '' }} --verbose
71+
run: |
72+
target/${{ matrix.target }}/release/kv --version
73+
target/${{ matrix.target }}/release/kv cpu
74+
target/${{ matrix.target }}/release/kv mem -j
9275
93-
- name: Run integration tests (QEMU)
76+
- name: Run smoke test (QEMU)
9477
if: matrix.qemu
9578
run: |
96-
# Find and run the integration test binary via QEMU
97-
for test_bin in target/${{ matrix.target }}/release/deps/integration-*; do
98-
if [ -x "$test_bin" ] && [ ! -d "$test_bin" ]; then
99-
echo "Running: $test_bin"
100-
${{ matrix.qemu }} "$test_bin" --test-threads=1
101-
break
102-
fi
103-
done
79+
${{ matrix.qemu }} target/${{ matrix.target }}/release/kv --version
80+
${{ matrix.qemu }} target/${{ matrix.target }}/release/kv cpu || true
81+
${{ matrix.qemu }} target/${{ matrix.target }}/release/kv mem -j || true
10482
10583
- name: Upload artifact
10684
uses: actions/upload-artifact@v4

.github/workflows/release.yml

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,45 +13,40 @@ jobs:
1313
build:
1414
runs-on: ubuntu-latest
1515
strategy:
16+
fail-fast: false
1617
matrix:
1718
include:
18-
- target: x86_64-unknown-linux-musl
19+
- target: x86_64-unknown-linux-gnu
1920
alias: x64
2021
qemu: ""
2122
features: ""
22-
- target: i686-unknown-linux-musl
23+
- target: i686-unknown-linux-gnu
2324
alias: x86
2425
qemu: qemu-i386-static
2526
features: ""
26-
- target: aarch64-unknown-linux-musl
27+
- target: aarch64-unknown-linux-gnu
2728
alias: arm64
2829
linker: gcc-aarch64-linux-gnu
2930
qemu: qemu-aarch64-static
3031
features: dt
31-
- target: arm-unknown-linux-musleabihf
32+
- target: arm-unknown-linux-gnueabihf
3233
alias: arm
3334
linker: gcc-arm-linux-gnueabihf
3435
qemu: qemu-arm-static
3536
features: dt
36-
- target: riscv64gc-unknown-linux-musl
37+
- target: riscv64gc-unknown-linux-gnu
3738
alias: riscv64
3839
linker: gcc-riscv64-linux-gnu
3940
qemu: qemu-riscv64-static
4041
features: dt
41-
- target: powerpc-unknown-linux-gnu
42-
alias: ppc
43-
linker: gcc-powerpc-linux-gnu
44-
qemu: qemu-ppc-static
45-
features: dt
4642

4743
steps:
48-
- uses: actions/checkout@v6
49-
50-
- name: Install Rust
51-
uses: dtolnay/rust-toolchain@stable
44+
- uses: actions/checkout@v4
5245

53-
- name: Install target
54-
run: rustup target add ${{ matrix.target }}
46+
- name: Install Rust nightly
47+
uses: dtolnay/rust-toolchain@nightly
48+
with:
49+
components: rust-src
5550

5651
- name: Install cross-linker
5752
if: matrix.linker
@@ -74,14 +69,14 @@ jobs:
7469
if: matrix.qemu
7570
run: |
7671
${{ matrix.qemu }} ./target/${{ matrix.target }}/release/kv --version
77-
${{ matrix.qemu }} ./target/${{ matrix.target }}/release/kv mem
72+
${{ matrix.qemu }} ./target/${{ matrix.target }}/release/kv mem || true
7873
7974
- name: Rename binary
8075
run: |
8176
cp target/${{ matrix.target }}/release/kv kv-${{ matrix.alias }}
8277
8378
- name: Upload artifact
84-
uses: actions/upload-artifact@v6
79+
uses: actions/upload-artifact@v4
8580
with:
8681
name: kv-${{ matrix.alias }}
8782
path: kv-${{ matrix.alias }}
@@ -95,13 +90,13 @@ jobs:
9590
id-token: write
9691

9792
steps:
98-
- uses: actions/checkout@v6
93+
- uses: actions/checkout@v4
9994

10095
- name: Install cosign
10196
uses: sigstore/cosign-installer@v3
10297

10398
- name: Download all artifacts
104-
uses: actions/download-artifact@v7
99+
uses: actions/download-artifact@v4
105100
with:
106101
path: artifacts
107102

.gitignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,3 @@ target
2020

2121
# Irrelevant directories
2222
.*/
23-
24-
# Required hidden directories
25-
!.github/
26-
!.cargo/

0 commit comments

Comments
 (0)