From c0ae31630bedc8c8377ef91a5e5b8f37ed15d6eb Mon Sep 17 00:00:00 2001 From: Andrea Bueide Date: Sat, 3 Sep 2022 20:52:27 -0500 Subject: [PATCH 1/6] try to find bls --- CMakeLists.txt | 27 +++-- cmake_modules/FindBLS.cmake | 31 ++++++ flake.lock | 195 ++++++++++++++++++++++++++++++++++++ flake.nix | 49 +++++++++ 4 files changed, 291 insertions(+), 11 deletions(-) create mode 100644 cmake_modules/FindBLS.cmake create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/CMakeLists.txt b/CMakeLists.txt index a8022376..f2a2a753 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,12 +30,14 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules ) +set(BUILD_LOCAL "0" CACHE STRING "") # # Grab Dependencies # set(platform_libs) +if(NOT BUILD_LOCAL) # BLS include(FetchContent) @@ -49,6 +51,9 @@ set(BUILD_BLS_PYTHON_BINDINGS "0" CACHE STRING "0") set(BUILD_BLS_TESTS "0" CACHE STRING "") set(BUILD_BLS_BENCHMARKS "0" CACHE STRING "") FetchContent_MakeAvailable(bls) +else() + find_package(bls REQUIRED) +endif() # Threads find_package(Threads REQUIRED) @@ -157,13 +162,13 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") ${c_opts}) set(tests_c_opts /DBB_TEST_MODE=1 ${tests_c_opts}) - - set(link_opts + + set(link_opts /SUBSYSTEM:CONSOLE /STACK:33554432,1048576 ${link_opts}) - set(release_c_opts + set(release_c_opts /Oi /O2 /Gy @@ -214,7 +219,7 @@ else() set(tests_c_opts -DBB_TEST_MODE=1 ${tests_c_opts}) - set(release_c_opts + set(release_c_opts -O3 #-flto -D_NDEBUG=1 -DNDEBUG=1 @@ -239,7 +244,7 @@ else() # Avoid ranlib error: plugin needed to handle lto objectR "gcc-ar") # set(c_opts -ffat-lto-objects ${c_opts}) - + # Build with native architecture when not building release packages if(NOT DEFINED ENV{CI}) set(c_opts -march=native ${c_opts}) @@ -291,7 +296,7 @@ file(GLOB_RECURSE src_tests RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} tests/*.cpp ) -file(GLOB_RECURSE src_dev RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} +file(GLOB_RECURSE src_dev RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} CONFIGURE_DEPENDS LIST_DIRECTORIES false src/sandbox/*.cpp src/sandbox/*.h @@ -376,7 +381,7 @@ set(bb_include_dirs # target_compile_options(${tgt} PRIVATE $<$:${c_opts} ${debug_c_opts}>) # target_link_options(${tgt} PRIVATE $<$:${link_opts} ${release_link_opts}>) # target_link_options(${tgt} PRIVATE $<$:${link_opts} ${debug_link_opts}>) - + # target_include_directories(${tgt} PRIVATE ${bb_include_dirs}) # endmacro() @@ -388,7 +393,7 @@ set_target_properties(lib_bladebit PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>" ) target_link_libraries(lib_bladebit PUBLIC Threads::Threads bls ${platform_libs}) -target_include_directories(lib_bladebit PUBLIC ${bb_include_dirs}) +target_include_directories(lib_bladebit PUBLIC ${bb_include_dirs} ${BLS_INCLUDE_DIR}) target_compile_options(lib_bladebit PUBLIC $<$:${c_opts} ${release_c_opts}>) target_compile_options(lib_bladebit PUBLIC $<$:${c_opts} ${debug_c_opts}>) @@ -405,11 +410,11 @@ target_link_libraries(bladebit_dev PRIVATE lib_bladebit) add_executable(fsegen src/tools/FSETableGenerator.cpp ${bb_sources} ${bb_headers}) target_link_libraries(fsegen PRIVATE lib_bladebit) -# add_executable(plot_tool -# src/tools/PlotTools_Main.cpp +# add_executable(plot_tool +# src/tools/PlotTools_Main.cpp # src/tools/PlotReader.cpp # src/tools/PlotValidator.cpp -# src/tools/PlotComparer.cpp +# src/tools/PlotComparer.cpp # ${bb_headers} # ) # target_link_libraries(plot_tool PRIVATE lib_bladebit) diff --git a/cmake_modules/FindBLS.cmake b/cmake_modules/FindBLS.cmake new file mode 100644 index 00000000..333e6f6d --- /dev/null +++ b/cmake_modules/FindBLS.cmake @@ -0,0 +1,31 @@ +# Find libnuma +# +# NUMA_FOUND : True if libnuma was found +# NUMA_INCLUDE_DIR : Where to find numa.h & numaif.h +# NUMA_LIBRARY : Library to link + +include(FindPackageHandleStandardArgs) + +find_path(BLS_INCLUDE_DIR + NAMES bls.hpp chiabls/bls.hpp + HINTS ${INCLUDE_INSTALL_DIR}) + +find_library(BLS_LIBRARY + NAMES libbls.a + HINTS ${LIB_INSTALL_DIR}) + +if(BLS_INCLUDE_DIR) + message("Found bls includes: ${BLS_INCLUDE_DIR}") +endif() + +if(BLS_LIBRARY) + message("Found bls library: ${BLS_LIBRARY}") +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(bls + REQUIRED_VARS BLS_INCLUDE_DIR BLS_LIBRARY) + +mark_as_advanced( + BLS_INCLUDE_DIR + BLS_LIBRARY) \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..9241cad8 --- /dev/null +++ b/flake.lock @@ -0,0 +1,195 @@ +{ + "nodes": { + "bls-signatures": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "relic": "relic" + }, + "locked": { + "lastModified": 1662244740, + "narHash": "sha256-Z7wMgzljIoVHqY/DVniL7CUtYi/2am5y6rRiK3LCKZU=", + "owner": "abueide", + "repo": "bls-signatures", + "rev": "2c412f8b0a95adb1548973864fb282b43051b5b8", + "type": "github" + }, + "original": { + "owner": "abueide", + "ref": "flake", + "repo": "bls-signatures", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_3": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_4": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1662252173, + "narHash": "sha256-fEyM+K/N4srfUNdf9O5yoncyFS8nuUe4TkjgX5LGU4I=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "65bb4b6d3f13ba962541d7ae27a13f42ca673658", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1662158175, + "narHash": "sha256-tFdRHPacHDEuiAFusNe/ZSkPvtSiPouDu6PYQpizIJc=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "96ff5b58ec922f626d039406914ae4b5caef530f", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1662252173, + "narHash": "sha256-fEyM+K/N4srfUNdf9O5yoncyFS8nuUe4TkjgX5LGU4I=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "65bb4b6d3f13ba962541d7ae27a13f42ca673658", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_4": { + "locked": { + "lastModified": 1662158175, + "narHash": "sha256-tFdRHPacHDEuiAFusNe/ZSkPvtSiPouDu6PYQpizIJc=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "96ff5b58ec922f626d039406914ae4b5caef530f", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "type": "github" + } + }, + "relic": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1662240382, + "narHash": "sha256-NveG1oOnl1j01eamwcwQ8StjCOOmY0j4M+4QqgjjFW4=", + "owner": "abueide", + "repo": "relic", + "rev": "3a455a4d5f8233951d11e819786e6b2d7eb20ae4", + "type": "github" + }, + "original": { + "owner": "abueide", + "ref": "flake", + "repo": "relic", + "type": "github" + } + }, + "relic_2": { + "inputs": { + "flake-utils": "flake-utils_4", + "nixpkgs": "nixpkgs_4" + }, + "locked": { + "lastModified": 1662240382, + "narHash": "sha256-NveG1oOnl1j01eamwcwQ8StjCOOmY0j4M+4QqgjjFW4=", + "owner": "abueide", + "repo": "relic", + "rev": "3a455a4d5f8233951d11e819786e6b2d7eb20ae4", + "type": "github" + }, + "original": { + "owner": "abueide", + "ref": "flake", + "repo": "relic", + "type": "github" + } + }, + "root": { + "inputs": { + "bls-signatures": "bls-signatures", + "flake-utils": "flake-utils_3", + "nixpkgs": "nixpkgs_3", + "relic": "relic_2" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..c5fac6b8 --- /dev/null +++ b/flake.nix @@ -0,0 +1,49 @@ +{ + description = "A very basic flake"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs"; + flake-utils.url = "github:numtide/flake-utils"; + relic.url = "github:abueide/relic/flake"; + bls-signatures.url = "github:abueide/bls-signatures/flake"; + }; + + outputs = { self, nixpkgs, flake-utils, relic, bls-signatures }: + flake-utils.lib.eachDefaultSystem (system: + let pkgs = nixpkgs.legacyPackages.${system}; + chia-relic = relic.defaultPackage.${system}; + bls = bls-signatures.defaultPackage.${system}; + deps = with pkgs; [ cmake gmp gmp.dev libsodium chia-relic bls-signatures ]; + platform_deps = if(pkgs.lib.strings.hasSuffix "linux" system) then [ pkgs.numactl ] else []; + in rec { + devShells.default = pkgs.mkShell { + packages = deps; + }; + defaultPackage = with pkgs; stdenv.mkDerivation { + pname = "bladebit"; + version = "develop"; + + src = self; + + nativeBuildInputs = [ cmake gmp gmp.dev libsodium chia-relic bls ] ++ platform_deps; + + buildPhase = '' + cmake . -DBUILD_BLADEBIT_TESTS=false + cmake --build . --target bladebit --config Release + ''; + + installPhase = '' + runHook preInstall + install -D -m 755 bladebit $out/bin/bladebit + runHook postInstall + ''; + + enableParallelBuilding = true; + cmakeFlags = [ + "-DBUILD_BLADEBIT_TESTS=false" + "-DBUILD_LOCAL=true" + ]; + }; +} +); +} From 0c8c7e2cab4646df8850d1a9e1827ca6a408de64 Mon Sep 17 00:00:00 2001 From: Andrea Bueide Date: Sat, 3 Sep 2022 22:58:29 -0500 Subject: [PATCH 2/6] nix build --- .gitignore | 45 +++++++++++++++++++---------------- CMakeLists.txt | 1 + cmake_modules/FindBLS.cmake | 8 +------ cmake_modules/FindRelic.cmake | 25 +++++++++++++++++++ flake.nix | 8 +++---- 5 files changed, 55 insertions(+), 32 deletions(-) create mode 100644 cmake_modules/FindRelic.cmake diff --git a/.gitignore b/.gitignore index 76391d19..174ff163 100644 --- a/.gitignore +++ b/.gitignore @@ -1,21 +1,24 @@ -.[bB]in/ -.[oP]bj/ -[bB]in/ -[oP]bj/ -[tT]mp/ -_[tT]mp/ - -.vs/ -.sandbox/ -.dist/ -.keys/ -dist/ -out/ - -.DS_Store -*.log -park*_hash.txt - -lib/* -build*/ -cmake-build*/ +.[bB]in/ +.[oP]bj/ +[bB]in/ +[oP]bj/ +[tT]mp/ +_[tT]mp/ + +.vs/ +.sandbox/ +.dist/ +.keys/ +dist/ +out/ + +.DS_Store +*.log +park*_hash.txt + +lib/* +build*/ +cmake-build*/ + +.idea/ +cmake-build-debug/ diff --git a/CMakeLists.txt b/CMakeLists.txt index f2a2a753..59c2fd88 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,7 @@ set(BUILD_BLS_BENCHMARKS "0" CACHE STRING "") FetchContent_MakeAvailable(bls) else() find_package(bls REQUIRED) + find_package(relic REQUIRED) endif() # Threads diff --git a/cmake_modules/FindBLS.cmake b/cmake_modules/FindBLS.cmake index 333e6f6d..19b4702f 100644 --- a/cmake_modules/FindBLS.cmake +++ b/cmake_modules/FindBLS.cmake @@ -14,13 +14,7 @@ find_library(BLS_LIBRARY NAMES libbls.a HINTS ${LIB_INSTALL_DIR}) -if(BLS_INCLUDE_DIR) - message("Found bls includes: ${BLS_INCLUDE_DIR}") -endif() - -if(BLS_LIBRARY) - message("Found bls library: ${BLS_LIBRARY}") -endif() +set(BLS_INCLUDE_DIR ${BLS_INCLUDE_DIR}/chiabls) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(bls diff --git a/cmake_modules/FindRelic.cmake b/cmake_modules/FindRelic.cmake new file mode 100644 index 00000000..3db3cffc --- /dev/null +++ b/cmake_modules/FindRelic.cmake @@ -0,0 +1,25 @@ +# Find libnuma +# +# NUMA_FOUND : True if libnuma was found +# NUMA_INCLUDE_DIR : Where to find numa.h & numaif.h +# NUMA_LIBRARY : Library to link + +include(FindPackageHandleStandardArgs) + +find_path(RELIC_INCLUDE_DIR + NAMES relic_conf.h relic/relic_conf.h + HINTS ${INCLUDE_INSTALL_DIR}) + +find_library(RELIC_LIBRARY + NAMES librelic_s.a + HINTS ${LIB_INSTALL_DIR}) + +set(RELIC_INCLUDE_DIR ${RELIC_INCLUDE_DIR}/relic) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(RELIC + REQUIRED_VARS RELIC_INCLUDE_DIR RELIC_LIBRARY) + +mark_as_advanced( + RELIC_INCLUDE_DIR + RELIC_LIBRARY) \ No newline at end of file diff --git a/flake.nix b/flake.nix index c5fac6b8..9067678c 100644 --- a/flake.nix +++ b/flake.nix @@ -13,11 +13,11 @@ let pkgs = nixpkgs.legacyPackages.${system}; chia-relic = relic.defaultPackage.${system}; bls = bls-signatures.defaultPackage.${system}; - deps = with pkgs; [ cmake gmp gmp.dev libsodium chia-relic bls-signatures ]; + deps = with pkgs; [ cmake gmp gmp.dev libsodium chia-relic bls ]; platform_deps = if(pkgs.lib.strings.hasSuffix "linux" system) then [ pkgs.numactl ] else []; in rec { devShells.default = pkgs.mkShell { - packages = deps; + packages = deps ++ platform_deps; }; defaultPackage = with pkgs; stdenv.mkDerivation { pname = "bladebit"; @@ -25,7 +25,8 @@ src = self; - nativeBuildInputs = [ cmake gmp gmp.dev libsodium chia-relic bls ] ++ platform_deps; + nativeBuildInputs = platform_deps; + buildInputs = deps; buildPhase = '' cmake . -DBUILD_BLADEBIT_TESTS=false @@ -40,7 +41,6 @@ enableParallelBuilding = true; cmakeFlags = [ - "-DBUILD_BLADEBIT_TESTS=false" "-DBUILD_LOCAL=true" ]; }; From f8d5544a799f9b723ba575fc9b291233803d9720 Mon Sep 17 00:00:00 2001 From: Andrea Bueide Date: Sat, 3 Sep 2022 23:49:21 -0500 Subject: [PATCH 3/6] Remove flake --- CMakeLists.txt | 12 ++- flake.lock | 195 ------------------------------------------------- flake.nix | 3 +- 3 files changed, 10 insertions(+), 200 deletions(-) delete mode 100644 flake.lock diff --git a/CMakeLists.txt b/CMakeLists.txt index 59c2fd88..0772c37b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,7 @@ set(CMAKE_MODULE_PATH ) set(BUILD_LOCAL "0" CACHE STRING "") +set(BUILD_BLADEBIT_TESTS "1" CACHE STRING "") # # Grab Dependencies @@ -52,7 +53,7 @@ set(BUILD_BLS_TESTS "0" CACHE STRING "") set(BUILD_BLS_BENCHMARKS "0" CACHE STRING "") FetchContent_MakeAvailable(bls) else() - find_package(bls REQUIRED) + find_package(BLS REQUIRED) find_package(relic REQUIRED) endif() @@ -66,10 +67,11 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") endif() # Catch -# TODO: Add configuration var to disable this +if(BUILD_BLADEBIT_TESTS) include(cmake_modules/FindCatch2.cmake) set_target_properties(Catch2 PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") set_target_properties(Catch2WithMain PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") +endif() # Config @@ -393,8 +395,8 @@ set_target_properties(lib_bladebit PROPERTIES OUTPUT_NAME bladebit MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>" ) -target_link_libraries(lib_bladebit PUBLIC Threads::Threads bls ${platform_libs}) -target_include_directories(lib_bladebit PUBLIC ${bb_include_dirs} ${BLS_INCLUDE_DIR}) +target_link_libraries(lib_bladebit PUBLIC Threads::Threads ${RELIC_LIBRARY} ${BLS_LIBRARY} ${platform_libs}) +target_include_directories(lib_bladebit PUBLIC ${bb_include_dirs} ${RELIC_INCLUDE_DIR} ${BLS_INCLUDE_DIR}) target_compile_options(lib_bladebit PUBLIC $<$:${c_opts} ${release_c_opts}>) target_compile_options(lib_bladebit PUBLIC $<$:${c_opts} ${debug_c_opts}>) @@ -421,11 +423,13 @@ target_link_libraries(fsegen PRIVATE lib_bladebit) # target_link_libraries(plot_tool PRIVATE lib_bladebit) # Tests +if(BUILD_BLADEBIT_TESTS) add_executable(tests ${src_tests} ${bb_headers}) target_compile_options(tests PUBLIC $<$:${c_opts} ${release_c_opts} ${tests_c_opts}>) target_compile_options(tests PUBLIC $<$:${c_opts} ${debug_c_opts} ${tests_c_opts}>) set_target_properties(tests PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") target_link_libraries(tests PRIVATE lib_bladebit Catch2::Catch2WithMain) +endif() # Pretty source view for IDE projects source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/src diff --git a/flake.lock b/flake.lock deleted file mode 100644 index 9241cad8..00000000 --- a/flake.lock +++ /dev/null @@ -1,195 +0,0 @@ -{ - "nodes": { - "bls-signatures": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs", - "relic": "relic" - }, - "locked": { - "lastModified": 1662244740, - "narHash": "sha256-Z7wMgzljIoVHqY/DVniL7CUtYi/2am5y6rRiK3LCKZU=", - "owner": "abueide", - "repo": "bls-signatures", - "rev": "2c412f8b0a95adb1548973864fb282b43051b5b8", - "type": "github" - }, - "original": { - "owner": "abueide", - "ref": "flake", - "repo": "bls-signatures", - "type": "github" - } - }, - "flake-utils": { - "locked": { - "lastModified": 1659877975, - "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_2": { - "locked": { - "lastModified": 1659877975, - "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_3": { - "locked": { - "lastModified": 1659877975, - "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_4": { - "locked": { - "lastModified": 1659877975, - "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1662252173, - "narHash": "sha256-fEyM+K/N4srfUNdf9O5yoncyFS8nuUe4TkjgX5LGU4I=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "65bb4b6d3f13ba962541d7ae27a13f42ca673658", - "type": "github" - }, - "original": { - "owner": "nixos", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_2": { - "locked": { - "lastModified": 1662158175, - "narHash": "sha256-tFdRHPacHDEuiAFusNe/ZSkPvtSiPouDu6PYQpizIJc=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "96ff5b58ec922f626d039406914ae4b5caef530f", - "type": "github" - }, - "original": { - "owner": "nixos", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_3": { - "locked": { - "lastModified": 1662252173, - "narHash": "sha256-fEyM+K/N4srfUNdf9O5yoncyFS8nuUe4TkjgX5LGU4I=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "65bb4b6d3f13ba962541d7ae27a13f42ca673658", - "type": "github" - }, - "original": { - "owner": "nixos", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_4": { - "locked": { - "lastModified": 1662158175, - "narHash": "sha256-tFdRHPacHDEuiAFusNe/ZSkPvtSiPouDu6PYQpizIJc=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "96ff5b58ec922f626d039406914ae4b5caef530f", - "type": "github" - }, - "original": { - "owner": "nixos", - "repo": "nixpkgs", - "type": "github" - } - }, - "relic": { - "inputs": { - "flake-utils": "flake-utils_2", - "nixpkgs": "nixpkgs_2" - }, - "locked": { - "lastModified": 1662240382, - "narHash": "sha256-NveG1oOnl1j01eamwcwQ8StjCOOmY0j4M+4QqgjjFW4=", - "owner": "abueide", - "repo": "relic", - "rev": "3a455a4d5f8233951d11e819786e6b2d7eb20ae4", - "type": "github" - }, - "original": { - "owner": "abueide", - "ref": "flake", - "repo": "relic", - "type": "github" - } - }, - "relic_2": { - "inputs": { - "flake-utils": "flake-utils_4", - "nixpkgs": "nixpkgs_4" - }, - "locked": { - "lastModified": 1662240382, - "narHash": "sha256-NveG1oOnl1j01eamwcwQ8StjCOOmY0j4M+4QqgjjFW4=", - "owner": "abueide", - "repo": "relic", - "rev": "3a455a4d5f8233951d11e819786e6b2d7eb20ae4", - "type": "github" - }, - "original": { - "owner": "abueide", - "ref": "flake", - "repo": "relic", - "type": "github" - } - }, - "root": { - "inputs": { - "bls-signatures": "bls-signatures", - "flake-utils": "flake-utils_3", - "nixpkgs": "nixpkgs_3", - "relic": "relic_2" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/flake.nix b/flake.nix index 9067678c..68984e70 100644 --- a/flake.nix +++ b/flake.nix @@ -29,7 +29,7 @@ buildInputs = deps; buildPhase = '' - cmake . -DBUILD_BLADEBIT_TESTS=false + cmake . cmake --build . --target bladebit --config Release ''; @@ -42,6 +42,7 @@ enableParallelBuilding = true; cmakeFlags = [ "-DBUILD_LOCAL=true" + "-DBUILD_BLADEBIT_TESTS=false" ]; }; } From 52b3a0432badd1b705c137e76ade0c823288d53b Mon Sep 17 00:00:00 2001 From: Andrea Bueide Date: Sun, 4 Sep 2022 00:19:09 -0500 Subject: [PATCH 4/6] working bladebit --- .gitignore | 1 + CMakeLists.txt | 6 +- .../{FindBLS.cmake => Findbls.cmake} | 0 cmake_modules/Findgmp.cmake | 87 ++++++ .../{FindRelic.cmake => Findrelic.cmake} | 0 cmake_modules/Findsodium.cmake | 294 ++++++++++++++++++ flake.lock | 195 ++++++++++++ flake.nix | 2 +- 8 files changed, 582 insertions(+), 3 deletions(-) rename cmake_modules/{FindBLS.cmake => Findbls.cmake} (100%) create mode 100644 cmake_modules/Findgmp.cmake rename cmake_modules/{FindRelic.cmake => Findrelic.cmake} (100%) create mode 100644 cmake_modules/Findsodium.cmake create mode 100644 flake.lock diff --git a/.gitignore b/.gitignore index 174ff163..e882548a 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ cmake-build*/ .idea/ cmake-build-debug/ +result diff --git a/CMakeLists.txt b/CMakeLists.txt index 0772c37b..3dc5ad86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,8 +53,10 @@ set(BUILD_BLS_TESTS "0" CACHE STRING "") set(BUILD_BLS_BENCHMARKS "0" CACHE STRING "") FetchContent_MakeAvailable(bls) else() - find_package(BLS REQUIRED) + find_package(sodium REQUIRED) + find_package(gmp REQUIRED) find_package(relic REQUIRED) + find_package(bls REQUIRED) endif() # Threads @@ -395,7 +397,7 @@ set_target_properties(lib_bladebit PROPERTIES OUTPUT_NAME bladebit MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>" ) -target_link_libraries(lib_bladebit PUBLIC Threads::Threads ${RELIC_LIBRARY} ${BLS_LIBRARY} ${platform_libs}) +target_link_libraries(lib_bladebit PUBLIC Threads::Threads ${GMP_LIBRARIES} ${sodium_LIBRARY_RELEASE} ${BLS_LIBRARY} ${RELIC_LIBRARY} ${platform_libs}) target_include_directories(lib_bladebit PUBLIC ${bb_include_dirs} ${RELIC_INCLUDE_DIR} ${BLS_INCLUDE_DIR}) target_compile_options(lib_bladebit PUBLIC $<$:${c_opts} ${release_c_opts}>) diff --git a/cmake_modules/FindBLS.cmake b/cmake_modules/Findbls.cmake similarity index 100% rename from cmake_modules/FindBLS.cmake rename to cmake_modules/Findbls.cmake diff --git a/cmake_modules/Findgmp.cmake b/cmake_modules/Findgmp.cmake new file mode 100644 index 00000000..16f1f8b4 --- /dev/null +++ b/cmake_modules/Findgmp.cmake @@ -0,0 +1,87 @@ +# Try to find the GMP library +# https://gmplib.org/ +# +# This module supports requiring a minimum version, e.g. you can do +# find_package(GMP 6.0.0) +# to require version 6.0.0 to newer of GMP. +# +# Once done this will define +# +# GMP_FOUND - system has GMP lib with correct version +# GMP_INCLUDES - the GMP include directory +# GMP_LIBRARIES - the GMP library +# GMP_VERSION - GMP version +# +# Copyright (c) 2016 Jack Poulson, +# Redistribution and use is allowed according to the terms of the BSD license. + +find_path(GMP_INCLUDES NAMES gmp.h PATHS $ENV{GMPDIR} ${INCLUDE_INSTALL_DIR}) + +# Set GMP_FIND_VERSION to 5.1.0 if no minimum version is specified +if(NOT GMP_FIND_VERSION) + if(NOT GMP_FIND_VERSION_MAJOR) + set(GMP_FIND_VERSION_MAJOR 5) + endif() + if(NOT GMP_FIND_VERSION_MINOR) + set(GMP_FIND_VERSION_MINOR 1) + endif() + if(NOT GMP_FIND_VERSION_PATCH) + set(GMP_FIND_VERSION_PATCH 0) + endif() + set(GMP_FIND_VERSION + "${GMP_FIND_VERSION_MAJOR}.${GMP_FIND_VERSION_MINOR}.${GMP_FIND_VERSION_PATCH}") +endif() + +message("GMP_INCLUDES=${GMP_INCLUDES}") +if(GMP_INCLUDES) + # Since the GMP version macros may be in a file included by gmp.h of the form + # gmp-.*[_]?.*.h (e.g., gmp-x86_64.h), we search each of them. + file(GLOB GMP_HEADERS "${GMP_INCLUDES}/gmp.h" "${GMP_INCLUDES}/gmp-*.h") + foreach(gmp_header_filename ${GMP_HEADERS}) + file(READ "${gmp_header_filename}" _gmp_version_header) + string(REGEX MATCH + "define[ \t]+__GNU_MP_VERSION[ \t]+([0-9]+)" _gmp_major_version_match + "${_gmp_version_header}") + if(_gmp_major_version_match) + set(GMP_MAJOR_VERSION "${CMAKE_MATCH_1}") + string(REGEX MATCH "define[ \t]+__GNU_MP_VERSION_MINOR[ \t]+([0-9]+)" + _gmp_minor_version_match "${_gmp_version_header}") + set(GMP_MINOR_VERSION "${CMAKE_MATCH_1}") + string(REGEX MATCH "define[ \t]+__GNU_MP_VERSION_PATCHLEVEL[ \t]+([0-9]+)" + _gmp_patchlevel_version_match "${_gmp_version_header}") + set(GMP_PATCHLEVEL_VERSION "${CMAKE_MATCH_1}") + set(GMP_VERSION + ${GMP_MAJOR_VERSION}.${GMP_MINOR_VERSION}.${GMP_PATCHLEVEL_VERSION}) + endif() + endforeach() + + # Check whether found version exists and exceeds the minimum requirement + if(NOT GMP_VERSION) + set(GMP_VERSION_OK FALSE) + message(STATUS "GMP version was not detected") + elseif(${GMP_VERSION} VERSION_LESS ${GMP_FIND_VERSION}) + set(GMP_VERSION_OK FALSE) + message(STATUS "GMP version ${GMP_VERSION} found in ${GMP_INCLUDES}, " + "but at least version ${GMP_FIND_VERSION} is required") + else() + set(GMP_VERSION_OK TRUE) + endif() +endif() + +if(STBIN) + set(_gmp_lib_name libgmp.a) +else() + set(_gmp_lib_name libgmp.so) +endif() + +find_library(GMP_LIBRARIES + NAMES + ${_gmp_lib_name} gmp.lib libgmp-10 libgmp gmp + PATHS + $ENV{GMPDIR} ${LIB_INSTALL_DIR} +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(gmp DEFAULT_MSG + GMP_INCLUDES GMP_LIBRARIES GMP_VERSION_OK) +mark_as_advanced(GMP_INCLUDES GMP_LIBRARIES) diff --git a/cmake_modules/FindRelic.cmake b/cmake_modules/Findrelic.cmake similarity index 100% rename from cmake_modules/FindRelic.cmake rename to cmake_modules/Findrelic.cmake diff --git a/cmake_modules/Findsodium.cmake b/cmake_modules/Findsodium.cmake new file mode 100644 index 00000000..0350b67f --- /dev/null +++ b/cmake_modules/Findsodium.cmake @@ -0,0 +1,294 @@ +# Written in 2016 by Henrik Steffen Gaßmann +# +# To the extent possible under law, the author(s) have dedicated all +# copyright and related and neighboring rights to this software to the +# public domain worldwide. This software is distributed without any warranty. +# +# You should have received a copy of the CC0 Public Domain Dedication +# along with this software. If not, see +# +# http://creativecommons.org/publicdomain/zero/1.0/ +# +######################################################################## +# Tries to find the local libsodium installation. +# +# On Windows the sodium_DIR environment variable is used as a default +# hint which can be overridden by setting the corresponding cmake variable. +# +# Once done the following variables will be defined: +# +# sodium_FOUND +# sodium_INCLUDE_DIR +# sodium_LIBRARY_DEBUG +# sodium_LIBRARY_RELEASE +# +# +# Furthermore an imported "sodium" target is created. +# + +if (CMAKE_C_COMPILER_ID STREQUAL "GNU" + OR CMAKE_C_COMPILER_ID STREQUAL "Clang") + set(_GCC_COMPATIBLE 1) +endif() + +# static library option +if (NOT DEFINED sodium_USE_STATIC_LIBS) + option(sodium_USE_STATIC_LIBS "enable to statically link against sodium" OFF) +endif() +if(NOT (sodium_USE_STATIC_LIBS EQUAL sodium_USE_STATIC_LIBS_LAST)) + unset(sodium_LIBRARY CACHE) + unset(sodium_LIBRARY_DEBUG CACHE) + unset(sodium_LIBRARY_RELEASE CACHE) + unset(sodium_DLL_DEBUG CACHE) + unset(sodium_DLL_RELEASE CACHE) + set(sodium_USE_STATIC_LIBS_LAST ${sodium_USE_STATIC_LIBS} CACHE INTERNAL "internal change tracking variable") +endif() + + +######################################################################## +# UNIX +if (UNIX) + # import pkg-config + find_package(PkgConfig QUIET) + if (PKG_CONFIG_FOUND) + pkg_check_modules(sodium_PKG QUIET libsodium) + endif() + + if(sodium_USE_STATIC_LIBS) + foreach(_libname ${sodium_PKG_STATIC_LIBRARIES}) + if (NOT _libname MATCHES "^lib.*\\.a$") # ignore strings already ending with .a + list(INSERT sodium_PKG_STATIC_LIBRARIES 0 "lib${_libname}.a") + endif() + endforeach() + list(REMOVE_DUPLICATES sodium_PKG_STATIC_LIBRARIES) + + # if pkgconfig for libsodium doesn't provide + # static lib info, then override PKG_STATIC here.. + if (NOT sodium_PKG_STATIC_FOUND) + set(sodium_PKG_STATIC_LIBRARIES libsodium.a) + endif() + + set(XPREFIX sodium_PKG_STATIC) + else() + if (NOT sodium_PKG_FOUND) + set(sodium_PKG_LIBRARIES sodium) + endif() + + set(XPREFIX sodium_PKG) + endif() + + find_path(sodium_INCLUDE_DIR sodium.h + HINTS ${${XPREFIX}_INCLUDE_DIRS} + ) + find_library(sodium_LIBRARY_DEBUG NAMES ${${XPREFIX}_LIBRARIES} + HINTS ${${XPREFIX}_LIBRARY_DIRS} + ) + find_library(sodium_LIBRARY_RELEASE NAMES ${${XPREFIX}_LIBRARIES} + HINTS ${${XPREFIX}_LIBRARY_DIRS} + ) + + +######################################################################## +# Windows +elseif (WIN32) + set(sodium_DIR "$ENV{sodium_DIR}" CACHE FILEPATH "sodium install directory") + mark_as_advanced(sodium_DIR) + + find_path(sodium_INCLUDE_DIR sodium.h + HINTS ${sodium_DIR} + PATH_SUFFIXES include + ) + + if (MSVC) + # detect target architecture + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/arch.cpp" [=[ + #if defined _M_IX86 + #error ARCH_VALUE x86_32 + #elif defined _M_X64 + #error ARCH_VALUE x86_64 + #endif + #error ARCH_VALUE unknown + ]=]) + try_compile(_UNUSED_VAR "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/arch.cpp" + OUTPUT_VARIABLE _COMPILATION_LOG + ) + string(REGEX REPLACE ".*ARCH_VALUE ([a-zA-Z0-9_]+).*" "\\1" _TARGET_ARCH "${_COMPILATION_LOG}") + + # construct library path + if (_TARGET_ARCH STREQUAL "x86_32") + string(APPEND _PLATFORM_PATH "Win32") + elseif(_TARGET_ARCH STREQUAL "x86_64") + string(APPEND _PLATFORM_PATH "x64") + else() + message(FATAL_ERROR "the ${_TARGET_ARCH} architecture is not supported by Findsodium.cmake.") + endif() + string(APPEND _PLATFORM_PATH "/$$CONFIG$$") + + if (MSVC_VERSION LESS 1900) + math(EXPR _VS_VERSION "${MSVC_VERSION} / 10 - 60") + else() + math(EXPR _VS_VERSION "${MSVC_VERSION} / 10 - 50") + endif() + string(APPEND _PLATFORM_PATH "/v${_VS_VERSION}") + + if (sodium_USE_STATIC_LIBS) + string(APPEND _PLATFORM_PATH "/static") + else() + string(APPEND _PLATFORM_PATH "/dynamic") + endif() + + string(REPLACE "$$CONFIG$$" "Debug" _DEBUG_PATH_SUFFIX "${_PLATFORM_PATH}") + string(REPLACE "$$CONFIG$$" "Release" _RELEASE_PATH_SUFFIX "${_PLATFORM_PATH}") + + find_library(sodium_LIBRARY_DEBUG libsodium.lib + HINTS ${sodium_DIR} + PATH_SUFFIXES ${_DEBUG_PATH_SUFFIX} + ) + find_library(sodium_LIBRARY_RELEASE libsodium.lib + HINTS ${sodium_DIR} + PATH_SUFFIXES ${_RELEASE_PATH_SUFFIX} + ) + if (NOT sodium_USE_STATIC_LIBS) + set(CMAKE_FIND_LIBRARY_SUFFIXES_BCK ${CMAKE_FIND_LIBRARY_SUFFIXES}) + set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll") + find_library(sodium_DLL_DEBUG libsodium + HINTS ${sodium_DIR} + PATH_SUFFIXES ${_DEBUG_PATH_SUFFIX} + ) + find_library(sodium_DLL_RELEASE libsodium + HINTS ${sodium_DIR} + PATH_SUFFIXES ${_RELEASE_PATH_SUFFIX} + ) + set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_BCK}) + endif() + + elseif(_GCC_COMPATIBLE) + if (sodium_USE_STATIC_LIBS) + find_library(sodium_LIBRARY_DEBUG libsodium.a + HINTS ${sodium_DIR} + PATH_SUFFIXES lib + ) + find_library(sodium_LIBRARY_RELEASE libsodium.a + HINTS ${sodium_DIR} + PATH_SUFFIXES lib + ) + else() + find_library(sodium_LIBRARY_DEBUG libsodium.dll.a + HINTS ${sodium_DIR} + PATH_SUFFIXES lib + ) + find_library(sodium_LIBRARY_RELEASE libsodium.dll.a + HINTS ${sodium_DIR} + PATH_SUFFIXES lib + ) + + file(GLOB _DLL + LIST_DIRECTORIES false + RELATIVE "${sodium_DIR}/bin" + "${sodium_DIR}/bin/libsodium*.dll" + ) + find_library(sodium_DLL_DEBUG ${_DLL} libsodium + HINTS ${sodium_DIR} + PATH_SUFFIXES bin + ) + find_library(sodium_DLL_RELEASE ${_DLL} libsodium + HINTS ${sodium_DIR} + PATH_SUFFIXES bin + ) + endif() + else() + message(FATAL_ERROR "this platform is not supported by FindSodium.cmake") + endif() + + +######################################################################## +# unsupported +else() + message(FATAL_ERROR "this platform is not supported by FindSodium.cmake") +endif() + + +######################################################################## +# common stuff + +# extract sodium version +if (sodium_INCLUDE_DIR) + set(_VERSION_HEADER "${_INCLUDE_DIR}/sodium/version.h") + if (EXISTS _VERSION_HEADER) + file(READ "${_VERSION_HEADER}" _VERSION_HEADER_CONTENT) + string(REGEX REPLACE ".*#[ \t]*define[ \t]*SODIUM_VERSION_STRING[ \t]*\"([^\n]*)\".*" "\\1" + sodium_VERSION "${_VERSION_HEADER_CONTENT}") + set(sodium_VERSION "${sodium_VERSION}" PARENT_SCOPE) + endif() +endif() + +# communicate results +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + sodium # The name must be either uppercase or match the filename case. + REQUIRED_VARS + sodium_LIBRARY_RELEASE + sodium_LIBRARY_DEBUG + sodium_INCLUDE_DIR + VERSION_VAR + sodium_VERSION +) + +if(Sodium_FOUND) + set(sodium_LIBRARIES + optimized ${sodium_LIBRARY_RELEASE} debug ${sodium_LIBRARY_DEBUG}) +endif() + +# mark file paths as advanced +mark_as_advanced(sodium_INCLUDE_DIR) +mark_as_advanced(sodium_LIBRARY_DEBUG) +mark_as_advanced(sodium_LIBRARY_RELEASE) +if (WIN32) + mark_as_advanced(sodium_DLL_DEBUG) + mark_as_advanced(sodium_DLL_RELEASE) +endif() + +# create imported target +if(sodium_USE_STATIC_LIBS) + set(_LIB_TYPE STATIC) +else() + set(_LIB_TYPE SHARED) +endif() +add_library(sodium ${_LIB_TYPE} IMPORTED) + +set_target_properties(sodium PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${sodium_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C" +) + +if (sodium_USE_STATIC_LIBS) + set_target_properties(sodium PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "SODIUM_STATIC" + IMPORTED_LOCATION "${sodium_LIBRARY_RELEASE}" + IMPORTED_LOCATION_DEBUG "${sodium_LIBRARY_DEBUG}" + ) +else() + if (UNIX) + set_target_properties(sodium PROPERTIES + IMPORTED_LOCATION "${sodium_LIBRARY_RELEASE}" + IMPORTED_LOCATION_DEBUG "${sodium_LIBRARY_DEBUG}" + ) + elseif (WIN32) + set_target_properties(sodium PROPERTIES + IMPORTED_IMPLIB "${sodium_LIBRARY_RELEASE}" + IMPORTED_IMPLIB_DEBUG "${sodium_LIBRARY_DEBUG}" + ) + if (NOT (sodium_DLL_DEBUG MATCHES ".*-NOTFOUND")) + set_target_properties(sodium PROPERTIES + IMPORTED_LOCATION_DEBUG "${sodium_DLL_DEBUG}" + ) + endif() + if (NOT (sodium_DLL_RELEASE MATCHES ".*-NOTFOUND")) + set_target_properties(sodium PROPERTIES + IMPORTED_LOCATION_RELWITHDEBINFO "${sodium_DLL_RELEASE}" + IMPORTED_LOCATION_MINSIZEREL "${sodium_DLL_RELEASE}" + IMPORTED_LOCATION_RELEASE "${sodium_DLL_RELEASE}" + ) + endif() + endif() +endif() diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..82b9c402 --- /dev/null +++ b/flake.lock @@ -0,0 +1,195 @@ +{ + "nodes": { + "bls-signatures": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "relic": "relic" + }, + "locked": { + "lastModified": 1662266670, + "narHash": "sha256-yVISHmuP0zFteWx++V3ZeoqCF54CkgW89PG+4bfQ1VE=", + "owner": "abueide", + "repo": "bls-signatures", + "rev": "3dad11fb4289b861d683988c2b2c430fd48a3799", + "type": "github" + }, + "original": { + "owner": "abueide", + "ref": "flake", + "repo": "bls-signatures", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_3": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_4": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1662257973, + "narHash": "sha256-9VbyuNk1vvUQ2e0tIeL5kvBQ1lqudCTi/Ugp9hLztJg=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "187f55926cca9f3c3b73e5c11f98b010cbf6f884", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1662158175, + "narHash": "sha256-tFdRHPacHDEuiAFusNe/ZSkPvtSiPouDu6PYQpizIJc=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "96ff5b58ec922f626d039406914ae4b5caef530f", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1662257973, + "narHash": "sha256-9VbyuNk1vvUQ2e0tIeL5kvBQ1lqudCTi/Ugp9hLztJg=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "187f55926cca9f3c3b73e5c11f98b010cbf6f884", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_4": { + "locked": { + "lastModified": 1662158175, + "narHash": "sha256-tFdRHPacHDEuiAFusNe/ZSkPvtSiPouDu6PYQpizIJc=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "96ff5b58ec922f626d039406914ae4b5caef530f", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "type": "github" + } + }, + "relic": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1662240382, + "narHash": "sha256-NveG1oOnl1j01eamwcwQ8StjCOOmY0j4M+4QqgjjFW4=", + "owner": "abueide", + "repo": "relic", + "rev": "3a455a4d5f8233951d11e819786e6b2d7eb20ae4", + "type": "github" + }, + "original": { + "owner": "abueide", + "ref": "flake", + "repo": "relic", + "type": "github" + } + }, + "relic_2": { + "inputs": { + "flake-utils": "flake-utils_4", + "nixpkgs": "nixpkgs_4" + }, + "locked": { + "lastModified": 1662240382, + "narHash": "sha256-NveG1oOnl1j01eamwcwQ8StjCOOmY0j4M+4QqgjjFW4=", + "owner": "abueide", + "repo": "relic", + "rev": "3a455a4d5f8233951d11e819786e6b2d7eb20ae4", + "type": "github" + }, + "original": { + "owner": "abueide", + "ref": "flake", + "repo": "relic", + "type": "github" + } + }, + "root": { + "inputs": { + "bls-signatures": "bls-signatures", + "flake-utils": "flake-utils_3", + "nixpkgs": "nixpkgs_3", + "relic": "relic_2" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix index 68984e70..36eee32e 100644 --- a/flake.nix +++ b/flake.nix @@ -30,7 +30,7 @@ buildPhase = '' cmake . - cmake --build . --target bladebit --config Release + cmake --build . --target bladebit --config Release -j10 ''; installPhase = '' From 53ead78ea7961046e9f60a364b0eaf2b4241d7ce Mon Sep 17 00:00:00 2001 From: Andrea Bueide Date: Sun, 4 Sep 2022 00:26:47 -0500 Subject: [PATCH 5/6] Working flake --- CMakeLists.txt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3dc5ad86..0e846767 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -397,8 +397,14 @@ set_target_properties(lib_bladebit PROPERTIES OUTPUT_NAME bladebit MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>" ) -target_link_libraries(lib_bladebit PUBLIC Threads::Threads ${GMP_LIBRARIES} ${sodium_LIBRARY_RELEASE} ${BLS_LIBRARY} ${RELIC_LIBRARY} ${platform_libs}) -target_include_directories(lib_bladebit PUBLIC ${bb_include_dirs} ${RELIC_INCLUDE_DIR} ${BLS_INCLUDE_DIR}) +if(BUILD_LOCAL) + target_link_libraries(lib_bladebit PUBLIC Threads::Threads ${GMP_LIBRARIES} ${sodium_LIBRARY_RELEASE} ${BLS_LIBRARY} ${RELIC_LIBRARY} ${platform_libs}) + target_include_directories(lib_bladebit PUBLIC ${bb_include_dirs} ${RELIC_INCLUDE_DIR} ${BLS_INCLUDE_DIR}) +else() + target_link_libraries(lib_bladebit PUBLIC Threads::Threads bls ${platform_libs}) + target_include_directories(lib_bladebit PUBLIC ${bb_include_dirs}) +endif() + target_compile_options(lib_bladebit PUBLIC $<$:${c_opts} ${release_c_opts}>) target_compile_options(lib_bladebit PUBLIC $<$:${c_opts} ${debug_c_opts}>) From ad372eb71723cb386488e45cf3aeccecc5c3d62f Mon Sep 17 00:00:00 2001 From: Andrea Bueide Date: Sun, 4 Sep 2022 00:49:17 -0500 Subject: [PATCH 6/6] Switch to chia-network libs --- flake.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 36eee32e..aac100f7 100644 --- a/flake.nix +++ b/flake.nix @@ -4,8 +4,8 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs"; flake-utils.url = "github:numtide/flake-utils"; - relic.url = "github:abueide/relic/flake"; - bls-signatures.url = "github:abueide/bls-signatures/flake"; + relic.url = "github:Chia-Network/relic"; + bls-signatures.url = "github:Chia-Network/bls-signatures"; }; outputs = { self, nixpkgs, flake-utils, relic, bls-signatures }: @@ -30,7 +30,7 @@ buildPhase = '' cmake . - cmake --build . --target bladebit --config Release -j10 + cmake --build . --target bladebit --config Release -j ''; installPhase = ''