Skip to content

Commit d947c94

Browse files
authored
fix: Statically link fuzzing builds (#2548)
* ci: Don't use `quickinstall` for `cargo-fuzz` See rust-fuzz/cargo-fuzz#398 * Space * Optimize * CARGO_PROFILE_RELEASE_LTO=false * static * More * Again * Again * Again * Again * Again * Again * Again * Again * Again * Again * Again * Finalize
1 parent 9fe44f3 commit d947c94

File tree

3 files changed

+39
-43
lines changed

3 files changed

+39
-43
lines changed

.github/workflows/check.yml

+7
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,17 @@ jobs:
4848
os: [ubuntu-24.04, ubuntu-24.04-arm, macos-14, windows-2025]
4949
rust-toolchain: ${{ fromJSON(needs.toolchains.outputs.toolchains) }}
5050
type: [debug]
51+
# Include some dynamically-linked release builds, to check that that works on all platforms.
5152
include:
5253
- os: ubuntu-24.04
5354
rust-toolchain: stable
5455
type: release
56+
- os: macos-14
57+
rust-toolchain: stable
58+
type: release
59+
- os: windows-2025
60+
rust-toolchain: stable
61+
type: release
5562
env:
5663
BUILD_TYPE: ${{ matrix.type == 'release' && '--release' || '' }}
5764
runs-on: ${{ matrix.os }}

.github/workflows/fuzz-bench.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@ jobs:
4444
env:
4545
UBUNTU: ${{ startsWith(matrix.os, 'ubuntu') }}
4646
run: |
47-
# FIXME: https://github.com/rust-fuzz/cargo-fuzz/issues/404
48-
[ "$UBUNTU" = "true" ] && FUZZ_FLAGS="-s none"
49-
# shellcheck disable=SC2086
50-
cargo fuzz build $FUZZ_FLAGS
47+
# FIXME: https://github.com/rust-fuzz/cargo-fuzz/issues/384 for why no LTO.
48+
CARGO_PROFILE_RELEASE_LTO=false cargo fuzz build
5149
5250
- if: ${{ matrix.check == 'bench' }}
5351
run: cargo bench --features bench --no-run

neqo-crypto/build.rs

+30-39
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,6 @@ struct Bindings {
5656
cplusplus: bool,
5757
}
5858

59-
fn is_debug() -> bool {
60-
// Check the build profile and not whether debug symbols are enabled (i.e.,
61-
// `env::var("DEBUG")`), because we enable those for benchmarking/profiling and still want
62-
// to build NSS in release mode.
63-
env::var("PROFILE").unwrap_or_default() == "debug"
64-
}
65-
6659
// bindgen needs access to libclang.
6760
// On windows, this doesn't just work, you have to set LIBCLANG_PATH.
6861
// Rather than download the 400Mb+ files, like gecko does, let's just reuse their work.
@@ -138,31 +131,34 @@ fn build_nss(dir: PathBuf, nsstarget: &str) {
138131
}
139132

140133
fn dynamic_link() {
141-
let libs = if env::consts::OS == "windows" {
142-
&["nssutil3.dll", "nss3.dll", "ssl3.dll"]
134+
let dynamic_libs = if env::consts::OS == "windows" {
135+
[
136+
"nssutil3.dll",
137+
"nss3.dll",
138+
"ssl3.dll",
139+
"libplds4.dll",
140+
"libplc4.dll",
141+
"libnspr4.dll",
142+
]
143143
} else {
144-
&["nssutil3", "nss3", "ssl3"]
144+
["nssutil3", "nss3", "ssl3", "plds4", "plc4", "nspr4"]
145145
};
146-
dynamic_link_both(libs);
147-
}
148-
149-
fn dynamic_link_both(extra_libs: &[&str]) {
150-
let nspr_libs = if env::consts::OS == "windows" {
151-
&["libplds4", "libplc4", "libnspr4"]
152-
} else {
153-
&["plds4", "plc4", "nspr4"]
154-
};
155-
for lib in nspr_libs.iter().chain(extra_libs) {
146+
for lib in dynamic_libs {
156147
println!("cargo:rustc-link-lib=dylib={lib}");
157148
}
158149
}
159150

160151
fn static_link() {
161-
let mut static_libs = vec![
152+
let static_libs = [
162153
"certdb",
163154
"certhi",
164155
"cryptohi",
165156
"freebl",
157+
if env::consts::OS == "windows" {
158+
"libnspr4"
159+
} else {
160+
"nspr4"
161+
},
166162
"nss_static",
167163
"nssb",
168164
"nssdev",
@@ -171,30 +167,23 @@ fn static_link() {
171167
"pk11wrap",
172168
"pkcs12",
173169
"pkcs7",
170+
if env::consts::OS == "windows" {
171+
"libplc4"
172+
} else {
173+
"plc4"
174+
},
175+
if env::consts::OS == "windows" {
176+
"libplds4"
177+
} else {
178+
"plds4"
179+
},
174180
"smime",
175181
"softokn_static",
176182
"ssl",
177183
];
178-
if env::consts::OS != "macos" {
179-
static_libs.push("sqlite");
180-
}
181184
for lib in static_libs {
182185
println!("cargo:rustc-link-lib=static={lib}");
183186
}
184-
185-
// Dynamic libs that aren't transitively included by NSS libs.
186-
let mut other_libs = Vec::new();
187-
if env::consts::OS != "windows" {
188-
if env::var("CARGO_CFG_TARGET_OS").unwrap_or_default() != "android" {
189-
// On Android, pthread is part of libc.
190-
other_libs.push("pthread");
191-
}
192-
other_libs.extend_from_slice(&["dl", "c", "z"]);
193-
}
194-
if env::consts::OS == "macos" {
195-
other_libs.push("sqlite3");
196-
}
197-
dynamic_link_both(&other_libs);
198187
}
199188

200189
fn get_includes(nsstarget: &Path, nssdist: &Path) -> Vec<PathBuf> {
@@ -342,7 +331,9 @@ fn setup_standalone(nss: &str) -> Vec<String> {
342331
"cargo:rustc-link-search=native={}",
343332
nsslibdir.to_str().unwrap()
344333
);
345-
if is_debug() || env::consts::OS == "windows" {
334+
#[expect(unexpected_cfgs, reason = "cargo-fuzz defines fuzzing")]
335+
// FIXME: NSPR doesn't build proper dynamic libraries on Windows.
336+
if cfg!(any(debug_assertions, fuzzing)) || env::consts::OS == "windows" {
346337
static_link();
347338
} else {
348339
dynamic_link();

0 commit comments

Comments
 (0)