Skip to content

Commit

Permalink
CI: use GMP from Conan on Windows too (erigontech#1184)
Browse files Browse the repository at this point in the history
  • Loading branch information
battlmonstr authored May 29, 2023
1 parent 540a91d commit e5c3f67
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 55 deletions.
18 changes: 1 addition & 17 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <VCPKG_ROOT>\installed\x64-windows\include to your `INCLUDE` environment variable.
* Add <VCPKG_ROOT>\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)
Expand Down
55 changes: 22 additions & 33 deletions third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@

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()
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)

Expand Down Expand Up @@ -69,39 +90,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)
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
Expand All @@ -125,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)
Expand Down

0 comments on commit e5c3f67

Please sign in to comment.