diff --git a/opam.sh b/opam.sh index ba03cf31..505596a3 100755 --- a/opam.sh +++ b/opam.sh @@ -14,6 +14,7 @@ cp include/* opam/hacl-star-raw/include/ | true cp -r include/internal opam/hacl-star-raw/include/internal cp -r vale opam/hacl-star-raw cp -r karamel opam/hacl-star-raw +cp -r cpu-features opam/hacl-star-raw cp CMakeLists.txt opam/hacl-star-raw diff --git a/rust/hacl-sys/build.rs b/rust/hacl-sys/build.rs index 6f953c1e..26e7ad0a 100644 --- a/rust/hacl-sys/build.rs +++ b/rust/hacl-sys/build.rs @@ -70,45 +70,34 @@ fn create_bindings(include_path: &Path, home_dir: &Path) { fn create_bindings(_: &Path, _: &Path) {} fn build_hacl_c(path: &Path, cross_target: Option) { - eprintln!(" >>> Building HACL C in {}", path.display()); + println!(" >>> Building HACL C in {}", path.display()); // cmake let mut cmake_cmd = Command::new("cmake"); // Map cross compile targets to cmake toolchain files let toolchain_file = cross_target - .clone() .map(|s| match s.as_str() { - "x86_64-apple-darwin" => vec!["-D", "CMAKE_TOOLCHAIN_FILE=config/x64-darwin.cmake"], - "aarch64-apple-darwin" => { - vec!["-D", "CMAKE_TOOLCHAIN_FILE=config/aarch64-darwin.cmake"] - } - _ => vec![], + "x86_64-apple-darwin" => "-DCMAKE_TOOLCHAIN_FILE=config/x64-darwin.cmake", + "aarch64-apple-darwin" => "-DCMAKE_TOOLCHAIN_FILE=config/aarch64-darwin.cmake", + _ => "", }) .unwrap_or_default(); - let mut cmake_args = cross_target - .map(|s| match s.as_str() { - "i686-unknown-linux-gnu" => vec!["-DCMAKE_C_FLAGS=-m32", "-D", "CMAKE_CXX_FLAGS=-m32"], - "i686-pc-windows-msvc" => vec!["-DCMAKE_C_FLAGS=-m32", "-D", "CMAKE_CXX_FLAGS=-m32"], - _ => vec![], - }) - .unwrap_or_default(); - if !toolchain_file.is_empty() { - cmake_args.extend_from_slice(&toolchain_file); - } - cmake_args.extend_from_slice(&[ - "-B", - "build", - "-G", - "Ninja", - "-D", - "CMAKE_BUILD_TYPE=Release", - ]); // We always build the release version here. // TODO: For debugging don't use this. - let cmake_cmd = cmake_cmd.current_dir(path).args(&cmake_args); - eprintln!(" >>> CMAKE: {cmake_cmd:?}"); - let cmake_status = cmake_cmd.status().expect("Failed to run cmake."); + let cmake_status = cmake_cmd + .current_dir(path) + .args(&[ + "-B", + "build", + "-G", + "Ninja", + "-D", + "CMAKE_BUILD_TYPE=Release", + toolchain_file, + ]) + .status() + .expect("Failed to run cmake."); if !cmake_status.success() { panic!("Failed to run cmake.") } @@ -125,7 +114,7 @@ fn build_hacl_c(path: &Path, cross_target: Option) { // install let install_path = path.join("build").join("installed"); - eprintln!(" >>> Installing HACL C into {}", install_path.display()); + println!(" >>> Installing HACL C into {}", install_path.display()); let mut cmake_cmd = Command::new("cmake"); let cmake_status = cmake_cmd .current_dir(path) @@ -159,6 +148,7 @@ fn copy_hacl_to_out(out_dir: &Path) { copy(&local_c_path.join("vale"), &out_dir, &options).unwrap(); copy(&local_c_path.join("karamel"), &out_dir, &options).unwrap(); copy(&local_c_path.join("include"), &out_dir, &options).unwrap(); + copy(&local_c_path.join("cpu-features"), &out_dir, &options).unwrap(); let options = file::CopyOptions::new().overwrite(true); file::copy( @@ -184,9 +174,9 @@ fn main() { let host = env::var("HOST").unwrap(); let out_dir = env::var("OUT_DIR").unwrap(); let out_dir = Path::new(&out_dir); - eprintln!("mach_build: {}", mach_build); + println!("mach_build: {}", mach_build); - let cross_target = if target != host { Some(target.clone()) } else { None }; + let cross_target = if target != host { Some(target) } else { None }; // Get the C library and build it first. // This is the default behaviour. It can be disabled when working on this @@ -195,9 +185,9 @@ fn main() { // Copy all of the code into out to prepare build let c_out_dir = out_dir.join("c"); if !c_out_dir.join("build").join("installed").exists() { - eprintln!(" >>> Copying HACL C file"); - eprintln!(" from {}", home_dir.join(".c").display()); - eprintln!(" to {}", c_out_dir.display()); + println!(" >>> Copying HACL C file"); + println!(" from {}", home_dir.join(".c").display()); + println!(" to {}", c_out_dir.display()); copy_hacl_to_out(&c_out_dir); } build_hacl_c(&c_out_dir, cross_target); @@ -233,7 +223,8 @@ fn main() { create_bindings(&hacl_include_path, home_dir); // Link hacl library. + let mode = "static"; + println!("cargo:rustc-link-lib={}={}", mode, library_name); println!("cargo:rustc-link-search=native={}", hacl_lib_path.display()); println!("cargo:lib={}", hacl_lib_path.display()); - println!("cargo:rustc-link-lib=static={library_name}"); }