Skip to content

Commit 1782b7e

Browse files
R0g3r10LL31t3JonLiu1993JackBoosY
authored
[secp256k1] Update secp256k1 from 2017 to 2022 (#25398)
* 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]>
1 parent 8b62d95 commit 1782b7e

7 files changed

+119
-55
lines changed

ports/secp256k1/CMakeLists.txt

+57-7
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,84 @@ cmake_minimum_required(VERSION 3.8)
22
project(secp256k1 C)
33

44
option(INSTALL_HEADERS "Install header files" ON)
5+
option(BUILD_TOOLS "Build tools" OFF)
6+
option(BUILD_EXAMPLES "Build examples" OFF)
57

68
add_definitions(
79
-DENABLE_MODULE_ECDH
810
-DENABLE_MODULE_RECOVERY
9-
-DHAVE_CONFIG_H
11+
-DENABLE_MODULE_EXTRAKEYS
12+
-DENABLE_MODULE_SCHNORRSIG
1013
)
1114

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

15-
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
18+
target_include_directories(secp256k1 PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include;${CMAKE_CURRENT_SOURCE_DIR}/src> $<INSTALL_INTERFACE:include>)
1619

17-
target_include_directories(secp256k1 PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<INSTALL_INTERFACE:include>)
20+
file(GLOB SOURCES_PRECOMP src/precomputed_ecmult.c src/precomputed_ecmult_gen.c)
21+
add_library(secp256k1_precomputed ${SOURCES_PRECOMP})
22+
23+
target_include_directories(secp256k1_precomputed PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)
24+
25+
if (BUILD_TOOLS)
26+
add_executable(bench src/bench.c)
27+
target_link_libraries(bench PRIVATE secp256k1 secp256k1_precomputed)
28+
29+
add_executable(bench_internal src/bench_internal.c)
30+
target_link_libraries(bench_internal PRIVATE secp256k1_precomputed)
31+
32+
add_executable(bench_ecmult src/bench_ecmult.c)
33+
target_link_libraries(bench_ecmult PRIVATE secp256k1_precomputed)
34+
35+
install(TARGETS bench bench_internal bench_ecmult RUNTIME DESTINATION bin)
36+
endif()
37+
38+
if (BUILD_EXAMPLES)
39+
add_executable(ecdsa_example examples/ecdsa.c)
40+
target_include_directories(ecdsa_example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
41+
target_link_libraries(ecdsa_example PRIVATE secp256k1 secp256k1_precomputed)
42+
if (WIN32)
43+
target_link_libraries(ecdsa_example PRIVATE Bcrypt)
44+
endif()
45+
46+
add_executable(ecdh_example examples/ecdh.c)
47+
target_include_directories(ecdh_example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
48+
target_link_libraries(ecdh_example PRIVATE secp256k1 secp256k1_precomputed)
49+
if (WIN32)
50+
target_link_libraries(ecdh_example PRIVATE Bcrypt)
51+
endif()
52+
53+
add_executable(schnorr_example examples/schnorr.c)
54+
target_include_directories(schnorr_example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
55+
target_link_libraries(schnorr_example PRIVATE secp256k1 secp256k1_precomputed)
56+
if (WIN32)
57+
target_link_libraries(schnorr_example PRIVATE Bcrypt)
58+
endif()
59+
60+
install(TARGETS ecdsa_example ecdh_example schnorr_example RUNTIME DESTINATION bin)
61+
endif()
1862

1963
if(INSTALL_HEADERS)
2064
file(GLOB HEADERS include/*.h)
2165
install(FILES ${HEADERS} DESTINATION include)
2266
endif()
2367

24-
install(TARGETS secp256k1 EXPORT unofficial-secp256k1-targets
68+
install(TARGETS secp256k1 EXPORT unofficial-secp256k1-config
69+
RUNTIME DESTINATION bin
70+
ARCHIVE DESTINATION lib
71+
LIBRARY DESTINATION lib
72+
)
73+
74+
install(TARGETS secp256k1_precomputed EXPORT unofficial-secp256k1-config
2575
RUNTIME DESTINATION bin
2676
ARCHIVE DESTINATION lib
2777
LIBRARY DESTINATION lib
2878
)
2979

3080
install(
31-
EXPORT unofficial-secp256k1-targets
32-
FILE unofficial-secp256k1-targets.cmake
81+
EXPORT unofficial-secp256k1-config
82+
FILE unofficial-secp256k1-config.cmake
3383
NAMESPACE unofficial::
3484
DESTINATION share/unofficial-secp256k1
35-
)
85+
)

ports/secp256k1/libsecp256k1-config.h

-29
This file was deleted.

ports/secp256k1/portfile.cmake

+34-13
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,45 @@ vcpkg_check_linkage(ONLY_STATIC_LIBRARY)
22

33
vcpkg_from_github(
44
OUT_SOURCE_PATH SOURCE_PATH
5-
REPO "bitcoin-core/secp256k1"
6-
REF "0b7024185045a49a1a6a4c5615bf31c94f63d9c4"
7-
SHA512 54e0c446ae63105800dfaf23dc934734f196c91f275db0455e58a36926c29ecc51a13d9b1eb2e45bc86199120c3c472ec7b39086787a49ce388a4df462a870bc
5+
REPO bitcoin-core/secp256k1
6+
REF 3efeb9da21368c02cad58435b2ccdf6eb4b359c3
7+
SHA512 6d792943f9277a1b4c36dad62389cb38e0b93efb570b6af6c41afdb936d10ca30d4c2e4e743fc0f113d1f9785891d1e9d1fe224d7b8abd4197a9f5febf0febd6
88
)
99

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

13-
vcpkg_configure_cmake(
14-
SOURCE_PATH ${SOURCE_PATH}
15-
PREFER_NINJA
16-
OPTIONS_DEBUG
12+
vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
13+
FEATURES
14+
tools BUILD_TOOLS
15+
examples BUILD_EXAMPLES
16+
)
17+
18+
vcpkg_cmake_configure(
19+
SOURCE_PATH "${SOURCE_PATH}"
20+
OPTIONS
21+
${FEATURE_OPTIONS}
22+
OPTIONS_DEBUG
1723
-DINSTALL_HEADERS=OFF
1824
)
1925

20-
vcpkg_install_cmake()
21-
vcpkg_fixup_cmake_targets(CONFIG_PATH share/unofficial-${PORT} TARGET_PATH share/unofficial-${PORT})
26+
vcpkg_cmake_install()
27+
vcpkg_copy_pdbs()
28+
29+
vcpkg_cmake_config_fixup(CONFIG_PATH "share/unofficial-${PORT}" PACKAGE_NAME unofficial-${PORT})
30+
31+
if (BUILD_TOOLS OR BUILD_EXAMPLES)
32+
set(SECP256K1_TOOLS "")
33+
if (BUILD_TOOLS)
34+
list(APPEND SECP256K1_TOOLS bench bench_internal bench_ecmult)
35+
endif()
36+
37+
if (BUILD_EXAMPLES)
38+
list(APPEND SECP256K1_TOOLS ecdsa_example ecdh_example schnorr_example)
39+
endif()
40+
41+
vcpkg_copy_tools(TOOL_NAMES ${SECP256K1_TOOLS} AUTO_CLEAN)
42+
endif()
2243

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

ports/secp256k1/secp256k1-config.cmake

-1
This file was deleted.

ports/secp256k1/vcpkg.json

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
{
22
"name": "secp256k1",
3-
"version-string": "2017-19-10",
4-
"port-version": 4,
3+
"version-date": "2022-07-11",
54
"description": "Optimized C library for EC operations on curve",
6-
"homepage": "https://github.com/bitcoin-core/secp256k1"
5+
"homepage": "https://github.com/bitcoin-core/secp256k1",
6+
"license": "MIT",
7+
"dependencies": [
8+
{
9+
"name": "vcpkg-cmake",
10+
"host": true
11+
},
12+
{
13+
"name": "vcpkg-cmake-config",
14+
"host": true
15+
}
16+
],
17+
"features": {
18+
"examples": {
19+
"description": "Build examples"
20+
},
21+
"tools": {
22+
"description": "Build tools"
23+
}
24+
}
725
}

versions/baseline.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -6505,8 +6505,8 @@
65056505
"port-version": 3
65066506
},
65076507
"secp256k1": {
6508-
"baseline": "2017-19-10",
6509-
"port-version": 4
6508+
"baseline": "2022-07-11",
6509+
"port-version": 0
65106510
},
65116511
"selene": {
65126512
"baseline": "0.3.1",

versions/s-/secp256k1.json

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
22
"versions": [
3+
{
4+
"git-tree": "31de2b5d2286595ff7771a30dee3c68d04e78082",
5+
"version-date": "2022-07-11",
6+
"port-version": 0
7+
},
38
{
49
"git-tree": "a0ba39af9284d60d41166c4f546975e9f2b2d9df",
510
"version-string": "2017-19-10",

0 commit comments

Comments
 (0)