Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,10 @@ jobs:
name: ${{ matrix.configuration.job_name }}
# See: https://github.com/actions/runner-images#available-images.
runs-on: windows-2022
defaults:
run:
# Enforce fail-fast behavior for PowerShell.
shell: pwsh -Command "$PSNativeCommandUseErrorActionPreference = $true; $ErrorActionPreference = 'Stop'; & '{0}'"
Comment on lines +543 to +544

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be implied according to the docs?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be implied according to the docs?

The docs state: "Fail-fast behavior when possible." Effectively, it works for cmdlets only. Non-zero exit codes from native commands are ignored unless $PSNativeCommandUseErrorActionPreference is also set.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sigh, why can't we just have nice things...


strategy:
fail-fast: false
Expand Down Expand Up @@ -570,7 +574,13 @@ jobs:
- *CHECKOUT

- name: Generate buildsystem
run: cmake -E env CFLAGS="/WX ${{ matrix.configuration.cpp_flags }}" cmake -B build -DSECP256K1_ENABLE_MODULE_RECOVERY=ON -DSECP256K1_BUILD_EXAMPLES=ON ${{ matrix.configuration.cmake_options }}
run: |
cmake -E env CFLAGS="/WX ${{ matrix.configuration.cpp_flags }}" `
cmake -B build `
-DSECP256K1_BUILD_PRECOMPUTED=ON `
-DSECP256K1_ENABLE_MODULE_RECOVERY=ON `
-DSECP256K1_BUILD_EXAMPLES=ON `
${{ matrix.configuration.cmake_options }}

- name: Build
run: cmake --build build --config RelWithDebInfo -- /p:UseMultiToolTask=true /maxCpuCount
Expand All @@ -596,6 +606,11 @@ jobs:
build\bin\RelWithDebInfo\bench_internal.exe
build\bin\RelWithDebInfo\bench.exe

- name: Check precomputed files
run: |
cmake -E copy build/src/precomputed_ecmult.c build/src/precomputed_ecmult_gen.c -t src
git diff --exit-code

win64-native-headers:
name: "x64 (MSVC): C++ (public headers)"
# See: https://github.com/actions/runner-images#available-images.
Expand Down
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
cmake_minimum_required(VERSION 3.22)

if(POLICY CMP0171)
# `codegen` is a reserved target name.
# See: https://cmake.org/cmake/help/latest/policy/CMP0171.html
cmake_policy(SET CMP0171 NEW)
endif()

#=============================
# Project / Package metadata
#=============================
Expand Down Expand Up @@ -141,6 +147,11 @@ option(SECP256K1_BUILD_EXHAUSTIVE_TESTS "Build exhaustive tests." ON)
option(SECP256K1_BUILD_CTIME_TESTS "Build constant-time tests." ${SECP256K1_VALGRIND})
option(SECP256K1_BUILD_EXAMPLES "Build examples." OFF)

option(SECP256K1_BUILD_PRECOMPUTED "Generate the precomputed files in the build tree." OFF)
if(SECP256K1_BUILD_PRECOMPUTED AND CMAKE_CROSSCOMPILING)
message(FATAL_ERROR "SECP256K1_BUILD_PRECOMPUTED requires executing precompute tools, which is not supported when cross compiling.")
endif()

# Redefine configuration flags.
# We leave assertions on, because they are only used in the examples, and we want them always on there.
if(MSVC)
Expand Down
21 changes: 21 additions & 0 deletions cmake/Precompute.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function(precompute base_name)
add_executable(secp256k1_precompute_${base_name} EXCLUDE_FROM_ALL precompute_${base_name}.c)
set_target_properties(secp256k1_precompute_${base_name} PROPERTIES
COMPILE_DEFINITIONS VERIFY
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}
)
set(CODEGEN_OPT "")
if(POLICY CMP0171)
cmake_policy(GET CMP0171 _cmp0171_status)
if(_cmp0171_status STREQUAL "NEW")
set(CODEGEN_OPT CODEGEN)
endif()
endif()
add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/src/precomputed_${base_name}.c
COMMAND secp256k1_precompute_${base_name}
DEPENDS secp256k1_precompute_${base_name}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
${CODEGEN_OPT}
)
endfunction()
20 changes: 16 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,22 @@ if(SECP256K1_ENABLE_MODULE_ECDH)
set_property(TARGET secp256k1 APPEND PROPERTY PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/include/secp256k1_ecdh.h)
endif()

add_library(secp256k1_precomputed OBJECT EXCLUDE_FROM_ALL
precomputed_ecmult.c
precomputed_ecmult_gen.c
)
add_library(secp256k1_precomputed OBJECT)
if(SECP256K1_BUILD_PRECOMPUTED)
include(Precompute)
precompute(ecmult)
precompute(ecmult_gen)
target_sources(secp256k1_precomputed PRIVATE
${PROJECT_BINARY_DIR}/src/precomputed_ecmult.c
${PROJECT_BINARY_DIR}/src/precomputed_ecmult_gen.c
)
target_include_directories(secp256k1_precomputed PRIVATE ${CMAKE_CURRENT_LIST_DIR})
else()
target_sources(secp256k1_precomputed PRIVATE
${CMAKE_CURRENT_LIST_DIR}/precomputed_ecmult.c
${CMAKE_CURRENT_LIST_DIR}/precomputed_ecmult_gen.c
)
endif()

# Add objects explicitly rather than linking to the object libs to keep them
# from being exported.
Expand Down
2 changes: 1 addition & 1 deletion src/precompute_ecmult.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int main(void) {
fprintf(fp, "#include \"precomputed_ecmult.h\"\n");
fprintf(fp, "#define S(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) SECP256K1_GE_STORAGE_CONST(0x##a##u,0x##b##u,0x##c##u,0x##d##u,0x##e##u,0x##f##u,0x##g##u,0x##h##u,0x##i##u,0x##j##u,0x##k##u,0x##l##u,0x##m##u,0x##n##u,0x##o##u,0x##p##u)\n");
fprintf(fp, "#if ECMULT_WINDOW_SIZE > %d\n", window_g);
fprintf(fp, " #error configuration mismatch, invalid ECMULT_WINDOW_SIZE. Try deleting precomputed_ecmult.c before the build.\n");
fprintf(fp, " #error configuration mismatch, invalid ECMULT_WINDOW_SIZE. If this is an Autotools build, try deleting precomputed_ecmult.c before the build. If this is a CMake build, pass -DSECP256K1_BUILD_PRECOMPUTED=ON to cmake.\n");
fprintf(fp, "#endif\n");
fprintf(fp, "#ifdef EXHAUSTIVE_TEST_ORDER\n");
fprintf(fp, "# error Cannot compile precomputed_ecmult.c in exhaustive test mode\n");
Expand Down
2 changes: 1 addition & 1 deletion src/precompute_ecmult_gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ int main(int argc, char **argv) {
print_table(fp, COMB_BLOCKS, COMB_TEETH);
}
fprintf(fp, "#else\n");
fprintf(fp, "# error Configuration mismatch, invalid COMB_* parameters. Try deleting precomputed_ecmult_gen.c before the build.\n");
fprintf(fp, "# error Configuration mismatch, invalid COMB_* parameters. If this is an Autotools build, try deleting precomputed_ecmult_gen.c before the build. If this is a CMake build, pass -DSECP256K1_BUILD_PRECOMPUTED=ON to cmake.\n");
fprintf(fp, "#endif\n");

fprintf(fp, "};\n");
Expand Down
2 changes: 1 addition & 1 deletion src/precomputed_ecmult.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/precomputed_ecmult_gen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading