Skip to content

Add loongarch64 support#198

Open
wjh-la wants to merge 1 commit intounrs:mainfrom
wjh-la:main
Open

Add loongarch64 support#198
wjh-la wants to merge 1 commit intounrs:mainfrom
wjh-la:main

Conversation

@wjh-la
Copy link

@wjh-la wjh-la commented Jan 10, 2026

Can we increase support for the loongarch64 architecture? I can build a .node file for loongarch64 using Docker image of ubuntu:latest and versions of Zig 0.14.0 and @ napi-rs/cli 3.3.1


Important

Add loongarch64 architecture support and update version handling for native bindings.

  • Architecture Support:
    • Add loongarch64-unknown-linux-gnu and loongarch64-unknown-linux-musl targets in .github/workflows/release-napi.yml and package.json.
    • Update requireNative() in napi/index.js to handle loong64 architecture.
  • Version Handling:
    • Add version mismatch check for native bindings in requireNative() in napi/index.js.
  • Dependencies:
    • Update @napi-rs/cli to version 3.3.1 in package.json.

This description was created by Ellipsis for 4d0b208. You can customize this summary. It will automatically update as commits are pushed.

Summary by CodeRabbit

  • Chores
    • Expanded platform support by adding Loongarch64 targets (GNU/Linux and musl variants) to the build and release pipeline.
    • Updated build tool dependency to the latest version for improved compatibility.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 10, 2026

📝 Walkthrough

Walkthrough

This PR adds support for Loongarch64 architecture targets (GNU/Linux and musl variants) to the NAPI release workflow, configures necessary cross-compilation toolchain for GNU/Linux, and updates the @napi-rs/cli dependency from 3.0.0-alpha.92 to 3.3.1, along with setup-zig action from 0.13.0 to 0.14.0.

Changes

Cohort / File(s) Summary
Release Workflow
.github/workflows/release-napi.yml
Added two Loongarch64 targets (loongarch64-unknown-linux-gnu and loongarch64-unknown-linux-musl) with appropriate cross-compiler setup (gcc-13/g++-13), environment variable exports, and build commands. Updated setup-zig action to version 0.14.0.
Dependencies and Build Configuration
package.json
Bumped @napi-rs/cli devDependency from 3.0.0-alpha.92 to 3.3.1. Extended napi.targets array with loongarch64-unknown-linux-gnu and loongarch64-unknown-linux-musl.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested labels

enhancement, dependencies

Poem

🐰 A rabbit hops with glee so bright,
Loongarch64 targets in the night,
CLI tools updated, workflows refined,
New architectures for all mankind!
Cross-compilers stand at the door,
Supporting systems, more and more! 🚀

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add loongarch64 support' accurately and concisely describes the main change in the pull request, which adds support for the loongarch64 architecture across multiple files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0dd4561 and 848c0b8.

📒 Files selected for processing (2)
  • .github/workflows/release-napi.yml
  • package.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (3)
.github/workflows/release-napi.yml (3)

112-114: LGTM!

The musl target configuration follows the established pattern for other musl-based targets, using Zig for cross-compilation via pnpm build -x.


103-111: Build configuration is correct; loongarch64 cross-compiler packages are available on ubuntu-latest.

The gcc-13-loongarch64-linux-gnu and g++-13-loongarch64-linux-gnu packages are available in Ubuntu 24.04 (Noble) universe repository and can be installed via apt-get. The environment variable naming convention (CC_<target>, CXX_<target>, CARGO_TARGET_<TARGET>_LINKER) follows Cargo's standard for target-specific toolchain configuration. The setup is correct and consistent with loongarch64 cross-compilation requirements, including the Zig 0.14.0 configuration for the musl target.


137-140: Version update is correct and necessary for loongarch64 support.

Zig 0.14.0 is a stable release that adds LoongArch support, including loongarch64-linux (Tier 3). This version bump is required to enable loongarch64-unknown-linux-musl cross-compilation.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Caution

