Pipeline + Go, Wasm, Java, Rust examples#65
Conversation
| - uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: lighter-go-darwin | ||
| path: build/lighter-signer-darwin-arm64.dylib No newline at end of file |
There was a problem hiding this comment.
We also would need:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: trueto prevent multiple pushes creating queue
Also for all external actions we need to pin them to SHA instead of tag (tags are mutable and prone to suplply chain attacks) .e.g.
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2All actions with SHAs:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
- uses: actions/setup-java@c1e323688fd81a25caa38c78aa6df2d33d3e20d9 # v4
- uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable
- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2
- uses: extractions/setup-just@dd310ad5a97d8e7b41793f8ef055398d51ad4de6 # v2
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
No release workflow right now. CI uploads artifacts, but nothing creates a GitHub Release on tag or attaches the binaries. Looks like the existing releases were done manually — might be worth automating at some point.
darwin/amd64 (Intel Mac) isn’t built in CI. macos-14 only covers arm64, so if you’re still shipping Intel dylibs, they’re not being verified.
Artifact retention isn’t explicitly set (so it defaults to 90 days). That’s fine for now, but could be worth setting it explicitly.
Running Java and Rust in the same Ubuntu job adds quite a bit of setup time. If builds start getting slow, it might make sense to split them into separate jobs.
Review SummaryOverall this is a solid PR — CI pipeline is well-structured (SHA-pinned actions, concurrency groups, Memory leaks in Rust & Java FFI wrappersBoth
For a short-lived benchmark this doesn't matter, but since
Go tests: unchecked
|
|
|
||
| - name: Cross-compile Windows DLL | ||
| run: | | ||
| sudo apt-get install -y gcc-mingw-w64-x86-64 |
There was a problem hiding this comment.
nit: The runner's package index can go stale. Consider adding sudo apt-get update before the install to avoid intermittent resolution failures:
run: |
sudo apt-get update
sudo apt-get install -y gcc-mingw-w64-x86-64Every call to Sign*, GenerateAPIKey, CreateAuthToken, CreateClient, and CheckClient returns structs containing C.CString pointers (malloc'd by the Go shared library). The wrappers copied these strings into managed memory but never called the exported Free() function, leaking the originals. Rust: - Cache the Free symbol as a raw fn pointer on LighterLib::load(). - Pass free_fn into ptr_to_string() and raw_to_signed_tx() so every copied pointer is freed immediately after conversion. - All 22 affected methods now free automatically. Java: - Change String fields to Pointer in StrOrErr, ApiKeyResponse, and SignedTxResponse structs. - Add readAndFree(Lib) helper that reads the string and calls Lib.Free. - Update Example.java to use the new API. C++: - Add Free() calls for all returned char* fields in example.cpp. Co-Authored-By: mihai <mihai2004marcu@gmail.com>
| curl -fsSL "https://raw.githubusercontent.com/golang/go/${GO_VERSION}/lib/wasm/wasm_exec.js" \ | ||
| -o ./build/wasm_exec.js \ | ||
| || curl -fsSL "https://raw.githubusercontent.com/golang/go/${GO_VERSION}/misc/wasm/wasm_exec.js" \ | ||
| -o ./build/wasm_exec.js |
There was a problem hiding this comment.
Why we've changed the approach?
The previous approach (cp from $(go env GOROOT)) was more reliable — the file is already on the runner since Go is installed. This adds an external network call that can fail, and it depends on GOVERSION matching the GitHub tag exactly.
Summary
Adds a CI pipeline and fills in cross-language testing/examples for the signer library.
Took the examples from and put them under examples.
#62
#59
CI (
.github/workflows/ci.yml)CIworkflow that runs on every push, PR, andworkflow_dispatch.build-and-testjob (ubuntu-latest): sets up Go 1.23.1, Node 22, Temurin JDK 21, Rust stable, andjust; runsgo test ./..., thenjust build-linux-local,just build-wasm, the WASM Node smoke test,just build-java, andjust build-rust. Uploads the Linux.so/.h,.wasm, andwasm_exec.jsas artifacts.build-darwinjob (macos-14): runsjust build-darwin-local, compiles the C++ example against the produced.dylib, and uploads the darwin arm64.dylib.Go tests (
client/sign_test.go)TxClient:TestGenerateAPIKey,TestCreateClient, and sign-tests for cancel-order, cancel-all-orders, create-order, create-sub-account, update-leverage, and create-grouped-orders. Asserts tx hashes are deterministic for fixed inputs and that theSkipNonceattribute is correctly toggled viaL2TxAttributes.WASM smoke test (
examples/wasm/test_wasm.mjs)build/lighter-signer.wasmviawasm_exec.js, callsGenerateAPIKey/CreateClient, signs cancel-order, cancel-all-orders, create-order, create-sub-account, and update-leverage txs, and verifiestxType/txHash/ decodedtxInfo. Also togglesskipNonceand asserts the hash andL2TxAttributeschange.Java example (
examples/java/)pom.xml,src/main/java/LighterLib.java,Example.java) with JNA bindings to the shared library and a benchmark that spawns 5 threads, each generating a key, creating a client on chain 304, obtaining a 7h auth token, and signing 100 create/cancel pairs back-to-back.Rust example (
examples/rust/)Cargo.toml,Cargo.lock,src/lib.rs,src/main.rs) with FFI bindings to the shared library and the equivalent 5-thread / 100 create+cancel benchmark.Examples reorg & docs
examples/example.cpptoexamples/cpp/example.cpp.examples/README.mdto document prerequisites, build, and run instructions for C++, Java, Rust, and WASM.justfile: addsbuild-javaandbuild-rustrecipes..gitignore: ignores Java/Rust build outputs.Review & Testing Checklist for Human
build-darwinjob actually produces a working.dylibonmacos-14(the rest of CI currently passes but this macOS runner is new).go test ./...inclient/sign_test.gouses hardcoded keys/nonces that are safe to commit (they look like throwaway test vectors, but worth a second pair of eyes).Notes
on: pushtriggers the workflow for all branches, not just PRs — let me know if you'd rather scope it tomain+ PRs only.Link to Devin session: https://app.devin.ai/sessions/c8654b9063d64a73ae24ad8f31c2ee40
Requested by: @mihaimarcu2004