|
1 | 1 | # 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) |
3 | 6 |
|
4 | 7 | [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"] |
7 | 13 |
|
8 | | -# Aliases for cross-compilation - shorter than typing full target triples |
9 | 14 | [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" |
23 | 23 |
|
24 | | -# x86_64 musl target - fully static binary |
25 | | -[target.x86_64-unknown-linux-musl] |
| 24 | +[target.x86_64-unknown-linux-gnu] |
26 | 25 | rustflags = [ |
| 26 | + "-C", "link-arg=-nostartfiles", |
27 | 27 | "-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", |
29 | 33 | ] |
30 | 34 |
|
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" |
33 | 37 | rustflags = [ |
| 38 | + "-C", "link-arg=-nostartfiles", |
34 | 39 | "-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", |
36 | 43 | ] |
37 | 44 |
|
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] |
41 | 46 | rustflags = [ |
| 47 | + "-C", "link-arg=-nostartfiles", |
42 | 48 | "-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", |
44 | 52 | ] |
45 | 53 |
|
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] |
49 | 55 | linker = "arm-linux-gnueabihf-gcc" |
50 | 56 | rustflags = [ |
| 57 | + "-C", "link-arg=-nostartfiles", |
51 | 58 | "-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", |
53 | 62 | ] |
54 | 63 |
|
55 | | -# riscv64 musl target - for RISC-V boards (SiFive, StarFive, etc.) |
56 | | -[target.riscv64gc-unknown-linux-musl] |
| 64 | +[target.riscv64gc-unknown-linux-gnu] |
57 | 65 | linker = "riscv64-linux-gnu-gcc" |
58 | 66 | rustflags = [ |
| 67 | + "-C", "link-arg=-nostartfiles", |
59 | 68 | "-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", |
87 | 72 | ] |
0 commit comments