Skip to content

Commit 76ad3d7

Browse files
committed
better build profiles
Signed-off-by: Sylvain Hellegouarch <[email protected]>
1 parent 6bfe101 commit 76ad3d7

File tree

4 files changed

+86
-10
lines changed

4 files changed

+86
-10
lines changed

.cargo/config.toml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[build]
2+
# No global rustflags here; target-specific below.
3+
# If you always target a specific platform for the server, set:
4+
# target = "x86_64-unknown-linux-gnu"
5+
6+
# -------- Server target (GNU Linux example) --------
7+
[target.x86_64-unknown-linux-gnu]
8+
rustflags = [
9+
"-C", "target-cpu=native", # use host CPU features for the server
10+
"-C", "symbol-mangling-version=v0",
11+
"-C", "link-arg=-Wl,--gc-sections",
12+
]
13+
14+
# macOS (if you build/run locally)
15+
[target.aarch64-apple-darwin]
16+
rustflags = [
17+
"-C", "target-cpu=native",
18+
"-C", "symbol-mangling-version=v0",
19+
"-C", "link-arg=-Wl,-dead_strip",
20+
]
21+
22+
# -------- eBPF target (Aya / bpfel-unknown-none as an example) --------
23+
# Adjust this triple to your actual BPF target (bpfel-unknown-none or bpfeb)
24+
[target.bpfel-unknown-none]
25+
rustflags = [
26+
# keep minimal & portable; let profiles set panic=abort
27+
"-C", "link-arg=-z", # placeholder; typically no special link args here
28+
# (avoid target-cpu=native, avoid exotic link flags)
29+
]
30+
31+
# -------- Optional MUSL for small static server builds --------
32+
# [target.x86_64-unknown-linux-musl]
33+
# linker = "musl-gcc"
34+
# rustflags = [
35+
# "-C", "target-cpu=x86-64-v3",
36+
# "-C", "embed-bitcode=no",
37+
# "-C", "symbol-mangling-version=v0",
38+
# "-C", "link-arg=-Wl,--gc-sections",
39+
# ]

.github/workflows/release.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,17 @@ jobs:
185185

186186
- name: Build Linux/MacOSX (shared)
187187
if: matrix.os != 'windows-latest' && matrix.target != 'x86_64-unknown-linux-musl' && matrix.target != 'aarch64-unknown-linux-musl'
188-
run: cargo +nightly build --release --features agent --target ${{ matrix.target }}
188+
run: cargo +nightly build --profile prod-fast --features agent --target ${{ matrix.target }}
189189
working-directory: ./fault-cli
190190

191191
- name: Build Windows (shared)
192192
if: matrix.os == 'windows-latest'
193-
run: cargo +nightly build --release --target ${{ matrix.target }}
193+
run: cargo +nightly build --profile prod-fast --target ${{ matrix.target }}
194194
working-directory: ./fault-cli
195195

196196
- name: Build (static)
197197
if: matrix.target == 'x86_64-unknown-linux-musl' || matrix.target == 'aarch64-unknown-linux-musl'
198-
run: cargo +nightly zigbuild --release --target ${{ matrix.target }}
198+
run: cargo +nightly zigbuild --profile prod-small --target ${{ matrix.target }}
199199
working-directory: ./fault-cli
200200

201201
- name: Upload binaries to release
@@ -320,7 +320,7 @@ jobs:
320320
if: matrix.target != 'x86_64-unknown-linux-musl' && matrix.target != 'aarch64-unknown-linux-musl'
321321
run: |
322322
cargo install bpf-linker --git https://github.com/aya-rs/bpf-linker.git
323-
cargo +nightly build --release --features stealth --target ${{ matrix.target }}
323+
cargo +nightly build --profile prod-fast --features stealth --target ${{ matrix.target }}
324324
cargo +nightly build \
325325
--release \
326326
-p fault-ebpf-programs \
@@ -332,7 +332,7 @@ jobs:
332332
if: matrix.target == 'x86_64-unknown-linux-musl' || matrix.target == 'aarch64-unknown-linux-musl'
333333
run: |
334334
cargo install bpf-linker --git https://github.com/aya-rs/bpf-linker.git
335-
cargo +nightly zigbuild --release --features stealth --target ${{ matrix.target }}
335+
cargo +nightly zigbuild --profile prod-fast --features stealth --target ${{ matrix.target }}
336336
cargo +nightly build \
337337
--release \
338338
-p fault-ebpf-programs \

Cargo.toml

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,49 @@ include = [
2424
which = { version = "8.0.0", default-features = false, features = ["real-sys"] }
2525
anyhow = { version = "1", default-features = false }
2626

27+
[profile.dev]
28+
opt-level = 0
29+
debug = 2
30+
debug-assertions = true
31+
overflow-checks = true
32+
incremental = true
33+
2734
[profile.release]
28-
lto = true
35+
opt-level = 3
36+
lto = "thin" # profile-level (allowed)
37+
codegen-units = 1
38+
panic = "abort" # profile-level (allowed)
39+
incremental = false
40+
debug-assertions = false
41+
overflow-checks = false
42+
strip = "debuginfo" # profile-level (allowed)
43+
44+
# ---------- Server-focused profiles you select explicitly ----------
45+
[profile.prod-fast]
46+
inherits = "release"
47+
lto = "fat"
48+
opt-level = 3
49+
strip = "debuginfo"
50+
51+
[profile.prod-small]
52+
inherits = "release"
53+
lto = "thin"
54+
opt-level = "z"
55+
strip = "symbols"
56+
57+
# ---------- Per-package overrides (ONLY allowed keys) ----------
58+
59+
# (Optional) tweak the server crate a bit; do NOT set lto/strip/panic here
60+
[profile.release.package.fault-cli]
61+
opt-level = 3
2962
codegen-units = 1
30-
panic = "abort"
63+
# (leave out panic/lto/strip)
3164

65+
# eBPF crate: conservative tweaks; again, no panic/lto/strip here
3266
[profile.release.package.fault-ebpf-programs]
67+
opt-level = "z"
3368
codegen-units = 1
34-
debug = 2
69+
debug = 0
70+
debug-assertions = false
71+
overflow-checks = false
72+
# (leave out panic/lto/strip)

fault-cli/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ path = "src/main.rs"
158158
default = [
159159
"demo",
160160
"scenario",
161-
"injection",
162-
"agent"
161+
"injection"
163162
]
164163
demo = []
165164
scenario = [

0 commit comments

Comments
 (0)