Skip to content

Commit

Permalink
[secp256k1] Update secp256k1 from 2017 to 2022 (#25398)
Browse files Browse the repository at this point in the history
* Update secp256k1 from 2017 to 2022, that added Schnorr Signature on last year.

- Edit CMakeList.txt to target precomputed library.
- Edit libsecp256k1-config.h to undef and define VARS compilation.
- Edit portfile.cmake to download new sources from repository, commit reference 44c2452fd387f7ca604ab42d73746e7d3a44d8a2 (bitcoin-core/secp256k1)
- Edit vcpkg.json to new version portfile

* Update secp256k1 from 2017 to 2022, that added Schnorr Signature on last year

>> vcpkg x-add-version secp256k1
- Update secp256k1.json version
- Update baseline.json version

* Update ports/secp256k1/portfile.cmake

Added JonLiu1993 suggestion. Put PREFER_NINJA to secp256k1/portfile.cmake

Co-authored-by: JonLiu1993 <[email protected]>

* Update ports/secp256k1/vcpkg.json

Added JonLiu1993 suggestion. Put dependencies to secp256k1/vcpkg.json

Co-authored-by: JonLiu1993 <[email protected]>

* Update port-version, REQUIRED to "x-add-version"

>> vcpkg x-add-version secp256k1

* Update port file to secp256k1 identation

* Update vcpkg.json identation

>> vcpkg format-manifest ports/secp256k1/vcpkg.json

* Update x-add-version command

vcpkg x-add-version secp256k1

* [secp256k1 ]Update secp256k1 from 2017 to 2022

* update version

* Add license

* update version

* Update, add features

* version

* fix

* version

* clean port version

* version

Co-authored-by: JonLiu1993 <[email protected]>
Co-authored-by: Jonliu1993 <[email protected]>
Co-authored-by: JackBoosY <[email protected]>
  • Loading branch information
4 people authored Jul 15, 2022
1 parent 8b62d95 commit 1782b7e
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 55 deletions.
64 changes: 57 additions & 7 deletions ports/secp256k1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,84 @@ cmake_minimum_required(VERSION 3.8)
project(secp256k1 C)

option(INSTALL_HEADERS "Install header files" ON)
option(BUILD_TOOLS "Build tools" OFF)
option(BUILD_EXAMPLES "Build examples" OFF)

add_definitions(
-DENABLE_MODULE_ECDH
-DENABLE_MODULE_RECOVERY
-DHAVE_CONFIG_H
-DENABLE_MODULE_EXTRAKEYS
-DENABLE_MODULE_SCHNORRSIG
)

file(GLOB SOURCES src/secp256k1.c)
add_library(secp256k1 ${SOURCES})

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
target_include_directories(secp256k1 PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include;${CMAKE_CURRENT_SOURCE_DIR}/src> $<INSTALL_INTERFACE:include>)

target_include_directories(secp256k1 PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<INSTALL_INTERFACE:include>)
file(GLOB SOURCES_PRECOMP src/precomputed_ecmult.c src/precomputed_ecmult_gen.c)
add_library(secp256k1_precomputed ${SOURCES_PRECOMP})

target_include_directories(secp256k1_precomputed PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)

if (BUILD_TOOLS)
add_executable(bench src/bench.c)
target_link_libraries(bench PRIVATE secp256k1 secp256k1_precomputed)

add_executable(bench_internal src/bench_internal.c)
target_link_libraries(bench_internal PRIVATE secp256k1_precomputed)

add_executable(bench_ecmult src/bench_ecmult.c)
target_link_libraries(bench_ecmult PRIVATE secp256k1_precomputed)

install(TARGETS bench bench_internal bench_ecmult RUNTIME DESTINATION bin)
endif()

if (BUILD_EXAMPLES)
add_executable(ecdsa_example examples/ecdsa.c)
target_include_directories(ecdsa_example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(ecdsa_example PRIVATE secp256k1 secp256k1_precomputed)
if (WIN32)
target_link_libraries(ecdsa_example PRIVATE Bcrypt)
endif()

add_executable(ecdh_example examples/ecdh.c)
target_include_directories(ecdh_example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(ecdh_example PRIVATE secp256k1 secp256k1_precomputed)
if (WIN32)
target_link_libraries(ecdh_example PRIVATE Bcrypt)
endif()

add_executable(schnorr_example examples/schnorr.c)
target_include_directories(schnorr_example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(schnorr_example PRIVATE secp256k1 secp256k1_precomputed)
if (WIN32)
target_link_libraries(schnorr_example PRIVATE Bcrypt)
endif()

install(TARGETS ecdsa_example ecdh_example schnorr_example RUNTIME DESTINATION bin)
endif()

if(INSTALL_HEADERS)
file(GLOB HEADERS include/*.h)
install(FILES ${HEADERS} DESTINATION include)
endif()

install(TARGETS secp256k1 EXPORT unofficial-secp256k1-targets
install(TARGETS secp256k1 EXPORT unofficial-secp256k1-config
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
)

install(TARGETS secp256k1_precomputed EXPORT unofficial-secp256k1-config
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
)

install(
EXPORT unofficial-secp256k1-targets
FILE unofficial-secp256k1-targets.cmake
EXPORT unofficial-secp256k1-config
FILE unofficial-secp256k1-config.cmake
NAMESPACE unofficial::
DESTINATION share/unofficial-secp256k1
)
)
29 changes: 0 additions & 29 deletions ports/secp256k1/libsecp256k1-config.h

This file was deleted.

47 changes: 34 additions & 13 deletions ports/secp256k1/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,45 @@ vcpkg_check_linkage(ONLY_STATIC_LIBRARY)

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO "bitcoin-core/secp256k1"
REF "0b7024185045a49a1a6a4c5615bf31c94f63d9c4"
SHA512 54e0c446ae63105800dfaf23dc934734f196c91f275db0455e58a36926c29ecc51a13d9b1eb2e45bc86199120c3c472ec7b39086787a49ce388a4df462a870bc
REPO bitcoin-core/secp256k1
REF 3efeb9da21368c02cad58435b2ccdf6eb4b359c3
SHA512 6d792943f9277a1b4c36dad62389cb38e0b93efb570b6af6c41afdb936d10ca30d4c2e4e743fc0f113d1f9785891d1e9d1fe224d7b8abd4197a9f5febf0febd6
)

file(COPY ${CURRENT_PORT_DIR}/libsecp256k1-config.h DESTINATION ${SOURCE_PATH})
file(COPY ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt DESTINATION ${SOURCE_PATH})
file(COPY "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" DESTINATION "${SOURCE_PATH}")

vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
PREFER_NINJA
OPTIONS_DEBUG
vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
FEATURES
tools BUILD_TOOLS
examples BUILD_EXAMPLES
)

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
${FEATURE_OPTIONS}
OPTIONS_DEBUG
-DINSTALL_HEADERS=OFF
)

vcpkg_install_cmake()
vcpkg_fixup_cmake_targets(CONFIG_PATH share/unofficial-${PORT} TARGET_PATH share/unofficial-${PORT})
vcpkg_cmake_install()
vcpkg_copy_pdbs()

vcpkg_cmake_config_fixup(CONFIG_PATH "share/unofficial-${PORT}" PACKAGE_NAME unofficial-${PORT})

if (BUILD_TOOLS OR BUILD_EXAMPLES)
set(SECP256K1_TOOLS "")
if (BUILD_TOOLS)
list(APPEND SECP256K1_TOOLS bench bench_internal bench_ecmult)
endif()

if (BUILD_EXAMPLES)
list(APPEND SECP256K1_TOOLS ecdsa_example ecdh_example schnorr_example)
endif()

vcpkg_copy_tools(TOOL_NAMES ${SECP256K1_TOOLS} AUTO_CLEAN)
endif()

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")
configure_file(${CMAKE_CURRENT_LIST_DIR}/secp256k1-config.cmake ${CURRENT_PACKAGES_DIR}/share/unofficial-${PORT}/unofficial-secp256k1-config.cmake @ONLY)
file(INSTALL ${SOURCE_PATH}/COPYING DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)

file(INSTALL "${SOURCE_PATH}/COPYING" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
1 change: 0 additions & 1 deletion ports/secp256k1/secp256k1-config.cmake

This file was deleted.

24 changes: 21 additions & 3 deletions ports/secp256k1/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
{
"name": "secp256k1",
"version-string": "2017-19-10",
"port-version": 4,
"version-date": "2022-07-11",
"description": "Optimized C library for EC operations on curve",
"homepage": "https://github.com/bitcoin-core/secp256k1"
"homepage": "https://github.com/bitcoin-core/secp256k1",
"license": "MIT",
"dependencies": [
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
}
],
"features": {
"examples": {
"description": "Build examples"
},
"tools": {
"description": "Build tools"
}
}
}
4 changes: 2 additions & 2 deletions versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -6505,8 +6505,8 @@
"port-version": 3
},
"secp256k1": {
"baseline": "2017-19-10",
"port-version": 4
"baseline": "2022-07-11",
"port-version": 0
},
"selene": {
"baseline": "0.3.1",
Expand Down
5 changes: 5 additions & 0 deletions versions/s-/secp256k1.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "31de2b5d2286595ff7771a30dee3c68d04e78082",
"version-date": "2022-07-11",
"port-version": 0
},
{
"git-tree": "a0ba39af9284d60d41166c4f546975e9f2b2d9df",
"version-string": "2017-19-10",
Expand Down

0 comments on commit 1782b7e

Please sign in to comment.