Changes requested ❌

Reviewed everything up to 4d0b208 in 2 minutes and 13 seconds. Click for details.
  • Reviewed 669 lines of code in 3 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. napi/index.js:369
  • Draft comment:
    Ensure correct arch string for loongarch64 support; 'process.arch' might be 'loongarch64' instead of 'loong64'.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 15% vs. threshold = 50% This comment is speculative - it says "might be" without providing evidence that Node.js actually reports 'loongarch64' as a process.arch value. The file is auto-generated by NAPI-RS, so manual changes would likely be overwritten. The comment doesn't provide strong evidence that this is actually an issue - no documentation links, no test cases, no real-world examples. All other architectures in the file use a single canonical name without alternatives. If this were a real issue, it would need to be fixed in the NAPI-RS code generator, not in this generated file. The comment is asking the author to make a change based on speculation rather than demonstrated need. However, it's possible that Node.js does report different arch strings for LoongArch on different systems or versions, and this could be a legitimate compatibility concern. The commenter might have domain knowledge about LoongArch systems that I lack. Even if this is a legitimate concern, the comment violates the rule about not commenting on auto-generated code without strong evidence. The file header clearly states it's auto-generated by NAPI-RS. Any fix would need to be made upstream in the generator, not in this file. Additionally, the comment is speculative ("might be") rather than definitive, which violates the rule against speculative comments. This comment should be deleted. It's speculative without strong evidence, and it's commenting on auto-generated code where manual changes would be inappropriate. If this is a real issue, it needs to be addressed in the NAPI-RS code generator, not in this generated file.
2. napi/index.js:81
  • Draft comment:
    Consider refactoring the repetitive binding version check logic into a helper, to improve maintainability.
  • Reason this comment was not posted:
    Confidence changes required: 50% <= threshold 50% None
3. napi/index.js:575
  • Draft comment:
    Review the error-chaining in the reduce call; modifying 'cur.cause' may not produce the intended nested error chain.
  • Reason this comment was not posted:
    Confidence changes required: 50% <= threshold 50% None
4. .github/workflows/release-napi.yml:107
  • Draft comment:
    Typographical error: 'apt-fet' should be corrected to 'apt-get'.
  • Reason this comment was not posted:
    Marked as duplicate.

Workflow ID: wflow_L6uDecx0v3H10GTm

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

target: loongarch64-unknown-linux-gnu
build: |-
sudo apt-get update &&
sudo apt-fet install gcc-13-loongarch64-linux-gnu g++-13-loongarch64-linux-gnu -y &&
Copy link

Choose a reason for hiding this comment

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

Typo: use apt-get (not apt-fet) in the loongarch64 GNU build step.

Suggested change
sudo apt-fet install gcc-13-loongarch64-linux-gnu g++-13-loongarch64-linux-gnu -y &&
sudo apt-get install gcc-13-loongarch64-linux-gnu g++-13-loongarch64-linux-gnu -y &&

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @.github/workflows/release-napi.yml:
- Around line 103-111: The CI job for target "loongarch64-unknown-linux-gnu"
contains a typo in the build script: replace the misspelled command "apt-fet"
with "apt-get" in the build step so the package installation line runs
correctly; update the build block where the target/environment variables are set
(the block that exports CC_loongarch64_unknown_linux_gnu,
CXX_loongarch64_unknown_linux_gnu, and
CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_GNU_LINKER) to use the corrected
"apt-get" command.
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9480a90 and 4d0b208.

📒 Files selected for processing (3)
  • .github/workflows/release-napi.yml
  • napi/index.js
  • package.json
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2025-06-05T18:52:30.363Z
Learnt from: JounQin
Repo: unrs/unrs-resolver PR: 136
File: src/tests/extension_alias.rs:36-46
Timestamp: 2025-06-05T18:52:30.363Z
Learning: The fixtures/yarn directory in the unrs-resolver project requires running `yarn install` to install TypeScript dependencies before tests can run, similar to other fixture directories like fixtures/pnp. The test in src/tests/extension_alias.rs depends on the installed TypeScript package providing lib/typescript.d.ts and related files.

Applied to files:

  • package.json
  • napi/index.js
📚 Learning: 2025-06-10T13:53:02.983Z
Learnt from: JounQin
Repo: unrs/unrs-resolver PR: 144
File: napi/patch.mjs:5-5
Timestamp: 2025-06-10T13:53:02.983Z
Learning: Build-time scripts in napi/patch.mjs and similar build pipeline contexts don't require error handling for reading expected files like index.js, as these files are guaranteed to be present during the build process.

Applied to files:

  • napi/index.js
📚 Learning: 2025-03-29T04:14:03.715Z
Learnt from: JounQin
Repo: unrs/unrs-resolver PR: 40
File: src/tests/resolve.rs:121-136
Timestamp: 2025-03-29T04:14:03.715Z
Learning: For tests involving npm/yarn package resolution in the unrs-resolver project, dependencies must be installed first using the appropriate package manager commands (pnpm i, yarn) in both the root directory and fixture directories like fixtures/pnp and fixtures/misc/nested-package-json.

Applied to files:

  • napi/index.js
📚 Learning: 2025-04-21T08:11:41.469Z
Learnt from: JounQin
Repo: unrs/unrs-resolver PR: 75
File: fixtures/pnp/package.json:11-14
Timestamp: 2025-04-21T08:11:41.469Z
Learning: The project uses a justfile with an `install` task that includes running yarn in the fixtures/pnp directory to install dependencies with the command: `cd fixtures/pnp && yarn`.

Applied to files:

  • napi/index.js
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (7)
.github/workflows/release-napi.yml (2)

112-114: LGTM!

The loongarch64-unknown-linux-musl target correctly uses the -x flag for Zig cross-compilation, consistent with other musl targets in this workflow.


137-140: Zig version 0.14.0 is confirmed released and stable.

Zig 0.14.0 (released March 5, 2025) includes expanded target support for loongarch64-linux and ships with musl v1.2.5 for musl-based builds. The version specified in the workflow is correct and suitable for the intended musl-target builds.

package.json (2)

31-31: LGTM!

Good upgrade from alpha (3.0.0-alpha.92) to stable (3.3.1) release of @napi-rs/cli.


70-71: LGTM!

The new loongarch64 targets correctly align with the CI workflow matrix entries added in the release workflow.

napi/index.js (3)

1-4: Auto-generated file - limited review scope.

This file is auto-generated by NAPI-RS. The formatting inconsistencies (e.g., lines 111-143) are artifacts of the code generator and not actionable in this PR.


369-402: LGTM!

The loong64 architecture support follows the established pattern used by other architectures in this file, with proper musl/glibc detection and version enforcement checks.


574-579: Error chaining implementation is correct.

The reduce() call safely chains error causes. The guard loadErrors.length > 0 on line 569 ensures the array is never empty when this code executes, avoiding the reduce-on-empty-array pitfall.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
napi/index.js (1)

81-86: Version checking mechanism is well-designed.

The version checking for native bindings adds a valuable safeguard against version mismatches. The opt-in enforcement via NAPI_RS_ENFORCE_VERSION_CHECK ensures backward compatibility while allowing strict validation when needed.

Minor observation about the hardcoded version

The version string '1.11.1' appears in approximately 30 locations throughout the file. Since this is auto-generated code (line 4 comment), this is expected. However, if modifying the generator, consider extracting this to a constant at the top of the file for easier maintenance during version bumps.

This is purely informational since manual edits to auto-generated files would be overwritten.

