Skip to content

Commit 74fcbc3

Browse files
committed
Don't build the c wrapper library by default (avoid it in the wheel) + add workflow for the c libs
1 parent 2ee0789 commit 74fcbc3

File tree

2 files changed

+105
-6
lines changed

2 files changed

+105
-6
lines changed
+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Build C Libraries
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
release:
8+
types: [published]
9+
pull_request:
10+
branches:
11+
- '**'
12+
13+
concurrency:
14+
# SHA is added to the end if on `main` to let all main workflows run
15+
group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }}-${{ (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/') || startsWith(github.ref, 'refs/heads/long_lived/')) && github.sha || '' }}
16+
cancel-in-progress: true
17+
18+
permissions:
19+
contents: read
20+
id-token: write
21+
22+
jobs:
23+
build-c-libraries:
24+
name: C Libraries - ${{ matrix.os.name }} ${{ matrix.arch.name }}
25+
runs-on: ${{ matrix.os.runs-on[matrix.arch.matrix] }}
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
os:
30+
- name: macOS
31+
matrix: macos
32+
runs-on:
33+
arm: [macOS, ARM64]
34+
intel: [macos-11]
35+
- name: Ubuntu
36+
matrix: ubuntu
37+
runs-on:
38+
arm: [Linux, ARM64]
39+
intel: [ubuntu-latest]
40+
- name: Windows
41+
matrix: windows
42+
runs-on:
43+
intel: [windows-latest]
44+
arch:
45+
- name: ARM
46+
matrix: arm
47+
- name: Intel
48+
matrix: intel
49+
exclude:
50+
# Only partial entries are required here by GitHub Actions so generally I
51+
# only specify the `matrix:` entry. The super linter complains so for now
52+
# all entries are included to avoid that. Reported at
53+
# https://github.com/github/super-linter/issues/3016
54+
- os:
55+
name: Windows
56+
matrix: windows
57+
runs-on:
58+
intel: [windows-latest]
59+
arch:
60+
name: ARM
61+
matrix: arm
62+
63+
steps:
64+
- name: Clean workspace
65+
uses: Chia-Network/actions/clean-workspace@main
66+
67+
- name: Checkout code
68+
uses: actions/checkout@v4
69+
with:
70+
fetch-depth: 0
71+
72+
- name: Build
73+
working-directory: src
74+
run: |
75+
cmake . -DBUILD_CHIAVDFC=ON
76+
make
77+
78+
- name: Upload artifacts
79+
uses: actions/upload-artifact@v3
80+
with:
81+
name: c-libraries
82+
path: ./src/lib

src/CMakeLists.txt

+23-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
CMAKE_MINIMUM_REQUIRED(VERSION 3.14 FATAL_ERROR)
2+
option(BUILD_CHIAVDFC "Build the chiavdfc shared library" OFF)
23

34
set(CMAKE_CXX_STANDARD 17)
45
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
@@ -46,11 +47,27 @@ add_executable(verifier_test
4647
${CMAKE_CURRENT_SOURCE_DIR}/refcode/lzcnt.c
4748
)
4849

49-
add_library(chiavdfc SHARED
50-
${CMAKE_CURRENT_SOURCE_DIR}/c_bindings/c_wrapper.cpp
51-
${CMAKE_CURRENT_SOURCE_DIR}/refcode/lzcnt.c
52-
)
53-
5450
target_link_libraries(chiavdf PRIVATE ${GMP_LIBRARIES} ${GMPXX_LIBRARIES} -pthread)
5551
target_link_libraries(verifier_test ${GMP_LIBRARIES} ${GMPXX_LIBRARIES} -pthread)
56-
target_link_libraries(chiavdfc ${GMP_LIBRARIES} ${GMPXX_LIBRARIES})
52+
53+
if(BUILD_CHIAVDFC)
54+
add_library(chiavdfc_shared SHARED
55+
${CMAKE_CURRENT_SOURCE_DIR}/c_bindings/c_wrapper.cpp
56+
${CMAKE_CURRENT_SOURCE_DIR}/refcode/lzcnt.c
57+
)
58+
add_library(chiavdfc_static STATIC
59+
${CMAKE_CURRENT_SOURCE_DIR}/c_bindings/c_wrapper.cpp
60+
${CMAKE_CURRENT_SOURCE_DIR}/refcode/lzcnt.c
61+
)
62+
target_link_libraries(chiavdfc_shared ${GMP_LIBRARIES} ${GMPXX_LIBRARIES})
63+
target_link_libraries(chiavdfc_static ${GMP_LIBRARIES} ${GMPXX_LIBRARIES})
64+
65+
set_target_properties(chiavdfc_shared PROPERTIES
66+
OUTPUT_NAME chiavdfc
67+
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/shared"
68+
)
69+
set_target_properties(chiavdfc_static PROPERTIES
70+
OUTPUT_NAME chiavdfc
71+
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/static"
72+
)
73+
endif()

0 commit comments

Comments
 (0)