diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 39764f1..630d16f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,8 +6,8 @@ # trystero's CI: the superproject's reusable workflow, which builds this commit inside a checkout of # webcpp, on every lane trystero declares and its own lanes, oracle and interop, with libsecp256k1, -# libdatachannel and OpenSSL, which the workflow's actions install, its page, the lint and the test -# matrix. +# libdatachannel and OpenSSL, all built from the superproject's pinned sources, its page, the lint +# and the test matrix. name: CI on: diff --git a/AGENTS.md b/AGENTS.md index 0d31605..55a1f27 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -51,21 +51,20 @@ holds only what is specific to trystero. alone in a call of their own, without it, so the lint analyses the timer, the sealer and the WebSockets without exceptions too. trystero raises nothing of its own; a raise would go through `boost::throw_exception`. -- **The dependencies.** libsecp256k1 (every room) remains an external - installation, found through `webcpp.external` and `webcpp.external-found` - at `-sSECP256K1_ROOT=` or `-sSECP256K1_EMSCRIPTEN_ROOT=`, then - `.local/secp256k1-native` or `.local/secp256k1-emscripten`. Native system - fallback outside Windows is allowed only for this dependency. A missing - installation leaves trystero out unless `webcpp-require-external=on`. - MSVC links its static `libsecp256k1.lib` with `SECP256K1_STATIC`. - The native backend instead names `/webcpp/third_party//libdatachannel`, +- **The dependencies.** libsecp256k1 (every room) is webcpp's own build, + `/third_party//secp256k1` (v0.8.0, from `third_party/libs/secp256k1`), which + `/webcpp/trystero//trystero` names; its tables come from + `webcpp-secp256k1-tables` (see `doc/building.adoc`). Nothing is installed + outside the checkout, once the pinned submodules are initialised. + The native backend also names `/webcpp/third_party//libdatachannel`, which builds pinned libdatachannel 0.24.6, libjuice, usrsctp and libsrtp as separate static archives against `/webcpp/third_party//openssl` and its matching generated headers. These are the same OpenSSL target used by Asio and Beast, so a combined application has one provider. No `LIBDATACHANNEL_ROOT`, `OPENSSL_ROOT` or installed binary is consulted. Initialize their sources with `git submodule update --init --recursive - third_party/libs/libdatachannel third_party/libs/openssl`. Native builds + third_party/libs/libdatachannel third_party/libs/openssl + third_party/libs/secp256k1`. Native builds need CMake 3.21 or newer in addition to OpenSSL's Perl and Make/nmake. B2 forwards the configured compiler, C++ ABI, runtime and optimization flags, and isolates artifacts by their effective configuration. The diff --git a/README.md b/README.md index 7bec36d..e6cac45 100644 --- a/README.md +++ b/README.md @@ -65,25 +65,19 @@ send a wrong room proof, reported by the lower id only. trystero is developed inside the webcpp superproject, as a Boost library is developed inside Boost. Its TLS and WebRTC dependencies are built from -pinned sources; only libsecp256k1 needs an external installation: +pinned sources, and so is libsecp256k1: | Library | Needed by | Found where | | --- | --- | --- | -| libsecp256k1 0.8.0, with its `schnorrsig` and `extrakeys` modules | every room: it signs the Nostr events peers meet through | `-sSECP256K1_ROOT=` natively, `-sSECP256K1_EMSCRIPTEN_ROOT=` for its emscripten build, else `.local/secp256k1-native` and `.local/secp256k1-emscripten` | +| libsecp256k1 0.8.0, with its `schnorrsig` and `extrakeys` modules | every room: it signs the Nostr events peers meet through | `/third_party//secp256k1`, from `third_party/libs/secp256k1` | | libdatachannel 0.24.6 | the native backend | `/webcpp/third_party//libdatachannel`, from pinned source submodules | | OpenSSL 3.5.9 | the native backend | `/webcpp/third_party//openssl`, also used by Asio and Beast | -The libsecp256k1 `-s` option, on b2's command line, names a directory with the library's -`include/` and `lib/`; the environment is never read. Without it, the library -is looked for in the superproject's `.local/` directory the table names, -where webcpp's CI installs it, and else, natively outside Windows, in -`/usr/include` or `/usr/local/include`, where a system install is -legitimate; a relative `-s` is read from b2's working directory. A `-s` that names a directory -without the library's header stops the build, naming it. A library found -nowhere leaves trystero out: its tests and examples are skipped, b2 says so -once, naming the library and where it looked, and every other library -builds; `webcpp-require-external=on`, which the CI gives, stops the build -instead. With them found, +The tables of libsecp256k1 follow `webcpp-secp256k1-tables`: `auto` is window 15 and +comb 11x6 natively (a larger program, faster signing and verification) and window 2 and +comb 2x5 on emscripten (the same signing, verification a little slower than window 4, a +smaller program). A program that wants otherwise asks for `small` +or `large`. With the pinned source submodules initialized, b2 libs/trystero/test libs/trystero/example b2 toolset=emscripten libs/trystero/test libs/trystero/example @@ -241,34 +235,13 @@ git clone https://github.com/emscripten-core/emsdk.git git clone --recurse-submodules https://github.com/webcpporg/webcpp.git ``` -### 5. Build libsecp256k1 - -libsecp256k1 is built twice: natively, and with Emscripten for the browser. - -```sh -git clone --branch v0.8.0 https://github.com/bitcoin-core/secp256k1.git -options="-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF \ - -DSECP256K1_ENABLE_MODULE_SCHNORRSIG=ON -DSECP256K1_ENABLE_MODULE_EXTRAKEYS=ON \ - -DSECP256K1_ECMULT_WINDOW_SIZE=4 -DSECP256K1_ECMULT_GEN_KB=2 \ - -DSECP256K1_BUILD_TESTS=OFF -DSECP256K1_BUILD_EXHAUSTIVE_TESTS=OFF \ - -DSECP256K1_BUILD_BENCHMARK=OFF" - -cmake -S secp256k1 -B build-secp256k1-native $options \ - -DCMAKE_INSTALL_PREFIX=$PWD/webcpp/.local/secp256k1-native -cmake --build build-secp256k1-native && cmake --install build-secp256k1-native - -./emsdk/upstream/emscripten/emcmake cmake -S secp256k1 -B build-secp256k1-emscripten $options \ - -DCMAKE_INSTALL_PREFIX=$PWD/webcpp/.local/secp256k1-emscripten -cmake --build build-secp256k1-emscripten && cmake --install build-secp256k1-emscripten -``` - -### 6. Initialize the native dependencies +### 5. Initialize the native dependencies The recursive checkout already includes pinned OpenSSL, libdatachannel, libjuice, usrsctp, plog and libsrtp sources. For an existing checkout: ```sh -git -C webcpp submodule update --init --recursive third_party/libs/openssl third_party/libs/libdatachannel +git -C webcpp submodule update --init --recursive third_party/libs/openssl third_party/libs/libdatachannel third_party/libs/secp256k1 ``` B2 builds them with the selected compiler, runtime and C++ ABI when the @@ -279,7 +252,7 @@ combined application; no system OpenSSL or installed libdatachannel is used. Native Trystero targets declare `multi` because WebRTC runs worker threads. The supplied examples and tests declare it already. -### 7. Tell b2 its compilers and Boost +### 6. Tell b2 its compilers and Boost ```sh cat > user-config.jam <=` with the directory that `cmake --install` wrote. -- **b2 stops naming a `-s`**: it names a directory without the library's - header; give the directory that `cmake --install` wrote. - **b2 prints `node: bad option: --experimental-wasm-threads`** when it configures the emscripten toolset: b2's toolset probes node with a flag that recent Node removed. It is harmless. diff --git a/build.jam b/build.jam index 6bc8db5..27dc04b 100644 --- a/build.jam +++ b/build.jam @@ -10,34 +10,12 @@ project /webcpp/trystero ; -# Only libsecp256k1 is externally installed. Native WebRTC and OpenSSL are -# pinned source dependencies, built together for the consumer's B2 variant. +# libsecp256k1 (every room) is webcpp's build of it, /third_party//secp256k1: +# v0.8.0 from the submodule third_party/libs/secp256k1, with the tables the +# feature webcpp-secp256k1-tables chooses (small on emscripten, large natively; +# CODING-GUIDELINES.md chapter 5). Native WebRTC and OpenSSL are pinned source +# dependencies too, built together for the consumer's B2 variant. import errors ; -import webcpp ; - -# tag::dependencies[] -local secp256k1-root = [ webcpp.external trystero : libsecp256k1 - : SECP256K1_ROOT : secp256k1-native : secp256k1.h : native ] ; -local secp256k1-emscripten-root = [ webcpp.external trystero : libsecp256k1 - : SECP256K1_EMSCRIPTEN_ROOT : secp256k1-emscripten : secp256k1.h : emscripten ] ; -lib secp256k1 : : secp256k1 emscripten - $(secp256k1-emscripten-root)/lib - : : $(secp256k1-emscripten-root)/include ; -lib secp256k1 : : libsecp256k1 msvc - $(secp256k1-root)/lib - : : $(secp256k1-root)/include SECP256K1_STATIC ; -lib secp256k1 : : secp256k1 $(secp256k1-root)/lib - : : $(secp256k1-root)/include ; -# Searched libraries are used only through usage requirements. -explicit secp256k1 ; -# end::dependencies[] - -# The dependencies of the rooms: libsecp256k1, the emscripten build of it on -# emscripten. Checked only when a target that uses trystero is built. -rule trystero-dependencies ( properties * ) -{ - return [ webcpp.external-found trystero : libsecp256k1 : $(properties) ] ; -} # The native backend's own dependencies, checked only when a target that # uses it is built. @@ -55,9 +33,9 @@ rule native-dependencies ( properties * ) # program then fails to link, undefined _embind_register_function), since # b2 takes only free features from usage requirements. # tag::trystero[] -alias trystero : : @trystero-dependencies +alias trystero : : : : include /boost//headers /webcpp//boost_json - /webcpp/config//config secp256k1 + /webcpp/config//config /third_party//secp256k1 emscripten:BOOST_ASIO_DISABLE_THREADS emscripten:-lembind ; # end::trystero[] diff --git a/doc/building.adoc b/doc/building.adoc index 7175d46..fafaa34 100644 --- a/doc/building.adoc +++ b/doc/building.adoc @@ -9,8 +9,7 @@ trystero is header-only, and is developed inside the webcpp superproject, as a Boost library is developed inside Boost. Its native TLS and WebRTC -dependencies are built from pinned sources. Only libsecp256k1 needs an -external installation: +dependencies, and libsecp256k1, are built from pinned sources: [cols="2,2,3",options="header"] |=== @@ -18,9 +17,7 @@ external installation: | libsecp256k1 0.8.0, with its `schnorrsig` and `extrakeys` modules | every room: it signs the Nostr events peers meet through -| `-sSECP256K1_ROOT=` natively, else `.local/secp256k1-native`; - `-sSECP256K1_EMSCRIPTEN_ROOT=` for its emscripten build, else - `.local/secp256k1-emscripten` +| `/third_party//secp256k1`, built from `third_party/libs/secp256k1` | libdatachannel 0.24.6 | the native backend @@ -31,26 +28,12 @@ external installation: | `/webcpp/third_party//openssl`, shared by the Asio, Beast and Trystero build graphs |=== -The libsecp256k1 `-s` option names a directory with the library's `include/` and `lib/`, on b2's -command line; the environment is never read, so that a variable a shell keeps -from another day never replaces `.local/` without a word. Without it, the -library is looked for in the directory of `.local/` that the table names, -where webcpp's continuous integration installs it, when that directory holds -the library's header, and else, natively outside Windows, in `/usr/include` -or `/usr/local/include`, where a system install is legitimate. A relative -`-s` is read from b2's working directory. A `-s` that names a directory without the library's -header stops the build, naming it. A library found nowhere leaves trystero -out: its tests and examples are skipped, the build says so once, naming the -library and where it looked, and every other library builds; with -`webcpp-require-external=on`, as the continuous integration builds, it stops -the build instead. With MSVC, libsecp256k1 uses CMake's -`libsecp256k1.lib`, linked statically with `SECP256K1_STATIC` defined. -trystero's `build.jam` declares that external dependency so: - -[listing] ----- -include::{library-root}/build.jam[tag=dependencies] ----- +The tables of libsecp256k1 are chosen by the feature +`webcpp-secp256k1-tables`. With `auto`, the default, natively they are window 15 +and comb 11x6: a larger program, and faster signing and verification. On emscripten +they are window 2 and comb 2x5: the same signing, verification a little slower than +window 4, and a smaller program. A program that wants otherwise asks for +`small` or `large`. [#trystero-building-project] === In a b2 project @@ -120,7 +103,7 @@ include::{webcpp-root}/tools/ci/emsdk.jam[tag=emsdk] include::{webcpp-root}/tools/ci/emsdk.jam[tag=emscripten] ---- -With it, libsecp256k1 installed and the pinned source submodules initialized, from the root of a webcpp checkout, +With it and the pinned source submodules initialized, from the root of a webcpp checkout, these build the tests and the examples, natively and on emscripten: [source,bash] @@ -132,35 +115,12 @@ b2 toolset=emscripten libs/trystero/test libs/trystero/example [#trystero-building-dependencies] === Preparing the dependencies -libsecp256k1 is built twice: natively, and with Emscripten for the browser. -Its small tables keep the browser's download small: - -[source,bash] ----- -git clone --branch v0.8.0 https://github.com/bitcoin-core/secp256k1.git -options="-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF \ - -DSECP256K1_ENABLE_MODULE_SCHNORRSIG=ON -DSECP256K1_ENABLE_MODULE_EXTRAKEYS=ON \ - -DSECP256K1_ECMULT_WINDOW_SIZE=4 -DSECP256K1_ECMULT_GEN_KB=2 \ - -DSECP256K1_BUILD_TESTS=OFF -DSECP256K1_BUILD_EXHAUSTIVE_TESTS=OFF \ - -DSECP256K1_BUILD_BENCHMARK=OFF" - -cmake -S secp256k1 -B build-secp256k1-native $options \ - -DCMAKE_INSTALL_PREFIX=$PWD/webcpp/.local/secp256k1-native -cmake --build build-secp256k1-native && cmake --install build-secp256k1-native - -emcmake cmake -S secp256k1 -B build-secp256k1-emscripten $options \ - -DCMAKE_INSTALL_PREFIX=$PWD/webcpp/.local/secp256k1-emscripten -cmake --build build-secp256k1-emscripten && cmake --install build-secp256k1-emscripten ----- - -where `webcpp` is the checkout of the superproject: each is installed in the -directory of `.local/` where the build looks for it. - Initialize the native dependencies from the superproject root: [source,bash] ---- -git submodule update --init --recursive third_party/libs/openssl third_party/libs/libdatachannel +git submodule update --init --recursive third_party/libs/openssl third_party/libs/libdatachannel \ + third_party/libs/secp256k1 ---- Install CMake 3.21 or newer, Perl and Make (native Windows Perl and nmake diff --git a/doc/changelog.adoc b/doc/changelog.adoc index 65033fe..d6c7728 100644 --- a/doc/changelog.adoc +++ b/doc/changelog.adoc @@ -16,6 +16,9 @@ of every version are on webcpp's index page. === Unreleased // tag::unreleased[] +* Changed libsecp256k1 to come from `/third_party//secp256k1`, not an external + installation: `-sSECP256K1_ROOT` and `-sSECP256K1_EMSCRIPTEN_ROOT` are gone, and + `webcpp-secp256k1-tables` chooses its tables. // end::unreleased[] [#trystero-changelog-0-1-0] diff --git a/doc/overview.adoc b/doc/overview.adoc index 202f07a..e8e23d5 100644 --- a/doc/overview.adoc +++ b/doc/overview.adoc @@ -72,7 +72,8 @@ namespace `webcpp::trystero`. System; and Beast for the native backend. * https://github.com/bitcoin-core/secp256k1[libsecp256k1] 0.8.0, with its `schnorrsig` and `extrakeys` modules, for the BIP-340 signatures of Nostr - events: every room needs it. + events: every room needs it. webcpp builds it from its pinned + source, `/third_party//secp256k1`. * In the browser: Emscripten 6.0.11, the version webcpp pins, and a page served from a secure context (https, or http on `localhost`), where `crypto.subtle` exists. diff --git a/doc/roadmap.adoc b/doc/roadmap.adoc index be5ef58..87de050 100644 --- a/doc/roadmap.adoc +++ b/doc/roadmap.adoc @@ -21,7 +21,3 @@ echoes the offerer's `msid` into the answer. . *Trystero's other features.* Request actions (`kind: 'request'`), decisions on incoming transfers and their progress, the application's own handshake, passive rooms, and the other strategies, among them MQTT and BitTorrent trackers. -. *libsecp256k1 from webcpp's own build.* libsecp256k1 is still found where -b2's command line or the superproject's `.local/` says. Native OpenSSL and -libdatachannel already build from pinned `third_party/` sources -(<>). diff --git a/doc/testing.adoc b/doc/testing.adoc index bfb19d3..3c5ed9f 100644 --- a/doc/testing.adoc +++ b/doc/testing.adoc @@ -262,9 +262,8 @@ and run the unit tests with GCC 14 and with clang 18 against `libstdc{plus}{plus}` in a Linux container, Ubuntu 24.04, with `docker run` and the network `none`, which leaves the loopback alone: every test passes, which shows that none reaches beyond the machine -(<>). libsecp256k1 is installed before -running the container. B2 builds the pinned OpenSSL, libdatachannel and -nested source dependencies inside the container with the lane's compiler, +(<>). B2 builds the pinned libsecp256k1, OpenSSL, +libdatachannel and nested source dependencies inside the container with the lane's compiler, runtime and static link configuration. These builds need no network access. [#trystero-testing-provider] diff --git a/test/provider/Jamfile b/test/provider/Jamfile index a438ce5..1edf242 100644 --- a/test/provider/Jamfile +++ b/test/provider/Jamfile @@ -8,7 +8,6 @@ import webcpp ; webcpp.targets native ; webcpp.original python3 ; -# Keep ownership with Trystero so CI provisions its external secp256k1. # The common executable names all three public dependency aliases. webcpp.drive combined : ../../../../tools/openssl/test//combined_provider : release multi on