diff --git a/Makefile b/Makefile index 2ba495da5..95860af20 100644 --- a/Makefile +++ b/Makefile @@ -243,16 +243,20 @@ test_boolean: install_rs_build_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \ --features=$(TARGET_ARCH_FEATURE),boolean -p tfhe -- boolean:: -.PHONY: test_c_api # Run the tests for the C API -test_c_api: install_rs_check_toolchain +.PHONY: test_c_api_rs # Run the rust tests for the C API +test_c_api_rs: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) test --profile $(CARGO_PROFILE) \ --features=$(TARGET_ARCH_FEATURE),boolean-c-api,shortint-c-api,high-level-c-api \ -p tfhe \ c_api - - "$(MAKE)" build_c_api + +.PHONY: test_c_api_c # Run the C tests for the C API +test_c_api_c: build_c_api ./scripts/c_api_tests.sh +.PHONY: test_c_api # Run all the tests for the C API +test_c_api: test_c_api_rs test_c_api_c + .PHONY: test_shortint_ci # Run the tests for shortint ci test_shortint_ci: install_rs_build_toolchain install_cargo_nextest BIG_TESTS_INSTANCE="$(BIG_TESTS_INSTANCE)" \ diff --git a/scripts/c_api_tests.sh b/scripts/c_api_tests.sh index 0d99693b8..e41697434 100755 --- a/scripts/c_api_tests.sh +++ b/scripts/c_api_tests.sh @@ -40,7 +40,7 @@ mkdir -p "${TFHE_BUILD_DIR}" cd "${TFHE_BUILD_DIR}" -cmake .. -DCMAKE_BUILD_TYPE=RELEASE +cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DCARGO_PROFILE="${CARGO_PROFILE}" make -j diff --git a/tfhe/build.rs b/tfhe/build.rs index 4a77dc060..e0547d678 100644 --- a/tfhe/build.rs +++ b/tfhe/build.rs @@ -7,6 +7,18 @@ fn gen_c_api() { return; } + fn get_build_profile_name() -> String { + // The profile name is always the 3rd last part of the path (with 1 based indexing). + // e.g. /code/core/target/cli/build/my-build-info-9f91ba6f99d7a061/out + let out_dir = std::env::var("OUT_DIR") + .expect("OUT_DIR is not set, cannot determine build profile, aborting"); + out_dir + .split(std::path::MAIN_SEPARATOR) + .nth_back(3) + .expect("Cannot determine build profile, aborting") + .to_string() + } + /// Find the location of the `target/` directory. Note that this may be /// overridden by `cmake`, so we also need to check the `CARGO_TARGET_DIR` /// variable. @@ -14,7 +26,8 @@ fn gen_c_api() { if let Ok(target) = env::var("CARGO_TARGET_DIR") { PathBuf::from(target) } else { - PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("../target/release") + PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()) + .join(format!("../target/{}", get_build_profile_name())) } } diff --git a/tfhe/c_api_tests/CMakeLists.txt b/tfhe/c_api_tests/CMakeLists.txt index 21cd966ca..e7c6275dd 100644 --- a/tfhe/c_api_tests/CMakeLists.txt +++ b/tfhe/c_api_tests/CMakeLists.txt @@ -2,7 +2,10 @@ project(tfhe-c-api-tests) cmake_minimum_required(VERSION 3.16) -set(TFHE_C_API_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/../../target/release/") +if(NOT CARGO_PROFILE) + set(CARGO_PROFILE release) +endif() +set(TFHE_C_API_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/../../target/${CARGO_PROFILE}") include_directories(${TFHE_C_API_RELEASE}) add_library(Tfhe STATIC IMPORTED)