From 3202f744e8880a2c334d39c81be9f1944a7cbf84 Mon Sep 17 00:00:00 2001 From: xvzcf Date: Tue, 5 Dec 2023 15:24:08 -0500 Subject: [PATCH] Don't build libcrux by default. --- CMakeLists.txt | 46 +++++++++++++++++++++++--- _build.sh | 2 +- config/config.json | 4 ++- mach | 3 +- rust/hacl-sys/src/bindings/bindings.rs | 10 +++--- tools/configure.py | 17 ++++++++++ tools/test.py | 3 +- 7 files changed, 71 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5616f383..e7374bd9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -359,9 +359,11 @@ if(TOOLCHAIN_CAN_COMPILE_VEC256 AND HACL_VEC256_O) target_sources(hacl_static PRIVATE $) endif() -add_library(libcrux_static STATIC ${LIBCRUX_SOURCES}) -if(NOT MSVC) - target_compile_options(libcrux_static PRIVATE -Wsign-conversion -Wconversion -Wall -Wextra -pedantic) +if(BUILD_LIBCRUX) + add_library(libcrux_static STATIC ${LIBCRUX_SOURCES}) + if(NOT MSVC) + target_compile_options(libcrux_static PRIVATE -Wsign-conversion -Wconversion -Wall -Wextra -pedantic) + endif() endif() # Install @@ -476,7 +478,6 @@ if(ENABLE_TESTS) hacl_static hacl_cpu_features nlohmann_json::nlohmann_json - libcrux_static ) target_include_directories(${TEST_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/cpu-features/include) @@ -488,6 +489,43 @@ if(ENABLE_TESTS) ${PROJECT_SOURCE_DIR}/tests/${TEST_NAME} $) endif() endforeach() + + if(BUILD_LIBCRUX) + foreach(TEST_FILE IN LISTS LIBCRUX_TEST_SOURCES) + get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) + add_executable(${TEST_NAME} + ${TEST_FILE} + ) + + # Coverage + if(ENABLE_COVERAGE) + target_compile_options(${TEST_NAME} PRIVATE -fprofile-instr-generate -fcoverage-mapping) + target_link_options(${TEST_NAME} PRIVATE -fprofile-instr-generate -fcoverage-mapping) + endif() + + if(MSVC) + # MSVC needs a modern C++ for designated initializers. + target_compile_options(${TEST_NAME} PRIVATE /std:c++20) + endif(MSVC) + + add_dependencies(${TEST_NAME} hacl hacl_cpu_features) + target_link_libraries(${TEST_NAME} PRIVATE + gtest_main + hacl_static + hacl_cpu_features + nlohmann_json::nlohmann_json + libcrux_static + ) + + if(EXISTS ${PROJECT_SOURCE_DIR}/tests/${TEST_NAME}) + # Copy test input files. They must be in a directory with the same + # name as the test and get copied to the build directory. + add_custom_command(TARGET ${TEST_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${PROJECT_SOURCE_DIR}/tests/${TEST_NAME} $) + endif() + endforeach() + endif() endif() # Benchmarks diff --git a/_build.sh b/_build.sh index 183e0302..5dd654e3 100755 --- a/_build.sh +++ b/_build.sh @@ -6,5 +6,5 @@ printf " ! USE ./mach FOR MORE OPTIONS !\n\n" mkdir build cp config/default_config.cmake build/config.cmake -cmake -B build -G"Ninja Multi-Config" +cmake -B build -G"Ninja Multi-Config" -DBUILD_LIBCRUX=ON ninja -f build-Release.ninja -C build diff --git a/config/config.json b/config/config.json index 3d8992e5..b6f3cee7 100644 --- a/config/config.json +++ b/config/config.json @@ -507,7 +507,9 @@ ], "aead": [ "aead.cc" - ], + ] + }, + "libcrux_tests": { "kyber": [ "kyber.cc" ] diff --git a/mach b/mach index 005c26ba..d5078c23 100755 --- a/mach +++ b/mach @@ -197,7 +197,7 @@ def build(args): if not os.path.exists("build"): os.mkdir("build") - cmake_args = [] + cmake_args = ["-DBUILD_LIBCRUX=1"] # Verbosity verbose = False if args.verbose: @@ -475,6 +475,7 @@ def build(args): # test if requested if args.test: run_tests(config.tests, build_config, coverage=args.coverage) + run_tests(config.libcrux_tests, build_config, coverage=args.coverage) # benchmark if requested if args.benchmark: diff --git a/rust/hacl-sys/src/bindings/bindings.rs b/rust/hacl-sys/src/bindings/bindings.rs index fd024e15..31b89732 100644 --- a/rust/hacl-sys/src/bindings/bindings.rs +++ b/rust/hacl-sys/src/bindings/bindings.rs @@ -884,10 +884,8 @@ extern "C" { output: *mut u8, ); } -pub type __m128i = [::std::os::raw::c_longlong; 2usize]; -pub type Lib_IntVector_Intrinsics_vec128 = __m128i; -pub type __m256i = [::std::os::raw::c_longlong; 4usize]; -pub type Lib_IntVector_Intrinsics_vec256 = __m256i; +pub type uint32x4_t = [u32; 4usize]; +pub type Lib_IntVector_Intrinsics_vec128 = uint32x4_t; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Hacl_Hash_Blake2s_Simd128_block_state_t_s { @@ -944,8 +942,8 @@ extern "C" { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Hacl_Hash_Blake2b_Simd256_block_state_t_s { - pub fst: *mut Lib_IntVector_Intrinsics_vec256, - pub snd: *mut Lib_IntVector_Intrinsics_vec256, + pub fst: *mut *mut ::std::os::raw::c_void, + pub snd: *mut *mut ::std::os::raw::c_void, } pub type Hacl_Hash_Blake2b_Simd256_block_state_t = Hacl_Hash_Blake2b_Simd256_block_state_t_s; #[repr(C)] diff --git a/tools/configure.py b/tools/configure.py index f04c9c58..16df4411 100644 --- a/tools/configure.py +++ b/tools/configure.py @@ -132,6 +132,7 @@ def __init__( self.vale_files = self.config["vale_sources"] self.libcrux_files = self.config["libcrux_sources"] self.tests = self.config["tests"] + self.libcrux_tests = self.config["libcrux_tests"] self.benchmarks = self.config["benchmarks"] self.include_paths = [include_dir] @@ -208,6 +209,12 @@ def __init__( f for files in [self.tests[b] for b in self.tests] for f in files ] + self.libcrux_test_sources = [ + f + for files in [self.libcrux_tests[b] for b in self.libcrux_tests] + for f in files + ] + # Flatten benchmark sources self.benchmark_sources = [ f for files in [self.benchmarks[b] for b in self.benchmarks] for f in files @@ -326,6 +333,16 @@ def write_cmake_config(self, cmake_config): ) ) + out.write( + "set(LIBCRUX_TEST_SOURCES\n\t%s\n)\n" + % ( + "\n\t".join( + join("${PROJECT_SOURCE_DIR}", "tests", f) + for f in self.libcrux_test_sources + ).replace("\\", "/") + ) + ) + out.write( "set(BENCHMARK_SOURCES\n\t%s\n)\n" % ( diff --git a/tools/test.py b/tools/test.py index 688159e3..10e23529 100644 --- a/tools/test.py +++ b/tools/test.py @@ -64,8 +64,9 @@ def run_tests(tests, bin_path, test_args=[], algorithms=[], coverage=False): if coverage: generate_report(test_name, my_env) + os.chdir(dir_backup) + if coverage: - os.chdir(dir_backup) subprocess.call(["./tools/coverage.sh"])