Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow offline builds of chiapos with local repos #442

Closed
wants to merge 4 commits into from
Closed
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
3 changes: 2 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ jobs:

- name: Prepare for publish
run: |
sh install-dependencies.sh
mkdir rust-bindings/cpp
cp -r src lib tests uint128_t python-bindings c-bindings CMakeLists.txt rust-bindings/cpp
cp -r src lib tests uint128_t python-bindings c-bindings CMakeLists.txt thirdparty rust-bindings/cpp

- name: Publish to crates.io (dry run)
# We use `--allow-dirty` because the `cpp` folder is copied into the working directory.
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ cmake-build*
*.tar.gz
libs/
target/
thirdparty/
79 changes: 51 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,32 @@ project(chiapos C CXX ASM)
# CMake 3.14+
include(FetchContent)

if (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
include(${CMAKE_INSTALL_PREFIX}/share/cmake/pybind11/pybind11Config.cmake)
# Make sure to also update install-dependencies.sh with these hashes.
option(BUILD_OFFLINE "Build offline, without fetching dependencies from Git" OFF)

if (BUILD_OFFLINE)
FetchContent_Declare(pybind11 SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/thirdparty/pybind11")
FetchContent_MakeAvailable(pybind11)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
include(${CMAKE_INSTALL_PREFIX}/share/cmake/pybind11/pybind11Config.cmake)
else()
FetchContent_Declare(
pybind11-src
GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG v2.11.1
)
FetchContent_MakeAvailable(pybind11-src)
FetchContent_Declare(
pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG 8a099e44b3d5f85b20f05828d919d2332a8de841 # v2.11.1
)
FetchContent_MakeAvailable(pybind11)
endif()

FetchContent_Declare(
cxxopts
GIT_REPOSITORY https://github.com/jarro2783/cxxopts.git
GIT_TAG v3.1.1
)
if (BUILD_OFFLINE)
FetchContent_Declare(cxxopts SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/thirdparty/cxxopts")
else()
FetchContent_Declare(
cxxopts
GIT_REPOSITORY https://github.com/jarro2783/cxxopts.git
GIT_TAG eb787304d67ec22f7c3a184ee8b4c481d04357fd # v3.1.1
)
endif()
FetchContent_MakeAvailable(cxxopts)

option(CP_LINK_BLADEBIT_HARVESTER "Links libbladebit_harvester at build time instead of dynamically loading it." OFF)
Expand All @@ -53,11 +63,16 @@ if (${CP_BUILD_BLADEBIT_HARVESTER})
FetchContent_MakeAvailable(bladebit)
endif()

FetchContent_Declare(
gulrak
GIT_REPOSITORY https://github.com/gulrak/filesystem.git
GIT_TAG v1.5.14
)
if (BUILD_OFFLINE)
FetchContent_Declare(gulrak SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/thirdparty/filesystem")
FetchContent_MakeAvailable(gulrak)
else()
FetchContent_Declare(
gulrak
GIT_REPOSITORY https://github.com/gulrak/filesystem.git
GIT_TAG 8a2edd6d92ed820521d42c94d179462bf06b5ed3 # v1.5.14
)
endif()
FetchContent_MakeAvailable(gulrak)

set(FSE_LIB ${CMAKE_CURRENT_SOURCE_DIR}/lib/FiniteStateEntropy/lib)
Expand Down Expand Up @@ -128,11 +143,15 @@ add_executable(ProofOfSpace
src/chacha8.c
)

FetchContent_Declare(
blake3
GIT_REPOSITORY https://github.com/BLAKE3-team/BLAKE3.git
GIT_TAG 1.5.0
)
if (BUILD_OFFLINE)
FetchContent_Declare(blake3 SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/thirdparty/BLAKE3")
else()
FetchContent_Declare(
blake3
GIT_REPOSITORY https://github.com/BLAKE3-team/BLAKE3.git
GIT_TAG 5aa53f07f7188a569cadfc5daf1522972d9a9630 # 1.5.0
)
endif()

FetchContent_GetProperties(blake3)
if(NOT blake3_POPULATED)
Expand Down Expand Up @@ -167,11 +186,15 @@ IF (BUILD_STATIC_CHIAPOS_LIBRARY)
target_include_directories(chiapos_static PUBLIC lib/include)
ENDIF()

FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.5.2
)
if (BUILD_OFFLINE)
FetchContent_Declare(Catch2 SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/thirdparty/Catch2")
else()
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG 05e10dfccc28c7f973727c54f850237d07d5e10f # v3.5.2
)
endif()
FetchContent_MakeAvailable(Catch2)

add_executable(RunTests
Expand Down
36 changes: 36 additions & 0 deletions install-dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
set -e

mkdir -p thirdparty
cd thirdparty

rm -rf pybind11 cxxopts filesystem BLAKE3 Catch2

# Make sure to also update CMakeLists.txt with these hashes.

git clone https://github.com/pybind/pybind11.git -b v2.11.1
cd pybind11
git checkout 8a099e44b3d5f85b20f05828d919d2332a8de841
cd ..

git clone https://github.com/jarro2783/cxxopts.git -b v3.1.1
cd cxxopts
git checkout eb787304d67ec22f7c3a184ee8b4c481d04357fd
cd ..

git clone https://github.com/gulrak/filesystem.git -b v1.5.14
cd filesystem
git checkout 8a2edd6d92ed820521d42c94d179462bf06b5ed3
cd ..

git clone https://github.com/BLAKE3-team/BLAKE3.git -b 1.5.0
cd BLAKE3
git checkout 5aa53f07f7188a569cadfc5daf1522972d9a9630
cd ..

git clone https://github.com/catchorg/Catch2.git -b v3.5.2
cd Catch2
git checkout 05e10dfccc28c7f973727c54f850237d07d5e10f
cd ..

cd ..
10 changes: 10 additions & 0 deletions rust-bindings/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,19 @@ fn main() {
.to_path_buf();
}

let build_offline = cpp_dir.join("thirdparty").try_exists().unwrap();

let dst = Config::new(cpp_dir.as_path())
.build_target("chiapos_static")
.define("BUILD_STATIC_CHIAPOS_LIBRARY", "ON")
.define(
"BUILD_OFFLINE",
if build_offline {
"ON".to_string()
} else {
"OFF".to_string()
},
)
.build();

let blake3_include_path = dst.join("build").join("_deps").join("blake3-src").join("c");
Expand Down
Loading