Skip to content

Commit

Permalink
Support create_bindings() in hacl build on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mamonet committed Aug 29, 2023
1 parent 139d5c7 commit 2879441
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
2 changes: 0 additions & 2 deletions sys/hacl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ libc = { version = "0.2", default-features = false }
fs_extra = "1.3"
cc = { version = "1.0", features = ["parallel"] }
libcrux_platform = { path = "../platform" }

[target.'cfg(not(windows))'.build-dependencies]
bindgen = "0.66"

[dev-dependencies]
Expand Down
22 changes: 9 additions & 13 deletions sys/hacl/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,20 @@ fn includes(home_dir: &Path, include_str: &str) -> Vec<String> {
]
}

fn append_simd128_flags(flags: &mut Vec<String>) {
if cfg!(all(any(target_arch = "x86", target_arch = "x86_64"), not(target_env = "msvc"))) {
fn append_simd128_flags(flags: &mut Vec<String>, is_bindgen: bool) {
if is_bindgen || cfg!(all(any(target_arch = "x86", target_arch = "x86_64"), not(target_env = "msvc"))) {
flags.push("-msse4.1".to_string());
flags.push("-msse4.2".to_string());
flags.push("-mavx".to_string());
}
}

fn append_simd256_flags(flags: &mut Vec<String>) {
if cfg!(not(target_env = "msvc")) {
fn append_simd256_flags(flags: &mut Vec<String>, is_bindgen: bool) {
if is_bindgen || cfg!(not(target_env = "msvc")) {
flags.push("-mavx2".to_string());
}
}

#[cfg(not(windows))]
fn create_bindings(platform: Platform, home_dir: &Path) {
let mut clang_args = includes(home_dir, "-I");

Expand All @@ -54,14 +53,14 @@ fn create_bindings(platform: Platform, home_dir: &Path) {
.header("c/config/hacl.h");

if platform.simd128 {
append_simd128_flags(&mut clang_args);
append_simd128_flags(&mut clang_args, true);
clang_args.push("-DSIMD128".to_string());
bindings = bindings
// Header to wrap HACL SIMD 128 headers
.header("c/config/hacl128.h");
}
if platform.simd256 {
append_simd256_flags(&mut clang_args);
append_simd256_flags(&mut clang_args, true);
clang_args.push("-DSIMD256".to_string());
bindings = bindings
// Header to wrap HACL SIMD 256 headers
Expand Down Expand Up @@ -111,9 +110,6 @@ fn create_bindings(platform: Platform, home_dir: &Path) {
.expect("Couldn't write bindings!");
}

#[cfg(windows)]
fn create_bindings(_: Platform, _: &Path) {}

fn compile_files(
library_name: &str,
files: &[String],
Expand Down Expand Up @@ -210,7 +206,7 @@ fn build(platform: Platform, home_path: &Path) {
defines.append(&mut vec![("HACL_CAN_COMPILE_VEC128", "1")]);

let mut simd128_flags = vec![];
append_simd128_flags(&mut simd128_flags);
append_simd128_flags(&mut simd128_flags, false);
compile_files(
"libhacl_128.a",
&files128,
Expand All @@ -234,7 +230,7 @@ fn build(platform: Platform, home_path: &Path) {
defines.append(&mut vec![("HACL_CAN_COMPILE_VEC256", "1")]);

let mut simd256_flags = vec![];
append_simd256_flags(&mut simd256_flags);
append_simd256_flags(&mut simd256_flags, false);
compile_files(
"libhacl_256.a",
&files256,
Expand Down Expand Up @@ -288,7 +284,7 @@ fn main() {
// Set library name to look up
const LIB_NAME: &str = "hacl";

// Generate new bindings. This is a no-op on Windows.
// Generate new bindings.
create_bindings(platform, home_path);

// Link hacl library.
Expand Down

0 comments on commit 2879441

Please sign in to comment.