From 392b9323e2a2b7ace95b80a6f049d50aace6aaef Mon Sep 17 00:00:00 2001 From: battlmonstr Date: Fri, 26 May 2023 13:33:51 +0200 Subject: [PATCH 1/4] fix gmp setup --- third_party/CMakeLists.txt | 67 +++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index 2b6cd2a7bd..94853280cb 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -16,6 +16,42 @@ include(ExternalProject) +# GMP +# declaring it first to be used by intx, libff +if(DEFINED GMP_LIBRARY) + add_library(gmplib STATIC IMPORTED) + set_target_properties(gmplib PROPERTIES IMPORTED_LOCATION "${GMP_LIBRARY}") + if(DEFINED GMP_INCLUDE_DIR) + set_target_properties(gmplib PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${GMP_INCLUDE_DIR}") + else() + message(FATAL_ERROR "GMP_INCLUDE_DIR is required if a custom GMP_LIBRARY is provided") + endif() +elseif(MSVC) + find_path(GMP_INCLUDE_DIR NAMES gmp.h) + find_library(GMP_LIBRARY mpir) + if(GMP_LIBRARY MATCHES ${CMAKE_SHARED_LIBRARY_SUFFIX}) + set(gmp_library_type SHARED) + else() + set(gmp_library_type STATIC) + endif() + message(STATUS "GMP: ${GMP_LIBRARY}, ${GMP_INCLUDE_DIR}") + add_library(gmplib ${gmp_library_type} IMPORTED) + set_target_properties( + gmplib PROPERTIES + IMPORTED_LOCATION ${GMP_LIBRARY} + INTERFACE_INCLUDE_DIRECTORIES ${GMP_INCLUDE_DIR} + ) +else() + find_package(gmp REQUIRED) + add_custom_target(gmplib DEPENDS gmp::GMP) + + # derive the path variables from the package for intx, libff + get_target_property(GMP_INCLUDE_DIR gmp::GMP INTERFACE_INCLUDE_DIRECTORIES) + set(GMP_INCLUDE_DIR "${GMP_INCLUDE_DIR}" CACHE PATH "") + get_target_property(GMP_LIBRARY_DIR gmp::GMP INTERFACE_LINK_DIRECTORIES) + find_library(GMP_LIBRARY gmp "${GMP_LIBRARY_DIR}") +endif() + # evmone with dependencies add_subdirectory(intx) @@ -69,39 +105,10 @@ else() target_compile_options(evmone PRIVATE -fno-exceptions) endif() -# GMP -if(NOT MSVC) - if(DEFINED GMP_LIBRARY) - add_library(gmplib STATIC IMPORTED) - set_target_properties(gmplib PROPERTIES IMPORTED_LOCATION "${GMP_LIBRARY}") - if(DEFINED GMP_INCLUDE_DIR) - set_target_properties(gmplib PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${GMP_INCLUDE_DIR}") - endif() - else() - find_package(gmp REQUIRED) - add_custom_target(gmplib DEPENDS gmp::gmp) - endif() -else() - find_path(GMP_INCLUDE_DIR NAMES gmp.h) - find_library(GMP_LIBRARY mpir) - if(GMP_LIBRARY MATCHES ${CMAKE_SHARED_LIBRARY_SUFFIX}) - set(gmp_library_type SHARED) - else() - set(gmp_library_type STATIC) - endif() - message(STATUS "GMP: ${GMP_LIBRARY}, ${GMP_INCLUDE_DIR}") - add_library(gmp ${gmp_library_type} IMPORTED) - set_target_properties( - gmp PROPERTIES - IMPORTED_LOCATION ${GMP_LIBRARY} - INTERFACE_INCLUDE_DIRECTORIES ${GMP_INCLUDE_DIR} - ) -endif() - # secp256k1 add_library(secp256k1 secp256k1/src/secp256k1.c) if(MSVC) - target_link_libraries(secp256k1 PRIVATE gmp) + target_link_libraries(secp256k1 PRIVATE gmplib) target_compile_definitions(secp256k1 PUBLIC USE_NUM_GMP USE_FIELD_INV_NUM USE_SCALAR_INV_NUM) target_compile_definitions(secp256k1 PUBLIC USE_FIELD_10X26 USE_SCALAR_8X32) target_compile_options(secp256k1 PRIVATE /w) # Not much we can do about warnings From 05a2351240632e3fb84e9c1b04242a626a8fcd2b Mon Sep 17 00:00:00 2001 From: battlmonstr Date: Fri, 26 May 2023 09:04:14 +0200 Subject: [PATCH 2/4] CI: use mpir from Conan on Windows --- .github/workflows/windows.yml | 18 +----------------- cmake/conan.cmake | 7 +++++++ third_party/CMakeLists.txt | 25 ++++++++++--------------- 3 files changed, 18 insertions(+), 32 deletions(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index b123d6cdc7..ce4c06382e 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -49,30 +49,14 @@ jobs: with: version: 1.59.0 - - name: Conan version - run: echo "${{ steps.conan.outputs.version }}" - - - name: vcpkg build - uses: johnwason/vcpkg-action@v4 - id: vcpkg - with: - pkgs: mpir - triplet: x64-windows - token: ${{ github.token }} - - name: Create Build Environment # Some projects don't allow in-source building, so create a separate build directory # We'll use this as our working directory for all subsequent commands run: cmake -E make_directory C:\build - - name: Add VCPKG libs to environment - run: | - Add-Content $env:GITHUB_PATH "${{runner.workspace}}\silkworm\vcpkg\installed\x64-windows\bin" - Add-Content $env:GITHUB_ENV "INCLUDE=${{runner.workspace}}\silkworm\vcpkg\installed\x64-windows\include" - - name: Configure CMake working-directory: C:\build - run: cmake ${{runner.workspace}}\silkworm + run: cmake ${{runner.workspace}}\silkworm -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} - name: Build silkworm working-directory: C:\build diff --git a/cmake/conan.cmake b/cmake/conan.cmake index ba28e7fe93..55b15ad35e 100644 --- a/cmake/conan.cmake +++ b/cmake/conan.cmake @@ -44,6 +44,13 @@ include("${CMAKE_SOURCE_DIR}/third_party/cmake-conan/conan.cmake") # provide a static conanfile.txt instead of generating it with conan_cmake_configure() file(COPY "${CMAKE_SOURCE_DIR}/conanfile.txt" DESTINATION "${CONAN_BINARY_DIR}") +# use mpir instead of gmp on Windows +if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + file(READ "${CONAN_BINARY_DIR}/conanfile.txt" conanfile_contents) + string(REPLACE "gmp/6.2.1" "mpir/3.0.0" conanfile_contents "${conanfile_contents}") + file(WRITE "${CONAN_BINARY_DIR}/conanfile.txt" "${conanfile_contents}") +endif() + if(NOT DEFINED CONAN_PROFILE) guess_conan_profile() endif() diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index 94853280cb..140cef1fc8 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -27,20 +27,15 @@ if(DEFINED GMP_LIBRARY) message(FATAL_ERROR "GMP_INCLUDE_DIR is required if a custom GMP_LIBRARY is provided") endif() elseif(MSVC) - find_path(GMP_INCLUDE_DIR NAMES gmp.h) - find_library(GMP_LIBRARY mpir) - if(GMP_LIBRARY MATCHES ${CMAKE_SHARED_LIBRARY_SUFFIX}) - set(gmp_library_type SHARED) - else() - set(gmp_library_type STATIC) - endif() - message(STATUS "GMP: ${GMP_LIBRARY}, ${GMP_INCLUDE_DIR}") - add_library(gmplib ${gmp_library_type} IMPORTED) - set_target_properties( - gmplib PROPERTIES - IMPORTED_LOCATION ${GMP_LIBRARY} - INTERFACE_INCLUDE_DIRECTORIES ${GMP_INCLUDE_DIR} - ) + find_package(mpir REQUIRED) + add_custom_target(gmplib DEPENDS mpir::mpir) + + # derive the path variables from the package for intx, libff + get_target_property(GMP_INCLUDE_DIR mpir::mpir INTERFACE_INCLUDE_DIRECTORIES) + set(GMP_INCLUDE_DIR "${GMP_INCLUDE_DIR}" CACHE PATH "") + get_target_property(GMP_LIBRARY_DIR mpir::mpir INTERFACE_LINK_DIRECTORIES) + find_library(GMP_LIBRARY gmp "${GMP_LIBRARY_DIR}") + message(FATAL_ERROR "TODO") else() find_package(gmp REQUIRED) add_custom_target(gmplib DEPENDS gmp::GMP) @@ -108,7 +103,7 @@ endif() # secp256k1 add_library(secp256k1 secp256k1/src/secp256k1.c) if(MSVC) - target_link_libraries(secp256k1 PRIVATE gmplib) + add_dependencies(secp256k1 gmplib) target_compile_definitions(secp256k1 PUBLIC USE_NUM_GMP USE_FIELD_INV_NUM USE_SCALAR_INV_NUM) target_compile_definitions(secp256k1 PUBLIC USE_FIELD_10X26 USE_SCALAR_8X32) target_compile_options(secp256k1 PRIVATE /w) # Not much we can do about warnings From d45061a447aa949455a7aa934363380493453298 Mon Sep 17 00:00:00 2001 From: battlmonstr Date: Fri, 26 May 2023 12:23:16 +0200 Subject: [PATCH 3/4] remove mpir --- cmake/conan.cmake | 7 ------- third_party/CMakeLists.txt | 13 ------------- 2 files changed, 20 deletions(-) diff --git a/cmake/conan.cmake b/cmake/conan.cmake index 55b15ad35e..ba28e7fe93 100644 --- a/cmake/conan.cmake +++ b/cmake/conan.cmake @@ -44,13 +44,6 @@ include("${CMAKE_SOURCE_DIR}/third_party/cmake-conan/conan.cmake") # provide a static conanfile.txt instead of generating it with conan_cmake_configure() file(COPY "${CMAKE_SOURCE_DIR}/conanfile.txt" DESTINATION "${CONAN_BINARY_DIR}") -# use mpir instead of gmp on Windows -if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") - file(READ "${CONAN_BINARY_DIR}/conanfile.txt" conanfile_contents) - string(REPLACE "gmp/6.2.1" "mpir/3.0.0" conanfile_contents "${conanfile_contents}") - file(WRITE "${CONAN_BINARY_DIR}/conanfile.txt" "${conanfile_contents}") -endif() - if(NOT DEFINED CONAN_PROFILE) guess_conan_profile() endif() diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index 140cef1fc8..779741ae90 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -26,16 +26,6 @@ if(DEFINED GMP_LIBRARY) else() message(FATAL_ERROR "GMP_INCLUDE_DIR is required if a custom GMP_LIBRARY is provided") endif() -elseif(MSVC) - find_package(mpir REQUIRED) - add_custom_target(gmplib DEPENDS mpir::mpir) - - # derive the path variables from the package for intx, libff - get_target_property(GMP_INCLUDE_DIR mpir::mpir INTERFACE_INCLUDE_DIRECTORIES) - set(GMP_INCLUDE_DIR "${GMP_INCLUDE_DIR}" CACHE PATH "") - get_target_property(GMP_LIBRARY_DIR mpir::mpir INTERFACE_LINK_DIRECTORIES) - find_library(GMP_LIBRARY gmp "${GMP_LIBRARY_DIR}") - message(FATAL_ERROR "TODO") else() find_package(gmp REQUIRED) add_custom_target(gmplib DEPENDS gmp::GMP) @@ -127,9 +117,6 @@ set(CURVE ) option(WITH_PROCPS "" OFF) option(IS_LIBFF_PARENT "" OFF) -if(MSVC) - option(MPIR_INSTEAD_OF_GMP "" ON) -endif() add_subdirectory(libff) if(NOT MSVC) add_dependencies(ff gmplib) From 8ec26d5e15ef54a1a37430f9e0c19e0d0ec877a4 Mon Sep 17 00:00:00 2001 From: battlmonstr Date: Fri, 26 May 2023 14:52:53 +0200 Subject: [PATCH 4/4] update readme --- README.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/README.md b/README.md index 3a16a18304..cebea174a2 100644 --- a/README.md +++ b/README.md @@ -108,11 +108,7 @@ cmd/test/ethereum **Note! Windows builds are maintained for compatibility/portability reasons. However, due to the lack of 128-bit integers support by MSVC, execution performance is inferior when compared to Linux builds.** * Install [Visual Studio] 2019. Community edition is fine. * Make sure your setup includes CMake support and Windows 10 SDK. -* Install [vcpkg](https://github.com/microsoft/vcpkg#quick-start-windows). -* `.\vcpkg\vcpkg install mpir:x64-windows` -* Add \installed\x64-windows\include to your `INCLUDE` environment variable. -* Add \installed\x64-windows\bin to your `PATH` environment variable. -* Install [Perl](https://strawberryperl.com/) (needed for OpenSSL build process) +* Install [Conan](https://conan.io) and add it to PATH. * Open Visual Studio and select File -> CMake... * Browse the folder where you have cloned this repository and select the file CMakeLists.txt * Let CMake cache generation complete (it may take several minutes)