Skip to content

Feat/native assets cs - #14

Open
sneurlax wants to merge 11 commits into
mainfrom
feat/native-assets-cs
Open

Feat/native assets cs#14
sneurlax wants to merge 11 commits into
mainfrom
feat/native-assets-cs

Conversation

@sneurlax

@sneurlax sneurlax commented Sep 3, 2026

Copy link
Copy Markdown
Member

Related to #11

This branch is named feat/native-assets-cs because feat/native-assets is based on upstream

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 bitcoin-core/secp256k1 at v0.5.0 (e3a885d) needed to
compile the shared library: public headers, implementation and the ecdh,
extrakeys, 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 autotools and
CMake builds: -O2, the ecdh, extrakeys, recovery and schnorrsig modules
and the default precomputed table sizes. Requires Dart 3.10, the first
release with stable build hooks.
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, autotools, CMake and MinGW scripts are superseded by the
build hook. The WebAssembly build script and shared helpers remain.
coinlib compiles libsecp256k1 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 example's Linux and Windows runners were generated before the
Flutter template added the step that installs build hook output into
the application bundle, so libsecp256k1 was built but not bundled. Add
the install step from the current template.
The SDK lower bound raise to 3.10 changes the language version that dart
format and the analyzer apply. Reformat in the tall style and add braces
to single-statement if bodies so that dart analyze --fatal-infos passes.
@sneurlax
sneurlax force-pushed the feat/native-assets-cs branch from 1ddf938 to 699e69c Compare September 4, 2026 00:16
@sneurlax

sneurlax commented Sep 4, 2026

Copy link
Copy Markdown
Member Author

alot of the changes are due to vendoring secp256k1. not ideal

tho that does lead me to think that only secp256k1 itself really needs to be handled via native-assets 🤔 so I may reapproach this but with a focus on a new secp256k1 package that vendors the current secp256k1 checkout currently used, have that use native_toolchain_cmake (a la flutter_libsparkmobile) for the build, maybe add some stagex or a nix flake for reproducibility as a side bonus (or left as TODO for the future), and redo this migration by just pointing the secp256k1 aspects to a new secp256k1 package

The example app's Android scaffold was pinned to Gradle 7.5 / AGP 7.2.0
/ Kotlin 1.7.10, which cannot build under Flutter 3.44 at all: Flutter's
own flutter_tools/gradle/build.gradle.kts applies the Kotlin DSL plugin,
which requires Gradle 7.6.3 or newer. This is not a JDK problem - the
build fails the same way under JDK 17 and JDK 21.

Bring the scaffold in line with the peercoin-lineage branch:

  - Gradle wrapper 7.5   -> 8.11.1
  - AGP           7.2.0  -> 8.9.0
  - Kotlin        1.7.10 -> 2.2.20
  - add the explicit `namespace`, which AGP 8 requires

This only touches the example application's Gradle files; the library
and the secp256k1 build hook are unchanged.

Verified on Windows: full-ABI release APK builds (arm64-v8a,
armeabi-v7a, x86_64), each bundling libsecp256k1.so with 66 exported
secp256k1_* symbols including secp256k1_ecdsa_recover and
secp256k1_schnorrsig_sign32, and no internal symbols leaked. Installed
and run on an Android 17 x86_64 emulator, where the Schnorr signature
matched the Windows desktop value byte for byte. dart analyze
--fatal-infos clean, dart test +286.

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.
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