diff --git a/.github/workflows/run_tests.yaml b/.github/workflows/run_tests.yaml index a31f5c7..830db2d 100644 --- a/.github/workflows/run_tests.yaml +++ b/.github/workflows/run_tests.yaml @@ -14,6 +14,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + with: + submodules: recursive - name: Cache folders uses: actions/cache@v4 @@ -40,4 +42,4 @@ jobs: # - name: Run tests # working-directory: .ci # run: bash run_all_tests.sh - \ No newline at end of file + diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..0ed8a5f --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "crates/c_hash_sig"] + path = crates/c_hash_sig + url = https://github.com/qdrvm/c-hash-sig + branch = crates-submodule diff --git a/CMakeLists.txt b/CMakeLists.txt index 9684ec8..a446914 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ project(qdrvm-crates C CXX) include(cmake/add_rust_library.cmake) -list(APPEND QDRVM_ALL_CRATES schnorrkel arkworks bandersnatch_vrfs ark_vrf pvm_bindings) +list(APPEND QDRVM_ALL_CRATES schnorrkel arkworks bandersnatch_vrfs ark_vrf pvm_bindings c_hash_sig) set(QDRVM_BIND_CRATES "" CACHE STRING "The list of crates to build or 'all'.") set_property(CACHE QDRVM_BIND_CRATES PROPERTY STRINGS ${QDRVM_ALL_CRATES}) @@ -27,7 +27,12 @@ if (SELECTED_CRATE_NUM EQUAL 0) endif() foreach (CRATE ${SELECTED_CRATES}) - add_rust_library(${CRATE} HEADER_FILE ${PROJECT_SOURCE_DIR}/generated/include/${CRATE}/${CRATE}.h LIB_NAME ${CRATE}_crust) + # Add kagome-crates feature for c_hash_sig to enable build-helper + if (CRATE STREQUAL "c_hash_sig") + add_rust_library(${CRATE} HEADER_FILE ${PROJECT_SOURCE_DIR}/generated/include/${CRATE}/${CRATE}.h LIB_NAME ${CRATE}_crust FEATURES "kagome-crates") + else() + add_rust_library(${CRATE} HEADER_FILE ${PROJECT_SOURCE_DIR}/generated/include/${CRATE}/${CRATE}.h LIB_NAME ${CRATE}_crust) + endif() endforeach() install( diff --git a/README.md b/README.md index 01f8ea8..c20d7dd 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,17 @@ # Kagome Rust Dependencies This repo contains wrappers for rust library which KAGOME uses. The crates in crates/ dir declare C API wrappers for Rust libraries and use cbindgen to generate an actual C header. + +## Setup +When cloning this repository, make sure to initialize submodules: +```bash +git clone --recurse-submodules https://github.com/qdrvm/kagome-crates.git +``` + +Or if you've already cloned the repository: +```bash +git submodule update --init --recursive +``` They need to be in the same CMake project so that Hunter, KAGOME's package manager, always builds them all with the same Rust compiler, otherwise conflicts in Rust runtime symbols happen when linking. In case any of those are required in projects other than KAGOME, this repo may be repurposed in one of the following ways: - Extract the following to a separate repo and use it as a dependency here and for the new project: diff --git a/cmake/add_rust_library.cmake b/cmake/add_rust_library.cmake index 665cb1e..b87c4f9 100644 --- a/cmake/add_rust_library.cmake +++ b/cmake/add_rust_library.cmake @@ -16,15 +16,21 @@ endif () set(CRATES_DIR "${PROJECT_SOURCE_DIR}/crates") function (add_rust_library CRATE_NAME) - cmake_parse_arguments(x "" "HEADER_FILE;LIB_NAME" "" ${ARGV}) + cmake_parse_arguments(x "" "HEADER_FILE;LIB_NAME;FEATURES" "" ${ARGV}) message(STATUS HEADER_FILE: ${x_HEADER_FILE}) message(STATUS LIB_NAME: ${x_LIB_NAME}) + # Add features if specified + if (x_FEATURES) + set(CARGO_FEATURES "--features" "${x_FEATURES}") + endif() + set(CARGO_COMMAND "${CMAKE_COMMAND}" -E env HEADER_FILE="${x_HEADER_FILE}" CBINDGEN_CONFIG="${PROJECT_SOURCE_DIR}/cbindgen.toml" cargo build --target-dir "${CMAKE_BINARY_DIR}/${CRATE_NAME}" - ${CARGO_BUILD_OPTION}) + ${CARGO_BUILD_OPTION} + ${CARGO_FEATURES}) message(STATUS ${CARGO_COMMAND}) add_custom_target( "cargo_build_${CRATE_NAME}" diff --git a/crates/c_hash_sig b/crates/c_hash_sig new file mode 160000 index 0000000..1e6c8ca --- /dev/null +++ b/crates/c_hash_sig @@ -0,0 +1 @@ +Subproject commit 1e6c8cadf3bfc9b3c62da8732a5b900c21d5b316