Skip to content

Commit

Permalink
build(rust-bindings): use the 2021 rust edition (#3386)
Browse files Browse the repository at this point in the history
  • Loading branch information
camshaft authored Jul 6, 2022
1 parent dea5dba commit c8380d0
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 24 deletions.
2 changes: 1 addition & 1 deletion bindings/rust/generate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "generate"
version = "0.1.0"
authors = ["AWS s2n"]
edition = "2018"
edition = "2021"
license = "Apache-2.0"
# this is an internal tool for generating bindings
publish = false
Expand Down
2 changes: 1 addition & 1 deletion bindings/rust/integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "integration"
version = "0.1.0"
authors = ["AWS s2n"]
edition = "2018"
edition = "2021"
publish = false

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion bindings/rust/s2n-tls-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "s2n-tls-sys"
description = "A C99 implementation of the TLS/SSL protocols"
version = "0.0.8"
authors = ["AWS s2n"]
edition = "2018"
edition = "2021"
links = "s2n-tls"
repository = "https://github.com/aws/s2n-tls"
license = "Apache-2.0"
Expand Down
57 changes: 38 additions & 19 deletions bindings/rust/s2n-tls-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ fn build_vendored() {
build.define("S2N_CPUID_AVAILABLE", "1");
}

if features.supports("features") {
build.define("S2N_FEATURES_AVAILABLE", "1");
}

if features.supports("fallthrough") {
build.define("FALL_THROUGH_SUPPORTED", "1");
}
Expand All @@ -130,6 +134,18 @@ fn build_vendored() {
build.define("__RESTRICT__SUPPORTED", "1");
}

if features.supports("madvise") {
build.define("MADVISE_SUPPORTED", "1");
}

if features.supports("minherit") {
build.define("MINHERIT_SUPPORTED", "1");
}

if features.supports("clone") {
build.define("CLONE_SUPPORTED", "1");
}

// don't spit out a bunch of warnings to the end user, since they won't really be able
// to do anything with it
build.warnings(false);
Expand All @@ -150,6 +166,14 @@ fn build_vendored() {
fn build_cmake() {
let mut config = cmake::Config::new("lib");

// sometimes openssl-sys decides not to set this value so we may need to set it anyway
if option_env("DEP_OPENSSL_ROOT").is_none() {
let include = env("DEP_OPENSSL_INCLUDE");
if let Some(root) = Path::new(&include).parent() {
std::env::set_var("DEP_OPENSSL_ROOT", root);
}
}

config
.register_dep("openssl")
.configure_arg("-DBUILD_TESTING=off");
Expand All @@ -160,14 +184,23 @@ fn build_cmake() {

let dst = config.build();

// tell rust we're linking with libcrypto
let root = PathBuf::from(env("DEP_OPENSSL_ROOT"));
if root.join("libcrypto.so").exists() {
println!("cargo:rustc-link-lib=crypto");
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=static=crypto");
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=crypto");

fn search(path: PathBuf) -> Option<PathBuf> {
if path.exists() {
println!("cargo:rustc-link-search={}", path.display());
Expand All @@ -176,20 +209,6 @@ fn build_cmake() {
None
}
}

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.so").exists() {
println!("cargo:rustc-link-lib=s2n");
} else {
println!("cargo:rustc-link-lib=static=s2n");
}

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

struct External {
Expand Down
2 changes: 1 addition & 1 deletion bindings/rust/s2n-tls-tokio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "s2n-tls-tokio"
description = "An implementation of TLS streams for Tokio built on top of s2n-tls"
version = "0.0.8"
authors = ["AWS s2n"]
edition = "2018"
edition = "2021"
repository = "https://github.com/aws/s2n-tls"
license = "Apache-2.0"

Expand Down
2 changes: 1 addition & 1 deletion bindings/rust/s2n-tls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "s2n-tls"
description = "A C99 implementation of the TLS/SSL protocols"
version = "0.0.8"
authors = ["AWS s2n"]
edition = "2018"
edition = "2021"
repository = "https://github.com/aws/s2n-tls"
license = "Apache-2.0"

Expand Down

0 comments on commit c8380d0

Please sign in to comment.