8000 Add native Apple Silicon (ARM64) support for zap-cli builds by Chapoly1305 · Pull Request #1607 · project-chip/zap · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add native Apple Silicon (ARM64) support for zap-cli builds #1607

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
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Chapoly1305
Copy link
@Chapoly1305 Chapoly1305 commented Jun 14, 2025

Apple Silicon (ARM64) Build Support for ZAP CLI

Problem

Original Issue: project-chip/connectedhomeip#39499
The original build device does not enable Rosetta 2 and resulted in build error.

Solution

Enable experimental support for Apple Silicon. We’ve updated the build configuration to support native ARM64 compilation using the modern pkg tool capabilities.

Build Process

To generate both Intel and ARM64 binaries:

# Install dependencies
npm install

# Build the project
npm run build

# Generate pkg binaries for both architectures
npx pkg -t node18-macos-x64,node18-macos-arm64 --output dist/zap-macos --compress GZip --options max-old-space-size=4096 .

# Package for distribution
npm run pack:cli:mac

Results

Before Changes

  • zap-cli: Intel x86_64 binary (97.7MB)
  • Required Rosetta translation on Apple Silicon
  • Performance penalty due to emulation

After Changes

  • zap-macos-x64: Intel x86_64 binary (93.8MB)
  • zap-macos-arm64: Native ARM64 binary (88.7MB)
  • Native performance on Apple Silicon Macs
  • Smaller binary size for ARM64

Verification

# Check architecture
$ file dist/zap-macos-arm64
dist/zap-macos-arm64: Mach-O 64-bit executable arm64

# Test functionality
$ ./dist/zap-macos-arm64 --version
Version: 2025.6.9
Feature level: 107
Hash: dbe4ed516e82c9a958a31e2e1573d5cd15799657
Date: 2025-06-09T16:41:32.000Z
Mode: binary
Executable: /Users/alex/Downloads/zap/dist/zap-macos-arm64

  - Add node18-macos-arm64 target to pkg configuration in package.json
  - Update pack-cli.js to properly handle ARM64 binary packaging
  - Remove outdated comments about ARM64 limitations
  - Enable native ARM64 compilation alongside existing x64 builds

  This resolves the issue where zap-mac-arm64.zip contained an Intel
  x86_64 binary requiring Rosetta translation on Apple Silicon Macs.
Copy link
@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @Chapoly1305, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request implements native Apple Silicon (ARM64) build support for the zap-cli macOS binary. Previously, the 'arm64' distribution contained an Intel x86_64 binary requiring Rosetta translation. With these changes, a true ARM64 binary is generated and packaged, providing native performance and a smaller size for users on Apple Silicon Macs.

Highlights

  • Native ARM64 Build Target: Added the node18-macos-arm64 target to the pkg configuration in package.json to enable the generation of a native Apple Silicon binary.
  • Updated Packaging Script: Modified src-script/pack-cli.js to correctly identify and package the newly generated zap-macos-arm64 binary into the zap-mac-arm64.zip distribution file, instead of packaging the x64 binary.
  • Removed Outdated Comments: Cleaned up comments in src-script/pack-cli.js that incorrectly stated pkg did not support macOS ARM64 builds.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configureGemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds native Apple Silicon (ARM64) support for zap-cli builds. The key change involves updating the pkg configuration and the pack-cli.js script. A critical adjustment is needed in src-script/pack-cli.js to ensure the x64 binary is correctly renamed to zap-macos-x64, aligning with the expected output of the pkg tool when building for both architectures. Also, the pkg:mac script in package.json must be updated to build both architectures.

Comment on lines +47 to 53
// Handle x64 build
await rename(`${file}`, cli)
await addToZip(`zap-mac-x64.zip`, cli)

// NOTE: `pkg` build tool does not officially support building for mac arch64 yet.
// until official support is out, x86 version will be packaged as
// Apple Rosetta will kick in.
// Handle arm64 build - pkg now supports macos-arm64
await rename(`${file}-arm64`, cli)
await addToZip(`zap-mac-arm64.zip`, cli)

Choose a reason for hiding this comment

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

high

The rename command for the x64 binary should use zap-macos-x64 to align with the expected output of the pkg command when building for both x64 and arm64 architectures. This ensures the script correctly identifies and packages the x64 binary.

Also, ensure that the pkg:mac script in package.json builds both architectures to produce the expected filenames.

Style Guide References

Suggested change
// Handle x64 build
await rename(`${file}`, cli)
await addToZip(`zap-mac-x64.zip`, cli)
// NOTE: `pkg` build tool does not officially support building for mac arch64 yet.
// until official support is out, x86 version will be packaged as
// Apple Rosetta will kick in.
// Handle arm64 build - pkg now supports macos-arm64
await rename(`${file}-arm64`, cli)
await addToZip(`zap-mac-arm64.zip`, cli)
// Handle x64 build
await rename(`zap-macos-x64`, cli)
await addToZip(`zap-mac-x64.zip`, cli)
// Handle arm64 build - pkg now supports macos-arm64
await rename(`zap-macos-arm64`, cli)
await addToZip(`zap-mac-arm64.zip`, cli)

@Chapoly1305
Copy link
Author

Although it seems to work on Apple Silicon, it's still worth to mention the the original repo https://github.com/vercel/pkg states macos-arm64 is experimental. The repo is no longer maintained.

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
0