-
Notifications
You must be signed in to change notification settings - Fork 997
Upgrade boring to 5.1 #2446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Upgrade boring to 5.1 #2446
Changes from 7 commits
a5379d4
3b12677
f2e65a2
11b319e
abb1d3d
ad2389b
78e6a2c
eff1f9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
cjpatton marked this conversation as resolved.
|
|
cjpatton marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,83 @@ Cflags: -I${{includedir}} | |
| out_file.write_all(output.as_bytes()).unwrap(); | ||
| } | ||
|
|
||
| /// Returns true if cargo resolved `boring` to a 4.x version. | ||
| /// | ||
| /// Walks up from `OUT_DIR` looking for a `Cargo.lock`, then scans it | ||
| /// for the `boring` package. We use `Cargo.lock` rather than shelling | ||
| /// out to `cargo metadata` because (a) the lockfile is guaranteed to | ||
| /// exist at this point in the build, (b) parsing it is cheap and has | ||
| /// no extra dependencies, and (c) it avoids re-entering cargo from a | ||
| /// build script. | ||
| fn detect_boring_v4() -> bool { | ||
|
ghedo marked this conversation as resolved.
Outdated
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another idea 😅 Could we check and since I don't think we'll ever update BoringSSL in v4 again Would require adding
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about differences in the |
||
| let Some(lockfile) = find_cargo_lock() else { | ||
| // No lockfile (shouldn't happen in normal cargo builds, but | ||
| // be conservative). Assume 5.x — the default and forward- | ||
| // looking version. Downstream can fix this by generating a | ||
| // lockfile (`cargo generate-lockfile`). | ||
| println!( | ||
| "cargo:warning=quiche: Cargo.lock not found; assuming boring 5.x" | ||
| ); | ||
| return false; | ||
| }; | ||
|
|
||
| println!("cargo:rerun-if-changed={}", lockfile.display()); | ||
|
|
||
| let contents = match std::fs::read_to_string(&lockfile) { | ||
| Ok(s) => s, | ||
| Err(e) => { | ||
| println!( | ||
| "cargo:warning=quiche: failed to read {}: {e}; assuming boring 5.x", | ||
| lockfile.display(), | ||
| ); | ||
| return false; | ||
| }, | ||
| }; | ||
|
|
||
| // The lockfile is TOML but a regex-light scan is enough: find a | ||
| // `[[package]]` whose `name = "boring"` (not "boring-sys") and | ||
| // read its `version`. | ||
| let mut in_boring = false; | ||
| for line in contents.lines() { | ||
| let line = line.trim(); | ||
| if line == "[[package]]" { | ||
| in_boring = false; | ||
| continue; | ||
| } | ||
| if line == "name = \"boring\"" { | ||
| in_boring = true; | ||
| continue; | ||
| } | ||
| if in_boring { | ||
| if let Some(rest) = line.strip_prefix("version = \"") { | ||
| let version = rest.trim_end_matches('"'); | ||
| let major = version.split('.').next().unwrap_or(""); | ||
| return major == "4"; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // `boring` not present in the lockfile (e.g. | ||
| // `boringssl-boring-crate` is off). Doesn't matter what we return | ||
| // since the `cfg` won't be observed. | ||
| false | ||
| } | ||
|
|
||
| fn find_cargo_lock() -> Option<std::path::PathBuf> { | ||
| // Start from `CARGO_MANIFEST_DIR` and walk up. Cargo guarantees | ||
| // the lockfile lives at the workspace root, which is an ancestor | ||
| // of the manifest dir. | ||
| let manifest_dir = | ||
| std::path::PathBuf::from(std::env::var_os("CARGO_MANIFEST_DIR")?); | ||
| for dir in manifest_dir.ancestors() { | ||
| let candidate = dir.join("Cargo.lock"); | ||
| if candidate.is_file() { | ||
| return Some(candidate); | ||
| } | ||
| } | ||
| None | ||
| } | ||
|
|
||
| fn target_dir_path() -> std::path::PathBuf { | ||
| let out_dir = std::env::var("OUT_DIR").unwrap(); | ||
| let out_dir = std::path::Path::new(&out_dir); | ||
|
|
@@ -44,7 +121,18 @@ fn target_dir_path() -> std::path::PathBuf { | |
| } | ||
|
|
||
| fn main() { | ||
| // Emit `cfg(boring_v4)` if boring version 4.x is detected. This is used to | ||
| // pick which APIs to expect and to guide test expectations. (Larger post | ||
| // quantum key shares are enabled by default in boring 5.x but not boring | ||
| // 4.x.) | ||
| // | ||
| // The cfg is always registered (even when the backend feature is | ||
| // off) so rustc doesn't warn about unknown cfg names. | ||
| println!("cargo::rustc-check-cfg=cfg(boring_v4)"); | ||
| if cfg!(feature = "boringssl-boring-crate") { | ||
| if detect_boring_v4() { | ||
|
cjpatton marked this conversation as resolved.
Outdated
|
||
| println!("cargo:rustc-cfg=boring_v4"); | ||
| } | ||
| println!("cargo:rustc-link-lib=static=ssl"); | ||
| println!("cargo:rustc-link-lib=static=crypto"); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.