Skip to content

Commit 2bafcf1

Browse files
authored
feat: consume openssl from openssl-sys (#275)
* feat: consume openssl from openssl-sys Signed-off-by: James Mayclin <[email protected]> * add separate feature for vendored openssl Signed-off-by: James Mayclin <[email protected]> * forgot to commit Cargo.toml Signed-off-by: James Mayclin <[email protected]> * add ci for vendored_openssl feature Signed-off-by: James Mayclin <[email protected]> * skip windows Signed-off-by: James Mayclin <[email protected]> --------- Signed-off-by: James Mayclin <[email protected]>
1 parent c2e98dc commit 2bafcf1

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

.github/workflows/ci.yml

+6
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ jobs:
8484
- name: Cargo test --no-default-features --features non_portable,kems,sigs,std
8585
run: cargo test --no-default-features --features non_portable,kems,sigs,std --manifest-path oqs/Cargo.toml
8686

87+
# skip windows, because the default image doesn't include several of the
88+
# system dependencies (e.g. Perl) required for the openssl-sys/vendored
89+
- name: Cargo test --features vendored_openssl
90+
if: matrix.os != 'windows-latest'
91+
run: cargo test --features vendored_openssl --manifest-path oqs/Cargo.toml
92+
8793
- name: Cargo fmt
8894
run: cargo fmt --all -- --check
8995

oqs-sys/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ include = ["README.md", "build.rs", "src/**", "liboqs/.CMake/**", "liboqs/src/**
1616

1717
[dependencies]
1818
libc = "0.2"
19+
openssl-sys = { version = "0.9", features = ["vendored"], optional = true }
1920

2021
[build-dependencies]
2122
pkg-config = "0.3"
@@ -26,6 +27,7 @@ build-deps = "0.1"
2627
[features]
2728
default = ["openssl", "kems", "sigs"]
2829
openssl = []
30+
vendored_openssl = ["openssl", "vendored", "dep:openssl-sys"]
2931
docs = []
3032
non_portable = []
3133
vendored = []

oqs-sys/build.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -88,24 +88,35 @@ fn build_from_source() -> PathBuf {
8888
config.define("CMAKE_SYSTEM_VERSION", "10.0");
8989
}
9090

91-
if cfg!(feature = "openssl") {
91+
// link the openssl libcrypto
92+
if cfg!(any(feature = "openssl", feature = "vendored_openssl")) {
9293
config.define("OQS_USE_OPENSSL", "Yes");
9394
if cfg!(windows) {
9495
// Windows doesn't prefix with lib
9596
println!("cargo:rustc-link-lib=libcrypto");
9697
} else {
9798
println!("cargo:rustc-link-lib=crypto");
9899
}
100+
} else {
101+
config.define("OQS_USE_OPENSSL", "No");
102+
}
99103

104+
// let the linker know where to search for openssl libcrypto
105+
if cfg!(feature = "vendored_openssl") {
106+
// DEP_OPENSSL_ROOT is set by openssl-sys if a vendored build was used.
107+
// We point CMake towards this so that the vendored openssl is preferred
108+
// over the system openssl.
109+
let vendored_openssl_root = std::env::var("DEP_OPENSSL_ROOT")
110+
.expect("The `vendored_openssl` feature was enabled, but DEP_OPENSSL_ROOT was not set");
111+
config.define("OPENSSL_ROOT_DIR", vendored_openssl_root);
112+
} else if cfg!(feature = "openssl") {
100113
println!("cargo:rerun-if-env-changed=OPENSSL_ROOT_DIR");
101114
if let Ok(dir) = std::env::var("OPENSSL_ROOT_DIR") {
102115
let dir = Path::new(&dir).join("lib");
103116
println!("cargo:rustc-link-search={}", dir.display());
104117
} else if cfg!(target_os = "windows") || cfg!(target_os = "macos") {
105118
println!("cargo:warning=You may need to specify OPENSSL_ROOT_DIR or disable the default `openssl` feature.");
106119
}
107-
} else {
108-
config.define("OQS_USE_OPENSSL", "No");
109120
}
110121

111122
let permit_unsupported = "OQS_PERMIT_UNSUPPORTED_ARCHITECTURE";
@@ -125,8 +136,10 @@ fn build_from_source() -> PathBuf {
125136
);
126137
}
127138

128-
// lib is installed to $outdir/lib
139+
// lib is installed to $outdir/lib or lib64, depending on CMake conventions
129140
let libdir = outdir.join("lib");
141+
let libdir64 = outdir.join("lib64");
142+
130143
if cfg!(windows) {
131144
// Static linking doesn't work on Windows
132145
println!("cargo:rustc-link-lib=oqs");
@@ -135,6 +148,7 @@ fn build_from_source() -> PathBuf {
135148
println!("cargo:rustc-link-lib=static=oqs");
136149
}
137150
println!("cargo:rustc-link-search=native={}", libdir.display());
151+
println!("cargo:rustc-link-search=native={}", libdir64.display());
138152

139153
outdir
140154
}

oqs/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ default = ["oqs-sys/openssl", "kems", "sigs", "std"]
2424
std = []
2525
non_portable = ["oqs-sys/non_portable"]
2626
vendored = ["oqs-sys/vendored"]
27+
vendored_openssl = ["oqs-sys/vendored_openssl"]
2728

2829
# algorithms: KEMs
2930
kems = ["oqs-sys/kems", "classic_mceliece", "frodokem", "hqc", "kyber", "ml_kem", "ntruprime"]

0 commit comments

Comments
 (0)