Skip to content

feat: add build variants - #94

Merged
wemeetagain merged 2 commits into
mainfrom
cayman/variants
Nov 16, 2026
Merged

wemeetagain merged 2 commits into
mainfrom
cayman/variants

Conversation

@wemeetagain

Copy link
Copy Markdown
Member

Lets one package ship several builds of the same addon. Motivation is Lodestar's native bindings, where the consensus preset is a compile-time option: we want mainnet, minimal and gnosis binaries in the same platform package, picked at load time.

  • zapi.variants in package.json maps a variant name to the extra zig build arguments that produce it, e.g. {"mainnet": ["-Dpreset=mainnet"], "minimal": ["-Dpreset=minimal"]}
  • The build step is unchanged and still installs <binaryName>.node. zapi runs it once per variant and stores the result as <binaryName>-<variant>.node
  • build-artifacts builds every variant of every target. Variants of a target build sequentially and share that target's cache
  • prepublish and publish put all variants in each target package. The target package has no main in that case
  • requireNapiLibrary(packageDir, {variant}) loads zig-out/lib/<binaryName>-<variant>.node, then <pkg>-<target>/<binaryName>-<variant>.node. The variant is required when the package declares variants and rejected when it does not
  • zapi build gains --variant, and --prefix so the renamed binary can land where the loader looks

Packages without variants behave as before.

This PR was written primarily by Claude Code.

🤖 Generated with Claude Code

https://claude.ai/code/session_01V21K4w9mTMmW75nFFxksTg

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V21K4w9mTMmW75nFFxksTg
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-14T23:33:52.269381Z 68d731d Draft marked ready
🔒 Security Review ✅ Completed 2026-11-14T23:38:29.623440Z 68d731d Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Comment thread ts/config.ts
binaryName: string;
targets: string[];
step?: string;
variants?: Record<string, string[]>;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have anything else other than presets to be built under variants? otherwise why not name this presets rather than variants. probably better to overspecify than underspecify

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think nazar and myself have a goal of keeping this as a reusable library. Preference towards keeping the variant or somesuch name.

Comment thread ts/build.ts

await build(buildOptions);

if (variant !== undefined) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would we ever want variant to be undefined? Seems like bindings should always ship with a preset anyway. Might be easier to specify, for example, mainnet as a default

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually like the idea that if you define variants, you must specify a variant at load time, ie no default. (Consumer would obviously specify and enforce a default)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test should perhaps be under publishing instead?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to examples/publishing/variants.test.ts in 95151c4.

@matthewkeil matthewkeil moved this from In Progress to Awaiting Author in Lodestar Team Coordination Nov 16, 2026
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V21K4w9mTMmW75nFFxksTg

@spiral-ladder spiral-ladder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@wemeetagain
wemeetagain merged commit 05659c6 into main Nov 16, 2026
5 checks passed
@github-project-automation github-project-automation Bot moved this from Awaiting Author to Done in Lodestar Team Coordination Nov 16, 2026
wemeetagain pushed a commit that referenced this pull request Nov 16, 2026
🤖 I have created a release *beep* *boop*
---


##
[4.5.0](zapi-v4.4.0...zapi-v4.5.0)
(2026-11-16)


### Features

* add build variants
([#94](#94))
([05659c6](05659c6))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants