Trying to compile oqs on the latest nightly for windows-msvc. After the C library compiles into oqs.lib, I get this error:
Compiling oqs v0.3.0 (C:\tmp2\liboqs-rust\oqs)
Running `sccache rustc --crate-name oqs --edition=2018 C:\tmp2\liboqs-rust\oqs\src\lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=bec23c3395d8ca30 -C extra-filename=-bec23c3395d8ca30 --out-dir C:\satori.net\target\debug\deps -C incremental=C:\satori.net\target\debug\incremental -L dependency=C:\satori.net\target\debug\deps --extern libc=C:\satori.net\target\debug\deps\liblibc-4b82f089068ad99f.rmeta --extern oqs_sys=C:\satori.net\target\debug\deps\liboqs_sys-ebdba39aed96788b.rmeta -C target-cpu=native -C target-feature=+aes,+sse2,+sse4.1,+ssse3,avx,avx2 -L native=C:\satori.net\target\debug\build\oqs-sys-ad015ed4de1a6c0b\out\build\lib`
error: could not find native static library `oqs`, perhaps an -L flag is missing?
error: aborting due to previous error
error: could not compile `oqs-sys`
Caused by:
process didn't exit successfully: `sccache rustc --crate-name oqs_sys --edition=2018 C:\tmp2\liboqs-rust\oqs-sys\src\lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=ebdba39aed96788b -C extra-filename=-ebdba39aed96788b --out-dir C:\satori.net\target\debug\deps -C incremental=C:\satori.net\target\debug\incremental -L dependency=C:\satori.net\target\debug\deps --extern libc=C:\satori.net\target\debug\deps\liblibc-4b82f089068ad99f.rmeta -C target-cpu=native -C target-feature=+aes,+sse2,+sse4.1,+ssse3,avx,avx2 -L native=C:\satori.net\target\debug\build\oqs-sys-ad015ed4de1a6c0b\out\build\lib -l static=oqs` (exit code: 1)
warning: build failed, waiting for other jobs to finish...
error: build failed
(You might need to scroll to the right to see the rest).
The output for "oqs.lib" is in C:\satori.net\target\debug\build\oqs-sys-ad015ed4de1a6c0b\out\build\lib (which I manually confirmed exists). So, the compile works. But, after oqs-sys finishes the build script, it shows the error message above. Here is the build script, which gets to the end and returns Ok(()).
use std::path::PathBuf;
fn generate_bindings(outdir: &PathBuf, headerfile: &str, filter: &str) {
let includedir = outdir.join("build").join("include");
bindgen::Builder::default()
.clang_arg(format!("-I{}", includedir.display()))
.header(
includedir
.join("oqs")
.join(format!("{}.h", headerfile))
.to_str()
.unwrap(),
)
// Options
.default_enum_style(bindgen::EnumVariation::Rust {
non_exhaustive: false,
})
.size_t_is_usize(true)
// Don't generate docs unless enabled
// Otherwise it breaks tests
.generate_comments(cfg!(feature = "docs"))
// Whitelist OQS stuff
.whitelist_recursively(false)
.whitelist_type(filter)
.whitelist_function(filter)
.whitelist_var(filter)
// Use core and libc
.use_core()
.ctypes_prefix("::libc")
// Finish the builder and generate the bindings.
.generate()
// Unwrap the Result and panic on failure.
.expect("Unable to generate bindings")
.write_to_file(outdir.join(format!("{}_bindings.rs", headerfile)))
.expect("Couldn't write bindings!");
}
use std::io::Write;
fn main() -> std::io::Result<()> {
let mut file = std::fs::File::create("C:/tmp/build.txt")?;
let mut config = cmake::Config::new("liboqs");
config.profile("Release");
config.define("OQS_BUILD_ONLY_LIB", "Yes");
if cfg!(feature = "openssl") {
config.define("OQS_USE_OPENSSL", "Yes");
println!("cargo:rustc-link-lib=crypto");
} else {
config.define("OQS_USE_OPENSSL", "No");
}
let outdir = config.build_target("oqs").build();
// lib is put into $outdir/build/lib
let libdir = outdir.join("build").join("lib");
let val = format!("Outdir: {}\n", libdir.display());
file.write_all(val.as_bytes())?;
println!("cargo:rustc-link-search=native={}", libdir.display());
println!("cargo:rustc-link-lib=static=oqs");
file.write_all(b"A3\n")?;
let gen_bindings = |file, filter| generate_bindings(&outdir, file, filter);
gen_bindings("common", "OQS_.*");
gen_bindings("kem", "OQS_KEM.*");
gen_bindings("sig", "OQS_SIG.*");
// https://docs.rs/build-deps/0.1.4/build_deps/fn.rerun_if_changed_paths.html
build_deps::rerun_if_changed_paths("liboqs/src/**/*").unwrap();
build_deps::rerun_if_changed_paths("liboqs/src").unwrap();
build_deps::rerun_if_changed_paths("liboqs/src/*").unwrap();
Ok(())
}
github of project: https://github.com/open-quantum-safe/liboqs-rust