feat!: error on non-DSL pub fn in exportModule - #38
Merged
Conversation
Zig functions are skipped if they: 1) are not `pub fn`, 2) do not use DSL-compatible types from the `js` module We can't error since we want flexibility to define and use other functions in the same file, so we just add a simple warning to warn the user about this at comptime. This is to avoid future situations encountered here: ChainSafe/lodestar-z#371
Contributor
|
Problem with simple warning is that binding author might not notice it at all, as most of the time there will some CI workflow building buildings, not a human looking at build warnings. And then for binding consumer that warning will be too late to address any solution. |
nazarhussain
approved these changes
May 26, 2026
nazarhussain
added a commit
to ChainSafe/lodestar-z
that referenced
this pull request
Jul 27, 2026
## Motivation zapi v3.0.0 added a lifecycle-managed `js.io()` to the JS DSL (ChainSafe/zapi#26): `js.exportModule` retains a shared `std.Io.Threaded` before the module's `init` hook and releases it after the `cleanup` hook, refcounted across N-API environments. This is the same lifecycle our hand-rolled `bindings/napi/io.zig` implemented, so the local module can be deleted. ## Summary - bump zapi v2.2.0 → v3.0.0 - delete `bindings/napi/io.zig`; replace all `napi_io.get()` call sites with `js.io()` (`blst`, `pubkeys`, `metrics`, `BeaconStateView`, `root`) - drop manual io init/deinit from the `root.zig` lifecycle hooks — ordering is preserved upstream (`retain()` runs before `init`, `release()` after `cleanup`), so `js.io()` is valid during CPU detection at init and thread pool teardown at cleanup ### zapi v3 breaking change v3.0.0 rejects non-DSL `pub fn`s in `exportModule` (ChainSafe/zapi#38) instead of silently skipping them. Internal decls that the exporter walked are now hidden: - `pool.State`, `config.State`, `pubkeys.State`, `config.chainConfigFromObject`: de-pubbed (cross-file access still works through the pub `state` vars; the exporter skips pub vars) - `pool.PoolRc`: de-pubbed; `BeaconStateView.pool_rc` now uses `@TypeOf(pool.state.pool_rc)` - `blst.initThreadPool`/`deinitThreadPool`: moved behind a pub `lifecycle` var so they stay native-only and are no longer silently exported to JS (`deinitThreadPool`, zero-arg, previously *was* reachable from JS; nothing on the TS side used it) ## Validation - `zig build build-lib:bindings` (Debug and ReleaseSafe) - `pnpm test`: all 233 tests pass, including `teardown.test.ts` (clean process exit through the new env-cleanup → io release path, no panic) - `zig fmt --check` on changed files 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
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.
js.exportModulepreviously silently droppedpub fns whose parameters weren't DSL-compatible. That made it easy to ship a function you thought was exported but wasn't (see ChainSafe/lodestar-z#371).Now
exportModuleraises a@compileErrornaming the offending decl.Fix it by one of:
js.Number),pubif the function is a helper not meant for JS,.registertojs.exportModuleto export the function manually.BREAKING CHANGE
Modules with non-DSL
pub fns alongside DSL exports will no longer build.