Repository navigation
gl-sdk: Bundle the desktop libraries in the jvm jar, update Gradle and AGP - #765
Merged
Merged
Conversation
angelix
force-pushed
the
ave-native-support
branch
3 times, most recently
from
November 13, 2026 15:27
ed105e6 to
9e21a07
Compare
cdecker
previously approved these changes
Nov 16, 2026
cdecker
force-pushed
the
ave-native-support
branch
from
November 16, 2026 13:02
9e21a07 to
8dd3427
Compare
cdecker
enabled auto-merge (rebase)
November 16, 2026 13:03
- AGP 9.5 requires Gradle 9.6.0 or newer and fixes the Configuration.setVisible() deprecation warnings that AGP 9.4.1 triggers on Gradle 9.8 - Read libraryVersion with project.property(): Gradle 9.6 deprecates the 'val name: Type by project' delegate, which Gradle 10 removes Kotlin stays at 2.2.21, as KT-88548 is fixed only in Kotlin 2.5.0. The Gradle deprecation warnings left come from its Gradle plugin.
The glsdk-jvm artifact shipped without a native library, so loading the SDK on a desktop JVM failed with UnsatisfiedLinkError. - Build the library for macOS, Linux and Windows, each on x86_64 and arm64, in release mode and unwinding on panic like the mobile libraries, and put each in the jvm resources directory where JNA looks for it - Strip the macOS dylibs with Apple's /usr/bin/strip instead of cargo's rust-objcopy, which in rustc 1.91 does not pad the string table to 8 bytes after an indirect symbol table with an odd number of entries: dyld on macOS 27 refuses such a dylib (seen in LWK, 291 entries). gl-sdk has 280 entries today, so it only loads by luck. The strip first on PATH can be llvm-strip, with the same bug, or GNU strip, without Mach-O support. Stripping the local symbols too almost halves the arm64 dylib. - Cross compile Linux from macOS with cargo-zigbuild against glibc 2.17, so the publish job keeps running on a single runner. The libraries depend only on libc, libm, libdl and libpthread, and the newer glibc functions Rust's std uses are weak symbols. - Cross compile Windows with cargo-xwin and link the C runtime statically: the DLLs depend only on Windows system DLLs and load without the Visual C++ Redistributable. The flag is appended to RUSTFLAGS, as cargo-xwin, like cargo, ignores the target rustflags when RUSTFLAGS is set, and a caller's RUSTFLAGS would drop it. - Pin the MSVC CRT (14.44.17.14) and Windows SDK (10.0.26100) cargo-xwin downloads, in a cache directory per version pair, the one LWK's build uses too: cargo-xwin reuses an existing cache that has the needed arches whatever its versions, which would ignore the pin - On Windows arm64 ring compiles its C code with clang, which reads the clang-cl /imsvc flags cargo-xwin passes the SDK headers with as file names. The headers go in INCLUDE instead, which clang and clang-cl both search, and only CFLAGS loses the flags: CXXFLAGS keeps /EHsc, without which bitcoinconsensus fails to compile. - cargo xwin env folds RUSTFLAGS into the target rustflags and exports an empty RUSTFLAGS, which cargo would use instead: unset it. Its output is assigned before the eval, so a failing cargo xwin env stops the build. - Build the two Windows libraries one after the other: every cargo-xwin run recreates the clang-cl symlink in its shared cache, and on a fresh cache unpacks the SDK there, so two runs at once fail with "Failed to setup clang-cl symlink" or "failed to splat" - Install cargo-zigbuild and cargo-xwin under target/cross-tools once per build. cargo-zigbuild needs zig, which the CI jobs install, the GitLab one only when the runner lacks it. cargo-xwin needs the llvm-tools component, which both CI jobs install: it links its llvm-ar as llvm-lib, the archiver it gives cc-rs, and silently skips the link without it, so ring's build script fails to find llvm-lib. - Target Java 17 and compile against its API: the classes otherwise get the bytecode version of the JDK running Gradle, Java 24 on a JDK 25 machine - Pass --enable-native-access=ALL-UNNAMED to the jvm tests: on Java 24 or later JNA loading the library with System::load, a restricted method, prints a warning. A library jar cannot grant native access itself, so the README tells applications to pass the flag. - Run the jvm tests in the GitHub workflow and build the Kotlin bindings there with Rust 1.91.0, as cargo-xwin needs 1.89 or later. Add the desktop targets to both CI jobs building the bindings.
The generated JVM bindings passed the library name to JNA, which looks it up in the system library paths before it falls back to the class path. A libglsdk with the same name in the working directory (macOS, Windows), on PATH (Windows) or in LD_LIBRARY_PATH was loaded instead of the one in the jar, and received every call into the SDK, the mnemonic included. Pin gobley to a revision that extracts the bundled library and loads it by its absolute path, which JNA opens without searching, and deletes the extracted file once it is loaded, as JNA does. The Android, iOS and common bindings are unchanged. Verified with a library planted in the working directory on macOS and Windows and in LD_LIBRARY_PATH on Linux: the unpatched bindings load it, the patched ones load the bundled library.
angelix
force-pushed
the
ave-native-support
branch
from
November 16, 2026 14:14
8dd3427 to
e4e32c1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
glsdk-jvm0.5.0 on Maven Central contains nolibglsdkfor any platform, so the first SDK call on a desktop JVM fails withUnsatisfiedLinkError: Unable to load library 'glsdk'. Thejvm()target is declared, buttask build:kotlinnever builds a desktop library.jvm()sets nojvmTarget, so the bytecode version follows the JDK running Gradle. 0.5.0 happens to be Java 17; a JDK 25 machine produces Java 24 classes (major version 68).lib/build.gradle.ktsreadslibraryVersionwith theby projectdelegate that Gradle 9.6 deprecates.glsdkto JNA, which looks it up in the system library paths before the class path: the working directory on macOS and Windows, everyPATHdirectory on Windows, andLD_LIBRARY_PATHon Linux. Alibglsdkplaced there is loaded instead of the bundled one and receives every call into the SDK, the mnemonic included.Change
gl-sdk-android: Update Gradle to 9.8.2 and AGP to 9.5.1Configuration.setVisible()deprecations AGP 9.4.1 triggers on Gradle 9.8.libraryVersionis read withproject.property().gl-sdk: Bundle the desktop libraries in the jvm jarjvmtask, whichkotlindepends on, buildslibglsdkfor macOS, Linux and Windows on x86_64 and arm64, in release and unwinding on panic through gl-sdk: build the Android libraries in release mode, and unwind on panic on iOS too #762'ssdk_env. It puts each injvmMain/resources/<platform>/, where JNA looks for it./usr/bin/strip -xinstead of cargo's rust-objcopy. In rustc 1.91, rust-objcopy does not pad the string table to 8 bytes after an indirect symbol table with an odd number of entries, and dyld on macOS 27 refuses such a dylib. LWK hit this with 291 entries; gl-sdk has 280 today, so it only loads by luck. The full path matters: thestripfirst onPATHcan bellvm-strip, with the same bug, or GNU strip, which doesn't handle Mach-O.+crt-staticflag is appended toRUSTFLAGS, because cargo-xwin, like cargo, ignores the target rustflags whenRUSTFLAGSis set, and a caller'sRUSTFLAGSwould drop it. The MSVC CRT (14.44.17.14) and Windows SDK (10.0.26100) are pinned, each version pair in its own cache directory, the one LWK uses too: cargo-xwin reuses an existing cache that has the needed arches whatever its versions, which would ignore a plain pin. On arm64, ring compiles its C code with plain clang, which can't read the clang-cl/imsvcflags cargo-xwin passes the SDK headers with. The headers go inINCLUDEinstead, and onlyCFLAGSloses the flags, sinceCXXFLAGSkeeps/EHsc, whichbitcoinconsensusneeds. This build needs ring 0.17: ring 0.16, whichmaindropped ind6fb51df, has noaarch64-pc-windows-msvcsupport.clang-clsymlink in its shared cache, so Task's parallel deps made them fail withFailed to setup clang-cl symlink ... File exists.-Xjdk-release=17). The jvm tests run with--enable-native-access=ALL-UNNAMED, because Java 24 or later warns when JNA callsSystem::load. The README tells applications to pass the same flag.:lib:jvmTestand builds with Rust 1.91.0, since cargo-xwin needs 1.89 or later. Both CI jobs get the desktop targets, zig, and thellvm-toolscomponent: cargo-xwin links itsllvm-arasllvm-lib, the archiver it gives cc-rs, and silently skips the link without it, so ring's build script fails withfailed to find tool "llvm-lib". The GitLab job'sbefore_scriptexpectsrustupandbrewon the m4 runner, as LWK's does; I can't check that runner.*.dllin.gitignore.This mirrors LWK's desktop support, without its
simplicity-sysNDEBUGworkaround and with a narrower Windows arm64 recipe, as LWK also had to handlepsmandaws-lc.gl-sdk: Load the bundled JVM library by its absolute path2af41b4onangelix/gobleymain: gobley 0.3.7 plus Read unsigned 8/16-bit direct-mapped returns as Int on JVM and Android gobley/gobley#297 and Load the bundled library by its absolute path on JVM gobley/gobley#300. With Load the bundled library by its absolute path on JVM gobley/gobley#300 the JVM bindings extract the bundled library withNative.extractFromResourcePath()and register it by its absolute path, which JNA opens without searching.uniffi.component.glsdk.libraryOverridestill comes first, and without a bundled library for the platform the name is looked up as before. The extracted file is deleted once loaded, and on Windows at the next start, as JNA does. The Android, iOS and common bindings are unchanged.mainalso merges Fix generated ProGuard rules not reaching library consumers gobley/gobley#291, Remove dangling consumerProguardFiles references from examples gobley/gobley#292 and Stop UniFFI tests depending on wall-clock timing and thread scheduling gobley/gobley#294 (ProGuard rules, examples, tests). The generated bindings are byte-identical to those from Read unsigned 8/16-bit direct-mapped returns as Int on JVM and Android gobley/gobley#297 and Load the bundled library by its absolute path on JVM gobley/gobley#300 alone.Testing
macOS 27 on arm64, rustc 1.98.1:
task build:kotlintask build:jvm, cached, 5 runs:lib:jvmTest, JDK 25mainwithUnsatisfiedLinkError, passes here with no native-access warningCommonTestagainst the builtlib-jvm.jar,eclipse-temurin:17-jreon linux/arm64 and linux/amd64darwin-x86-64dylib under Rosettaffi_glsdk_uniffi_contract_versionreturns 29GLIBC_2.17; they need only libc, libm, libdl and libpthreadVCRUNTIME140,ucrtbaseorapi-ms-win-crt-*RUSTFLAGS="--cfg glsdk_probe"+crt-staticand the caller's flag. Before appending toRUSTFLAGS, both importedVCRUNTIME140,MSVCP140andapi-ms-win-crt-*.textidentical; about 110 bytes of build metadata differ: generated-source paths in panic locations, whose hash follows the rustflags, the linker timestamp and the PDB GUIDuniffi_glsdksymbols:lib:assemble:lib:iosSimulatorArm64Test:lib:connectedAndroidDeviceTest, arm64 emulatorpublishToMavenLocal, into a scratch repositoryglsdk-jvm-0.5.0.jarcontains all six librariestask build:kotlinand with the libraries built frommain.main, the Android device tests printUnable to strip ... libglsdk.so(AGP's default NDK isn't installed) and, on JDK 25, asun.misc.Unsafewarning from protobuf in AGP's test runner.lld-linkLNK4099 warnings: the static CRT's objects reference debug symbol files on Microsoft's build machines (D:\a\_work\...\libcmt.amd64.pdb). They don't affect the DLL.aka.mswith no timeout, while LWK's runs failed withunable to locate SDK. If Microsoft drops the pinned versions, CI may hang until its job timeout rather than fail.libglsdkin the working directory on macOS 27 and Windows 11 arm64, and inLD_LIBRARY_PATHon Ubuntu 26.04 arm64, run with-Djna.debug_load=true: before, JNA loads the copy; after, the bundled library.libraryOverridestill takes precedence, and a jar without the platform's library falls back to the name lookup.