Skip to content
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

build(rust-bindings): use the 2021 rust edition #3386

Merged
merged 1 commit into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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") {
Comment on lines 124 to +125
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This statement is ridiculous and I love it.

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() {
Comment on lines +191 to +193
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why switch from checking for the .so to the .a? (see old line 186)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized .so is only Linux. On macOS it's going to by .dylib. Whereas if we use .a we don't have to care :)

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