Also applies to: 97-102, 118-123, 134-139, 151-156, 167-172, 186-191, 202-207, 218-223, 238-243, 254-259, 275-280, 291-296, 309-314, 325-330, 343-348, 359-364, 377-382, 393-398, 411-416, 427-432, 444-449, 460-465, 480-485, 496-501, 512-517

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4d0b208 and 0dd4561.

📒 Files selected for processing (3)
  • .github/workflows/release-napi.yml
  • napi/index.js
  • package.json
🚧 Files skipped from review as they are similar to previous changes (2)
  • .github/workflows/release-napi.yml
  • package.json
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2025-06-10T13:53:02.983Z
Learnt from: JounQin
Repo: unrs/unrs-resolver PR: 144
File: napi/patch.mjs:5-5
Timestamp: 2025-06-10T13:53:02.983Z
Learning: Build-time scripts in napi/patch.mjs and similar build pipeline contexts don't require error handling for reading expected files like index.js, as these files are guaranteed to be present during the build process.

Applied to files:

  • napi/index.js
📚 Learning: 2025-03-29T04:14:03.715Z
Learnt from: JounQin
Repo: unrs/unrs-resolver PR: 40
File: src/tests/resolve.rs:121-136
Timestamp: 2025-03-29T04:14:03.715Z
Learning: For tests involving npm/yarn package resolution in the unrs-resolver project, dependencies must be installed first using the appropriate package manager commands (pnpm i, yarn) in both the root directory and fixture directories like fixtures/pnp and fixtures/misc/nested-package-json.

Applied to files:

  • napi/index.js
📚 Learning: 2025-04-21T08:11:41.469Z
Learnt from: JounQin
Repo: unrs/unrs-resolver PR: 75
File: fixtures/pnp/package.json:11-14
Timestamp: 2025-04-21T08:11:41.469Z
Learning: The project uses a justfile with an `install` task that includes running yarn in the fixtures/pnp directory to install dependencies with the command: `cd fixtures/pnp && yarn`.

Applied to files:

  • napi/index.js
📚 Learning: 2025-06-05T18:52:30.363Z
Learnt from: JounQin
Repo: unrs/unrs-resolver PR: 136
File: src/tests/extension_alias.rs:36-46
Timestamp: 2025-06-05T18:52:30.363Z
Learning: The fixtures/yarn directory in the unrs-resolver project requires running `yarn install` to install TypeScript dependencies before tests can run, similar to other fixture directories like fixtures/pnp. The test in src/tests/extension_alias.rs depends on the installed TypeScript package providing lib/typescript.d.ts and related files.

Applied to files:

  • napi/index.js
🧬 Code graph analysis (1)
napi/index.js (3)
napi/resolver.wasi.cjs (1)
  • require (9-9)
src/lib.rs (1)
  • require (333-348)
napi/wasi-worker.mjs (2)
  • require (7-7)
  • require (9-9)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (4)
napi/index.js (4)

369-402: LGTM! Loongarch64 support correctly implemented.

The loongarch64 architecture support (Node.js arch name loong64) follows the established pattern for other architectures, with proper musl/gnu libc detection and fallback to npm packages with version checking. This aligns with the PR objectives and is consistent with the targets added to the release workflow.


111-143: MINGW detection correctly implemented.

The MINGW detection for Windows x64 properly distinguishes between GNU and MSVC builds using safe optional chaining. The nested structure ensures the correct binding is loaded based on the runtime environment.


532-557: WASI fallback handling improved with proper error chaining.

The WASI binding logic now includes proper error tracking with wasiBindingError and cascading fallbacks between local and npm packages. The new forced error mode (NAPI_RS_FORCE_WASI === 'error') provides explicit failure when WASI is required but unavailable, with proper cause chaining for debugging.


574-579: Error aggregation provides excellent debugging context.

The error chaining using reduce creates a linked list of all load failures, with each error's cause property pointing to the previous failure. This provides comprehensive debugging information when native bindings cannot be loaded.

@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant