Skip to content

Use the new Dart Native Assets toolchain for building secp256k1 - #51

Closed
sneurlax wants to merge 10 commits into
peercoin:masterfrom
cypherstack:feat/native-assets
Closed

Use the new Dart Native Assets toolchain for building secp256k1#51
sneurlax wants to merge 10 commits into
peercoin:masterfrom
cypherstack:feat/native-assets

Conversation

@sneurlax

@sneurlax sneurlax commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

See https://dart.dev/tools/hooks for more information related to Dart's new Native Assets toolchain: native builds may now be triggered on dart and flutter commands via hook/build.dart. Once set up, users won't have to build secp256k1 manually but builds will be triggered on first run.

I have only tested on Linux and Android so far: macOS, iOS, Windows, etc to come:
Tested:

  • Linux
  • Android emulator on Linux
  • Android physical hardware from Linux
  • macOS
  • Android emulator on macOS
  • Android physical hardware from macOS
  • iOS Simulator
  • iOS physical hardware
  • Windows
  • Android emulator on Windows
  • Android physical hardware from Windows

Vendor the subset of peercoin/secp256k1-coinlib at v0.7.0 (69018e5)
needed to compile the shared library: public headers, implementation and
the ecdh, extrakeys, musig, recovery and schnorrsig modules. ffigen now uses
the headers from third_party instead of the duplicates under
include/.
Use native_toolchain_c to compile the vendored sources into a shared
library code asset. The configuration matches the previous CMake builds:
-O2, the ecdh, extrakeys, musig, recovery and schnorrsig modules, a
window size of 15 and the 86 KiB signing table. Requires Dart 3.10, the
first release with stable build hooks.
@sneurlax

sneurlax commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

side benefit: CocoaPods already need to be updated to Swift Package Manager, this will handle that, too.

The analyzer flags if (stack != null) ...stack under the raised SDK
lower bound.
Regenerate the bindings with ffi-native so functions are top-level
@Native declarations resolved against the code asset from the build
hook. The wrapper no longer loads a prebuilt library from build/ or via
DynamicLibrary.open, and the path dependency is removed.
The Docker, CMake and MinGW scripts are superseded by the build hook.
The WebAssembly build script and shared helpers remain.
coinlib compiles secp256k1-coinlib through its build hook for each
target platform, so the CMake, Gradle and CocoaPods glue is no longer needed
and the package becomes a plain Dart package. Requires Dart 3.10 and
Flutter 3.38, the first releases with stable build hooks.
Depend on coinlib_flutter and coinlib by path so the example exercises
the checked-out code instead of the packages published to pub.dev. The
Linux and Windows runners also gain the template step that installs
build hook output into the bundle; they were generated before that step
existed.
Flutter 3.44 warns that support for Kotlin Gradle Plugin 2.2.10 "will
soon be dropped" and asks for at least 2.2.20. Bump the KGP version in
the example app's settings.gradle to clear the warning.

Verified on Windows: full-ABI release APK builds (arm64-v8a,
armeabi-v7a, x86_64), each bundling libsecp256k1.so with 81 exported
secp256k1_* symbols, 20 of them secp256k1_musig_*, and no internal
symbols leaked. dart analyze --fatal-infos clean, dart test +327.

Staged on a -win branch for review on non-Windows hosts before adoption.
Flutter 3.44 warns that support for Android Gradle Plugin 8.9.0 "will
soon be dropped" and asks for at least 8.11.1. AGP 8.11 in turn requires
Gradle 8.13 or newer, and Flutter separately wants Gradle 8.14, so move
the wrapper straight to 8.14.

  - AGP    8.9.0   -> 8.11.1
  - Gradle 8.11.1  -> 8.14

Together with the preceding Kotlin bump this clears every "will soon be
dropped" warning the Flutter Android build emits; the build now runs
warning-free.

Note this is needed on the peercoin lineage too: while that scaffold
already carried the Gradle 8.11.1 wrapper and the explicit namespace,
its AGP has been pinned at 8.9.0 on every ref including master.

Verified on Windows: full-ABI release APK builds (arm64-v8a,
armeabi-v7a, x86_64) with an unchanged secp256k1 export surface, and
the Windows desktop release build still bundles secp256k1.dll.
@sneurlax

sneurlax commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

I am going to redo this where instead of vendoring the whole secp256k1 repo, secp256k1 becomes a new package and plugin using native-assets (native_toolchain_cmake or similar) for the build. Then the new version of this PR will retain most of the stripping of build scaffolding (moving it out into a secp256k1 plugin, I'm thinking at this point) but not the huge addition of the secp256k1 codebase in this way

@sneurlax sneurlax closed this Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant