Skip to content

Commit

Permalink
Don't build libcrux by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
xvzcf committed Dec 5, 2023
1 parent 0c24d49 commit 3202f74
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 14 deletions.
46 changes: 42 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,11 @@ if(TOOLCHAIN_CAN_COMPILE_VEC256 AND HACL_VEC256_O)
target_sources(hacl_static PRIVATE $<TARGET_OBJECTS:hacl_vec256>)
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
Expand Down Expand Up @@ -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)

Expand All @@ -488,6 +489,43 @@ if(ENABLE_TESTS)
${PROJECT_SOURCE_DIR}/tests/${TEST_NAME} $<TARGET_FILE_DIR:${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} $<TARGET_FILE_DIR:${TEST_NAME}>)
endif()
endforeach()
endif()
endif()

# Benchmarks
Expand Down
2 changes: 1 addition & 1 deletion _build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,9 @@
],
"aead": [
"aead.cc"
],
]
},
"libcrux_tests": {
"kyber": [
"kyber.cc"
]
Expand Down
3 changes: 2 additions & 1 deletion mach
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 4 additions & 6 deletions rust/hacl-sys/src/bindings/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)]
Expand Down
17 changes: 17 additions & 0 deletions tools/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
% (
Expand Down
3 changes: 2 additions & 1 deletion tools/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])


Expand Down

0 comments on commit 3202f74

Please sign in to comment.