-
Notifications
You must be signed in to change notification settings - Fork 0
WIP: Add Nix build infrastructure with Crane #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
amackillop
wants to merge
10
commits into
main
Choose a base branch
from
austin/nix-build
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2479964
Add Nix build infrastructure with Crane
amackillop d234a09
Fix Nix cross-compilation and native addon naming
amackillop fafee54
Fix Darwin SDK and update macOS CI runner
amackillop 85c1f4e
Refactor flake.nix to reduce duplication
amackillop ba56724
Fix darwin build and improve CI package evaluation
amackillop 29c7275
Fix install phase to find library in Crane output
amackillop 3ceae26
Add Crane dependency caching for faster builds
amackillop ff6a51e
Remove armv7 Android target and limit CI parallelism
amackillop a1e9403
Consolidate Android build into Linux matrix job
amackillop 23f2927
Limit CI parallelism and improve install phase error handling
amackillop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| [target.aarch64-unknown-linux-musl] | ||
| linker = "aarch64-linux-musl-gcc" | ||
| rustflags = ["-C", "target-feature=-crt-static"] | ||
| # Native Linux builds: use mold for faster linking | ||
| [target.'cfg(target_os = "linux")'] | ||
| rustflags = ["-C", "link-arg=-fuse-ld=mold"] | ||
|
|
||
| # Cross-compilation settings for CI (yarn build) | ||
| # These are used by GitHub Actions, not by Nix builds | ||
| [target.x86_64-pc-windows-msvc] | ||
| rustflags = ["-C", "target-feature=+crt-static"] | ||
| rustflags = ["-C", "target-feature=+crt-static"] | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| use flake | ||
|
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| name: Nix | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| paths-ignore: | ||
| - "**/*.md" | ||
| - LICENSE | ||
| - .editorconfig | ||
| - docs/** | ||
| pull_request: | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| check: | ||
| name: Flake Check | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Install Nix | ||
| uses: DeterminateSystems/nix-installer-action@main | ||
|
|
||
| - name: Enable Nix cache | ||
| uses: DeterminateSystems/magic-nix-cache-action@main | ||
|
|
||
| - name: Check flake | ||
| uses: DeterminateSystems/flake-checker-action@main | ||
|
|
||
| - name: Verify all packages evaluate | ||
| run: nix flake check --all-systems --no-build | ||
|
|
||
| - name: Run checks (clippy, rustfmt, build) | ||
| run: nix flake check | ||
|
|
||
| build-linux: | ||
| name: Build - ${{ matrix.target }} | ||
| runs-on: ubuntu-latest | ||
| needs: check | ||
| strategy: | ||
| fail-fast: false | ||
| max-parallel: 1 | ||
| matrix: | ||
| target: | ||
| - x86_64_unknown_linux_gnu | ||
| - aarch64_unknown_linux_gnu | ||
| - x86_64_unknown_linux_musl | ||
| - aarch64_unknown_linux_musl | ||
| - aarch64_linux_android | ||
| include: | ||
| # x86_64 glibc uses 'default' - the native build on ubuntu runners | ||
| - target: x86_64_unknown_linux_gnu | ||
| package: default | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Install Nix | ||
| uses: DeterminateSystems/nix-installer-action@main | ||
|
|
||
| - name: Enable Nix cache | ||
| uses: DeterminateSystems/magic-nix-cache-action@main | ||
|
|
||
| - name: Build ${{ matrix.target }} | ||
| run: nix build .#${{ matrix.package || matrix.target }} --print-out-paths | ||
|
|
||
| - name: List output | ||
| run: | | ||
| ls -la result/lib/ | ||
| file result/lib/*.node | ||
|
|
||
| - name: Upload artifact | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: bindings-${{ matrix.target }} | ||
| path: result/lib/*.node | ||
| if-no-files-found: error | ||
|
|
||
| build-macos: | ||
| name: Build - ${{ matrix.target }} | ||
| runs-on: ${{ matrix.runner }} | ||
| needs: check | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| include: | ||
| - target: darwin-arm64 | ||
| runner: macos-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Install Nix | ||
| uses: DeterminateSystems/nix-installer-action@main | ||
|
|
||
| - name: Enable Nix cache | ||
| uses: DeterminateSystems/magic-nix-cache-action@main | ||
|
|
||
| - name: Build | ||
| run: nix build --print-out-paths | ||
|
|
||
| - name: List output | ||
| run: | | ||
| ls -la result/lib/ | ||
| file result/lib/*.node | ||
|
|
||
| - name: Upload artifact | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: bindings-${{ matrix.target }} | ||
| path: result/lib/*.node | ||
| if-no-files-found: error | ||
|
|
||
| # Disable publish for now | ||
| publish: | ||
| if: false | ||
| name: Publish | ||
| runs-on: ubuntu-latest | ||
| needs: | ||
| - check | ||
| - build-linux | ||
| - build-macos | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup node | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 22 | ||
| cache: yarn | ||
|
|
||
| - name: Install dependencies | ||
| run: yarn install | ||
|
|
||
| - name: Download all artifacts | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| path: artifacts | ||
|
|
||
| - name: List downloaded artifacts | ||
| run: ls -R artifacts/ | ||
|
|
||
| - name: Move artifacts to npm directories | ||
| run: | | ||
| # Copy all .node files from artifacts to current directory | ||
| # Nix outputs match NAPI-RS naming: lightning-js.{platform}.node | ||
| find artifacts -name "*.node" -exec cp {} . \; | ||
|
|
||
| # List what we have | ||
| ls -la lightning-js.*.node | ||
|
|
||
| # Run NAPI-RS artifacts command to move files to npm/ subdirectories | ||
| yarn artifacts | ||
|
|
||
| - name: List packages | ||
| run: ls -R ./npm | ||
|
|
||
| - name: Publish | ||
| run: | | ||
| npm config set provenance true | ||
| if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$"; | ||
| then | ||
| echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc | ||
| npm publish --access public | ||
| elif git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+"; | ||
| then | ||
| echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc | ||
| npm publish --tag next --access public | ||
| else | ||
| echo "Not a release, skipping publish" | ||
| fi | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,7 +117,6 @@ dist | |
| #Added by cargo | ||
|
|
||
| /target | ||
| Cargo.lock | ||
|
|
||
| *.node | ||
| .pnp.* | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All Linux targets now inherit
-fuse-ld=mold, but the Nix cross/musl packages only addpkg-configtonativeBuildInputs(see mkCrossPackage/mkMuslPackage in flake.nix) and Nix builds run in a pure environment. That meansnix build .#x86_64_unknown_linux_muslor.#aarch64_unknown_linux_muslwill fail at link time becausemoldis not in PATH. Either scope the mold flag to builds that include mold, or add mold to the cross/musl build inputs.Useful? React with 👍 / 👎.