bitcoin-core / secp256k1

Optimized C library for EC operations on curve secp256k1
MIT License
2.02k stars 977 forks source link

cmake: Set top-level target output locations #1553

Open hebasto opened 2 weeks ago

hebasto commented 2 weeks ago

While testing https://github.com/bitcoin-core/secp256k1/pull/1551, I noticed that when cross-compiling a shared library with examples for Windows, the ctest fails to run examples with Wine. Adjusting the PATH variable in https://github.com/bitcoin-core/secp256k1/blob/4af241b32099067464e015fa66daac5096206dea/examples/CMakeLists.txt#L16-L18 does not help because WINEPATH is expected.

Another issue with the current implementation is that the examples cannot run individually on Windows.

This PR resolves both issues by reverting the implementation from https://github.com/bitcoin-core/secp256k1/pull/1290 in favour of the reworked and improved implementation from https://github.com/bitcoin-core/secp256k1/pull/1233.

real-or-random commented 2 weeks ago

What are your commands for building on wine?

hebasto commented 2 weeks ago

What are your commands for building on wine?

On Ubuntu 24.04 with the wine-binfmt package installed:

$ cmake -B build --toolchain cmake/x86_64-w64-mingw32.toolchain.cmake -DSECP256K1_BUILD_EXAMPLES=ON
$ cmake --build build
$ ctest --test-dir build
Internal ctest changing into directory: /home/hebasto/git/secp256k1/secp256k1/build
Test project /home/hebasto/git/secp256k1/secp256k1/build
    Start 1: noverify_tests
1/6 Test #1: noverify_tests ...................   Passed   52.72 sec
    Start 2: tests
2/6 Test #2: tests ............................   Passed  111.58 sec
    Start 3: exhaustive_tests
3/6 Test #3: exhaustive_tests .................   Passed    8.01 sec
    Start 4: ecdsa_example
4/6 Test #4: ecdsa_example ....................   Passed    1.35 sec
    Start 5: ecdh_example
5/6 Test #5: ecdh_example .....................   Passed    1.34 sec
    Start 6: schnorr_example
6/6 Test #6: schnorr_example ..................   Passed    1.32 sec

100% tests passed, 0 tests failed out of 6

Total Test time (real) = 176.31 sec
$ ./build/bin/schnorr_example.exe 
Is the signature valid? true
Secret Key: 0x964362f6515fbb691dee49b936c8ba46dadd505eb4aa27f5db9b1ccf510f04a8
Public Key: 0x286123fee26ecfc75ec8bd6d4e175a9b4fa729e7d2bcd4034661a33dee600d80
Signature: 0xef0aa23ae13fd06710e31204a7a8ab52f0b726159b3cb2344c090220ed32d6dda958c9f7b3383c3fa7524a7f7ed54bf381c8a3bab1f8561072887dae6bf7bfe1
fanquake commented 2 weeks ago

implementation from https://github.com/bitcoin-core/secp256k1/pull/1233.

cc @theuni