Skip to content

Build Node release binaries with Bazel - #1416

Merged
BYVoid merged 1 commit into
masterfrom
use-bazel-for-node-release-binaries
Jul 9, 2026
Merged

BYVoid merged 1 commit into
masterfrom
use-bazel-for-node-release-binaries

Conversation

@BYVoid

@BYVoid BYVoid commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Summary

  • add a target-driven Bazel prebuild script for OpenCC Node scoped binary packages
  • switch the opencc npm binary release jobs from npm run prebuild to the Bazel script
  • keep binding.gyp / node-gyp-build as the source-build fallback and document the split

Verification

  • ./scripts/build-node-prebuild-bazel.sh darwin-arm64
  • PREBUILDS_ONLY=1 npm test
  • npm run prepare:scoped-packages
  • npm pack --dry-run dist/scoped-packages/@opencc/opencc-darwin-arm64
  • npm pack --dry-run
  • bazel test --test_output=errors //node/test:node_test
  • bash -n scripts/build-node-prebuild-bazel.sh scripts/build-node-windows-prebuild-zig.sh
  • YAML parse for .github/workflows/release-npm.yml and .github/workflows/release-npm-binaries.yml

@BYVoid
BYVoid force-pushed the use-bazel-for-node-release-binaries branch from 0c9e342 to c789449 Compare July 9, 2026 04:49
Use the Bazel Node addon target to produce npm scoped binary package artifacts while keeping the existing node-gyp source fallback for unsupported platforms.
@BYVoid
BYVoid force-pushed the use-bazel-for-node-release-binaries branch from c789449 to 508f692 Compare July 9, 2026 04:51
@BYVoid
BYVoid marked this pull request as ready for review July 9, 2026 04:57
@frankslin

Copy link
Copy Markdown
Collaborator

Have you compared if the binary sizes are similar generated from both systems? Are the diffs explainable?

@BYVoid

BYVoid commented Jul 9, 2026

Copy link
Copy Markdown
Owner Author

我比較了一下,差異看起來是可解釋的,而且沒有看到 package size 方面的異常。

比較方式:

  • 舊版:npm registry 上現有 @opencc/opencc-<target>@1.4.0,也就是目前 release binary package。
  • 新版:這個 PR 的 dry-run workflow 產物,run 28994929092,版本 1.4.0-bazel-test.3。

結果如下:

target old tgz new tgz tgz delta old opencc.node new opencc.node node delta
linux-x64 401.9 KiB 350.4 KiB -12.8% 1060.6 KiB 950.6 KiB -10.4%
linux-arm64 376.7 KiB 334.1 KiB -11.3% 1032.4 KiB 898.5 KiB -13.0%
darwin-arm64 277.2 KiB 277.4 KiB +0.1% 736.3 KiB 883.0 KiB +19.9%
darwin-x64 300.4 KiB 292.8 KiB -2.5% 753.8 KiB 908.6 KiB +20.5%
win32-x64 366.2 KiB 258.3 KiB -29.5% 752.5 KiB 566.5 KiB -24.7%

Linux/Windows 的 binary 和 package 都變小。macOS 的未壓縮 .node 變大約 20%,但壓縮後的 .tgz 幾乎不變或略小。

我也看了 macOS 差異:舊 gyp 產物是 Mach-O bundle;Bazel 產物是 Mach-O dylib,會多一個 LC_ID_DYLIB install name,並且 __LINKEDIT 比舊產物大。otool -L 第一行的 @rpath/libopencc_shared.dylib 是這個 dylib 自己的 LC_ID_DYLIB,不是外部 load dependency;實際 LC_LOAD_DYLIB 只有系統庫(libc++、libSystem,以及 Bazel toolchain 帶出的 Foundation/objc)。我也把 dry-run 的 @opencc/opencc-darwin-arm64 package 安裝到乾淨 temp 目錄後直接 require() 裡面的 opencc.node,可以正常載入。

另外本機同 commit 也比較了 node-gyp rebuild 和 bazel build -c opt //node:opencc 的 darwin-arm64 產物:gyp 是 Mach-O bundle,Bazel 是 Mach-O dylib;Bazel 產物在本機未壓縮大小反而更小(約 898 KiB vs 1.2 MiB,這裡 gyp 沒有走 prebuildify 的 strip 後包裝路徑)。所以我認為目前 release package 的 size diff 是合理且可解釋的。

@BYVoid

BYVoid commented Jul 9, 2026

Copy link
Copy Markdown
Owner Author

我又補了一輪真正的 end-to-end prebuilt 驗證,用 GitHub Actions hosted runners 當臨時 VM 跑了五個平台:

  • linux-x64 on ubuntu-24.04
  • linux-arm64 on ubuntu-24.04-arm
  • darwin-arm64 on macos-15
  • darwin-x64 on macos-15-intel
  • win32-x64 on windows-2025

驗證 run: https://github.com/BYVoid/OpenCC/actions/runs/28997678352

每個平台的測試流程都是:

  1. 從這個 PR 的 dry-run release workflow 下載對應的 @opencc/opencc-<platform>-<arch> scoped prebuilt package。
  2. 在 runner 上打 main opencc package,但安裝測試時使用 npm install --ignore-scripts --omit=optional,避免 fallback 到 source build。
  3. 在乾淨 test project 裡安裝 main package + matching scoped prebuilt package。
  4. 用 process.report.getReport().sharedObjects 確認實際載入的 opencc.node 來自 @opencc/opencc-<platform>-<arch> scoped package。
  5. 跑 CJS API、ESM import、CLI、以及 OpenCC.fromConfig() 轉換測試。

五個 matrix jobs 都通過,所以目前看起來這些 Bazel 產出的 prebuilt addons 不只是能 build/pack,也能在對應平台乾淨安裝後端到端使用。

@BYVoid
BYVoid merged commit 7296554 into master Jul 9, 2026
54 checks passed
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.

2 participants