Skip to content

Commit c123828

Browse files
authored
Use conan to build the project (#5)
* Use conan to build the project * Add build workflow * Fix command * Prepare runner and run tests * Rewrite docs * Put private headers to private dir * Use util from private too * Use another header style * Update openssl * Improve build instructions
1 parent 03687b9 commit c123828

File tree

6 files changed

+157
-88
lines changed

6 files changed

+157
-88
lines changed

.github/workflows/build.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Build and Test
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [main]
7+
workflow_dispatch:
8+
9+
jobs:
10+
build-and-test:
11+
runs-on: heavy
12+
container: ghcr.io/xrplf/clio-ci:14342e087ceb8b593027198bf9ef06a43833c696
13+
14+
strategy:
15+
matrix:
16+
conan_profile: [gcc, clang]
17+
build_type: [Release, Debug]
18+
19+
env:
20+
BUILD_DIR: build
21+
BUILD_TYPE: ${{ matrix.build_type }}
22+
23+
steps:
24+
- name: Cleanup workspace
25+
if: ${{ runner.os == 'macOS' }}
26+
uses: XRPLF/actions/cleanup-workspace@cf0433aa74563aead044a1e395610c96d65a37cf
27+
28+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
29+
with:
30+
fetch-depth: 0
31+
32+
- name: Prepare runner
33+
uses: XRPLF/actions/prepare-runner@2cbf481018d930656e9276fcc20dc0e3a0be5b6d
34+
with:
35+
enable_ccache: false
36+
37+
- name: Run Conan
38+
env:
39+
CONAN_PROFILE: ${{ matrix.conan_profile }}
40+
run: |
41+
conan \
42+
install . \
43+
-of "${BUILD_DIR}" \
44+
-b missing \
45+
-s "build_type=${BUILD_TYPE}" \
46+
-o "&:with_tests=True" \
47+
--profile:all "${CONAN_PROFILE}"
48+
49+
- name: Run CMake
50+
run: |
51+
cmake \
52+
-B "${BUILD_DIR}" \
53+
-S . \
54+
-G Ninja \
55+
-DCMAKE_TOOLCHAIN_FILE:FILEPATH=build/generators/conan_toolchain.cmake \
56+
-DCMAKE_BUILD_TYPE="${BUILD_TYPE}"
57+
58+
- name: Build
59+
run: ninja
60+
working-directory: ${{ env.BUILD_DIR }}
61+
62+
- name: Run tests
63+
run: ctest --output-on-failure
64+
working-directory: ${{ env.BUILD_DIR }}

CMakeLists.txt

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,9 @@
1-
cmake_minimum_required(VERSION 3.10)
1+
cmake_minimum_required(VERSION 3.16)
22
project(mpt-crypto C CXX)
33

44
# --- Find Dependencies ---
55
find_package(OpenSSL REQUIRED)
6-
7-
set(SECP256K1_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../secp256k1" CACHE PATH "Path to secp256k1 source directory")
8-
9-
if (NOT EXISTS ${SECP256K1_SOURCE_DIR}/CMakeLists.txt)
10-
message(FATAL_ERROR "Could not find libsecp256k1 source directory at ${SECP256K1_SOURCE_DIR}.
11-
Ensure it is located at the same level as the mpt-crypto directory.")
12-
endif ()
13-
14-
# Configure libsecp256k1 build options
15-
set(SECP256K1_BUILD_TESTS OFF CACHE BOOL "" FORCE)
16-
set(SECP256K1_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
17-
set(SECP256K1_BUILD_BENCHMARKS OFF CACHE BOOL "" FORCE)
18-
set(SECP256K1_BUILD_EXHAUSTIVE_TESTS OFF CACHE BOOL "" FORCE)
19-
20-
# Add libsecp256k1 as a sub-project (it's now a peer, but CMake treats it as a sub-project here)
21-
# We provide a binary dir name since it's outside our current source tree
22-
add_subdirectory(${SECP256K1_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/secp256k1_build)
6+
find_package(secp256k1 REQUIRED)
237

248
# --- Define The Library ---
259
add_library(mpt-crypto
@@ -35,16 +19,18 @@ add_library(mpt-crypto
3519
src/proof_same_plaintext_multi_shared_r.c)
3620

3721
# --- Set Include Directories ---
38-
target_include_directories(mpt-crypto PUBLIC include PRIVATE ${SECP256K1_SOURCE_DIR}/include
39-
PRIVATE ${SECP256K1_SOURCE_DIR}/src)
22+
target_include_directories(mpt-crypto PUBLIC include)
4023

4124
# --- Set Compile Definitions ---
4225
target_compile_definitions(mpt-crypto PRIVATE USE_SCALAR_8X32 USE_FIELD_10X26 ECMULT_WINDOW_SIZE=15
4326
ECMULT_GEN_PREC_BITS=4)
4427

4528
# --- Link Dependencies ---
46-
target_link_libraries(mpt-crypto PUBLIC secp256k1 PUBLIC OpenSSL::Crypto)
29+
target_link_libraries(mpt-crypto PUBLIC secp256k1::secp256k1 PUBLIC OpenSSL::Crypto)
4730

4831
# --- Testing ---
49-
enable_testing()
50-
add_subdirectory(tests)
32+
option(ENABLE_TESTS "Enable building tests" ON)
33+
if (ENABLE_TESTS)
34+
enable_testing()
35+
add_subdirectory(tests)
36+
endif ()

README.md

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,74 +33,59 @@ Before building, ensure you have the following installed:
3333

3434
- **CMake** (version 3.10 or higher)
3535
- **C Compiler** (GCC, Clang, or AppleClang)
36-
- **OpenSSL 3.x** (development headers and libraries)
3736

3837
On macOS with Homebrew:
3938

4039
```bash
41-
brew install cmake openssl@3
40+
brew install cmake
4241
```
4342

4443
On Ubuntu/Debian:
4544

4645
```bash
47-
sudo apt-get install cmake libssl-dev build-essential
46+
sudo apt-get install cmake build-essential
4847
```
4948

5049
### Dependency Setup
5150

52-
This library requires `libsecp256k1` as a sibling directory. Clone it from the bitcoin-core repository:
53-
54-
```bash
55-
# From the parent directory of mpt-crypto
56-
cd ..
57-
git clone https://github.com/bitcoin-core/secp256k1.git
58-
```
59-
60-
Your directory structure should look like:
61-
62-
```text
63-
Projects/
64-
├── mpt-crypto/
65-
└── secp256k1/
66-
```
51+
Set up Conan using [xrpld's BUILD.md](https://github.com/XRPLF/rippled/blob/develop/BUILD.md#steps)
6752

6853
### Build Instructions
6954

70-
1. **Create the build directory and configure:**
55+
Run following commands to build the library
56+
57+
1. Create build directory:
7158

7259
```bash
73-
cd mpt-crypto
74-
mkdir -p build && cd build
75-
cmake ..
60+
mkdir build && cd build
7661
```
7762

78-
2. **Build the library and tests:**
63+
2. Buld dependencies:
7964

8065
```bash
81-
make -j
66+
conan install .. --build=missing -o "&:with_tests=True"
8267
```
8368

84-
#### Platform-Specific Notes
85-
86-
**macOS (Apple Silicon):** If you encounter architecture mismatch errors with OpenSSL, explicitly set the architecture:
69+
3. Run CMake:
8770

88-
```bash
89-
cmake -DCMAKE_OSX_ARCHITECTURES=arm64 ..
90-
```
71+
```bash
72+
cmake .. \
73+
-DCMAKE_BUILD_TYPE=Release \
74+
-G Ninja \
75+
-DCMAKE_TOOLCHAIN_FILE:FILEPATH=build/generators/conan_toolchain.cmake
76+
```
9177

92-
**macOS (Intel):** Use `x86_64` instead:
78+
4. **Build the library and tests:**
9379

94-
```bash
95-
cmake -DCMAKE_OSX_ARCHITECTURES=x86_64 ..
96-
```
80+
```bash
81+
ninja
82+
```
9783

9884
### Running Tests
9985

100-
After building, run the test suite using CTest:
86+
After building, run the test suite using CTest from the build directory:
10187

10288
```bash
103-
cd build
10489
ctest --output-on-failure
10590
```
10691

cmake/Findsecp256k1.cmake

Lines changed: 0 additions & 24 deletions
This file was deleted.

conanfile.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from conan import ConanFile, tools
2+
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
3+
from conan.tools.files import get
4+
5+
required_conan_version = ">=2.0.0"
6+
7+
8+
class MptCryptoConan(ConanFile):
9+
name = "mpt-crypto"
10+
description = "MPT-Crypto: Cryptographic Primitives for Confidential Assets"
11+
url = "https://github.com/XRPLF/mpt-crypto"
12+
package_type = "library"
13+
settings = "os", "arch", "compiler", "build_type"
14+
options = {
15+
"shared": [True, False],
16+
"fPIC": [True, False],
17+
"with_tests": [True, False],
18+
}
19+
default_options = {
20+
"shared": False,
21+
"fPIC": True,
22+
"with_tests": False,
23+
}
24+
25+
requires = [
26+
"openssl/3.5.5",
27+
"secp256k1/0.7.0",
28+
]
29+
30+
def config_options(self):
31+
if self.settings.os == "Windows":
32+
del self.options.fPIC
33+
34+
def layout(self):
35+
cmake_layout(self, src_folder="src")
36+
self.folders.generators = "build/generators"
37+
38+
def generate(self):
39+
tc = CMakeToolchain(self)
40+
tc.variables["ENABLE_TESTS"] = self.options.with_tests
41+
tc.generate()
42+
43+
deps = CMakeDeps(self)
44+
deps.generate()
45+
46+
def build(self):
47+
cmake = CMake(self)
48+
cmake.configure()
49+
cmake.build()
50+
51+
def package(self):
52+
cmake = CMake(self)
53+
cmake.install()
54+
55+
def package_info(self):
56+
self.cpp_info.libs = ["mpt-crypto"]
57+
self.cpp_info.set_property("cmake_file_name", "mpt-crypto")
58+
self.cpp_info.set_property("cmake_target_name", "mpt-crypto::mpt-crypto")

src/mpt_scalar.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@
4747
/* 2. Include low-level utilities first.
4848
On ARM64/Apple Silicon, the scalar math depends on 128-bit
4949
integer helpers defined in these headers. */
50-
#include "util.h"
51-
#include "int128.h"
52-
#include "int128_impl.h"
50+
#include <private/util.h>
51+
#include <private/int128.h>
52+
#include <private/int128_impl.h>
5353

5454
/* 3. Include the actual scalar implementations */
55-
#include "scalar.h"
56-
#include "scalar_impl.h"
55+
#include <private/scalar.h>
56+
#include <private/scalar_impl.h>
5757

5858
/* --- Implementation --- */
5959

0 commit comments

Comments
 (0)