From 10bee351cb6c6f6087f2381d303298e2944b5069 Mon Sep 17 00:00:00 2001 From: Rigidity Date: Wed, 21 Aug 2024 13:40:04 -0400 Subject: [PATCH 1/4] Allow offline builds of chiapos with local repos --- .gitignore | 1 + CMakeLists.txt | 79 +++++++++++++++++++++++++++--------------- install-offline.sh | 36 +++++++++++++++++++ rust-bindings/build.rs | 4 +++ 4 files changed, 92 insertions(+), 28 deletions(-) create mode 100644 install-offline.sh diff --git a/.gitignore b/.gitignore index 160c0b854..8f2e81580 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,4 @@ cmake-build* *.tar.gz libs/ target/ +thirdparty/ diff --git a/CMakeLists.txt b/CMakeLists.txt index f66687fde..4dd5adb3b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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-offline.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) @@ -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) @@ -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) @@ -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 diff --git a/install-offline.sh b/install-offline.sh new file mode 100644 index 000000000..ae0ffa5b5 --- /dev/null +++ b/install-offline.sh @@ -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 .. diff --git a/rust-bindings/build.rs b/rust-bindings/build.rs index 0bddc1ead..2b7b11cd2 100644 --- a/rust-bindings/build.rs +++ b/rust-bindings/build.rs @@ -21,6 +21,10 @@ fn main() { let dst = Config::new(cpp_dir.as_path()) .build_target("chiapos_static") .define("BUILD_STATIC_CHIAPOS_LIBRARY", "ON") + .define( + "BUILD_OFFLINE", + env::var("BUILD_OFFLINE").unwrap_or_else(|_| "OFF".to_string()), + ) .build(); let blake3_include_path = dst.join("build").join("_deps").join("blake3-src").join("c"); From 17753733d4681f1b19950da60160bab26cc9a11b Mon Sep 17 00:00:00 2001 From: Rigidity Date: Wed, 21 Aug 2024 13:50:21 -0400 Subject: [PATCH 2/4] Enable offline based on thirdparty dir --- .github/workflows/rust.yml | 3 ++- rust-bindings/build.rs | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9ec65ab1b..1f6d29260 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -62,8 +62,9 @@ jobs: - name: Prepare for publish run: | + sh install-offline.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. diff --git a/rust-bindings/build.rs b/rust-bindings/build.rs index 2b7b11cd2..1a355968c 100644 --- a/rust-bindings/build.rs +++ b/rust-bindings/build.rs @@ -18,12 +18,18 @@ 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", - env::var("BUILD_OFFLINE").unwrap_or_else(|_| "OFF".to_string()), + if build_offline { + "ON".to_string() + } else { + "OFF".to_string() + }, ) .build(); From 6a097591e333b862d4f06f61c4624fec3c8d060e Mon Sep 17 00:00:00 2001 From: Rigidity Date: Wed, 21 Aug 2024 13:59:45 -0400 Subject: [PATCH 3/4] Rename to dependencies --- .github/workflows/rust.yml | 2 +- install-offline.sh => install-dependencies.sh | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename install-offline.sh => install-dependencies.sh (100%) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 1f6d29260..aa212a695 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -62,7 +62,7 @@ jobs: - name: Prepare for publish run: | - sh install-offline.sh + sh install-dependencies.sh mkdir rust-bindings/cpp cp -r src lib tests uint128_t python-bindings c-bindings CMakeLists.txt thirdparty rust-bindings/cpp diff --git a/install-offline.sh b/install-dependencies.sh similarity index 100% rename from install-offline.sh rename to install-dependencies.sh From 9d5209783d79a6edb604ced5c3b8075dfedbf180 Mon Sep 17 00:00:00 2001 From: Rigidity Date: Wed, 21 Aug 2024 14:00:24 -0400 Subject: [PATCH 4/4] Fix CMakeLists.txt --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4dd5adb3b..45e2356f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ project(chiapos C CXX ASM) # CMake 3.14+ include(FetchContent) -# Make sure to also update install-offline.sh with these hashes. +# 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)