Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/run_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive

- name: Cache folders
uses: actions/cache@v4
Expand All @@ -40,4 +42,4 @@ jobs:
# - name: Run tests
# working-directory: .ci
# run: bash run_all_tests.sh


4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand All @@ -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(
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
10 changes: 8 additions & 2 deletions cmake/add_rust_library.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
1 change: 1 addition & 0 deletions crates/c_hash_sig
Submodule c_hash_sig added at 1e6c8c