Skip to content

Commit

Permalink
fix(bindings): remove optional cmake dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
camshaft committed Jan 9, 2024
1 parent d606b53 commit 57d586f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 77 deletions.
77 changes: 2 additions & 75 deletions bindings/rust/s2n-tls-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@ fn main() {
if external.is_enabled() {
external.link();
} else {
#[cfg(feature = "cmake")]
{
// branch on a runtime value so we don't get unused code warnings
if option_env("CARGO_FEATURE_CMAKE").is_some() {
build_cmake();
} else {
build_vendored();
}
}

#[cfg(not(feature = "cmake"))]
build_vendored();
}
}
Expand Down Expand Up @@ -93,26 +82,7 @@ fn build_vendored() {

let mut build = builder(&libcrypto);

// TODO: update rust bindings to handle no pq-crypto dir

let pq = option_env("CARGO_FEATURE_PQ").is_some();

// TODO each pq section needs to be built separately since it
// has its own relative include paths
assert!(!pq, "pq builds are not currently supported without cmake");

build.files(include!("./files.rs").iter().copied().filter(|file| {
// the pq entry file is still needed
if *file == "lib/pq-crypto/s2n_pq.c" {
return true;
}

if file.starts_with("lib/pq-crypto/") {
return pq;
}

true
}));
build.files(include!("./files.rs"));

if env("PROFILE") == "release" {
// fortify source is only available in release mode
Expand All @@ -127,7 +97,7 @@ fn build_vendored() {
}
}

if !pq {
if option_env("CARGO_FEATURE_PQ").is_none() {
build.define("S2N_NO_PQ", "1");
}

Expand Down Expand Up @@ -214,49 +184,6 @@ fn builder(libcrypto: &Libcrypto) -> cc::Build {
build
}

#[cfg(feature = "cmake")]
fn build_cmake() {
let mut config = cmake::Config::new("lib");

let libcrypto = Libcrypto::default();

config
.register_dep(&format!("aws_lc_{}", libcrypto.version))
.configure_arg("-DBUILD_TESTING=off");

if option_env("CARGO_FEATURE_PQ").is_none() {
config.configure_arg("-DS2N_NO_PQ=on");
}

let dst = config.build();

let lib = search(dst.join("lib64"))
.or_else(|| search(dst.join("lib")))
.or_else(|| search(dst.join("build").join("lib")))
.expect("could not build libs2n");

// link the built artifact
if lib.join("libs2n.a").exists() {
println!("cargo:rustc-link-lib=static=s2n");
} else {
println!("cargo:rustc-link-lib=s2n");
}

println!("cargo:include={}", dst.join("include").display());

// tell rust we're linking with libcrypto
println!("cargo:rustc-link-lib={}", libcrypto.link);

fn search(path: PathBuf) -> Option<PathBuf> {
if path.exists() {
println!("cargo:rustc-link-search={}", path.display());
Some(path)
} else {
None
}
}
}

#[derive(PartialEq, Eq, PartialOrd, Ord)]
struct Libcrypto {
version: String,
Expand Down
5 changes: 3 additions & 2 deletions bindings/rust/s2n-tls-sys/templates/Cargo.template
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ include = [

[features]
default = []
# preserve the cmake feature in case any consumers had it enabled before
cmake = []
quic = []
pq = ["cmake"] # the pq build logic is complicated so just use cmake instead
pq = []
internal = []
stacktrace = []
<TOKEN_REPLACED_WITH_UNSTABLE_FEATURES>
Expand All @@ -38,7 +40,6 @@ libc = "0.2"

[build-dependencies]
cc = { version = "1.0", features = ["parallel"] }
cmake = { version = "0.1", optional = true }

[dev-dependencies]
jobserver = "=0.1.26" # newer versions require rust 1.66, see https://github.com/aws/s2n-tls/issues/4241

0 comments on commit 57d586f

Please sign in to comment.