Skip to content
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

Darwin universal architecture #1397

Merged
merged 8 commits into from Dec 19, 2022
Merged

Conversation

skirsdeda
Copy link
Contributor

TLDR: adds third 'universal' synthetic arch for macOS which combines x64/arm64 binaries into a universal binary and produces a single npm subdependency which is only tied to OS as opposed to OS/CPU combo.

Motivation

I am using napi-rs to create native macOS extension for electron App. It was working fine when building electron bundle on x64 host for x64 target, but I am now switching to arm64 host while still building for x64 target. This doesn't work due to the way how npm resolves optional dependencies and there's no good way to install x64 optional dependency on arm64 host. So instead of hacking something to workaround this, I decided it would be better to have an option to build universal binaries in napi-rs. That way, I will be able to build for both x64 and universal targets on arm64.

Implementation

  • new triple 'universal-apple-darwin'
  • new cli command 'universal' to combine x64/arm64 binaries
  • index.js changes to first try universal before going for x64/arm64
  • ci template changes as well as some unrelated fixes (typos and unnecessary stuff removed for darwin-arm64)

Future considerations

Whenever nodejs becomes officially available for Windows on ARM, this could be extended to also support universal windows binaries.

And huge thanks for creating napi-rs, BTW 💯 It is perfect for me 😸

@CMCDragonkai
Copy link

To make use of this, can we just use the option napi build --target universal-darwin-apple?

Because I'm getting this atm:

  error: Error loading target specification: Could not find specification for target "universal-apple-darwin". Run `rustc --print target-list` for a list of built-in targets

What is the purpose of the new universal command?

@CMCDragonkai
Copy link

Oh I think I understand, we have to build the x64 and arm64 separately...

Then we can try to combine them:

new cli command 'universal' to combine x64/arm64 binaries

It's possible for an x64 macos to build the arm64 binary too right?

@Brooooooklyn
Copy link
Sponsor Member

It's possible for an x64 macos to build the arm64 binary too right?

Yes

@CMCDragonkai
Copy link

Ok I've built 2 binaries.. But I've renamed them to what I want to use them for.

cmcdragonkai@matrix-mac-1 js-quic % ls prebuild/ 
quic-darwin-arm64.node	quic-darwin-x64.node

Now if I try to use napi universal -d prebuild. I just get an error about config.

Any docs about how this is supposed to be used? I see that the code seems to expect that the names of the binaries have to be specific. Can this command be made a bit more generic so I can just pass the binaries that I want combined?

@skirsdeda
Copy link
Contributor Author

@CMCDragonkai cli command was made to work with Github Actions. Dependence on source filenames is because that's how particular platform/arch binaries are looked up. If it doesn't fit your use-case, you can just use lipo on macOS directly.

kodiakhq bot pushed a commit to X-oss-byte/Canary-nextjs that referenced this pull request Sep 25, 2023
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [@napi-rs/cli](https://togithub.com/napi-rs/napi-rs) | [`2.13.3` -> `2.16.3`](https://renovatebot.com/diffs/npm/@napi-rs%2fcli/2.13.3/2.16.3) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@napi-rs%2fcli/2.16.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@napi-rs%2fcli/2.16.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@napi-rs%2fcli/2.13.3/2.16.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@napi-rs%2fcli/2.13.3/2.16.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>napi-rs/napi-rs (@&#8203;napi-rs/cli)</summary>

### [`v2.16.3`](https://togithub.com/napi-rs/napi-rs/releases/tag/%40napi-rs/cli%402.16.3)

[Compare Source](https://togithub.com/napi-rs/napi-rs/compare/@napi-rs/cli@2.16.2...@napi-rs/cli@2.16.3)

#### What's Changed

-   chore: upgrade npm dependencies by [@&#8203;Brooooooklyn](https://togithub.com/Brooooooklyn) in [napi-rs/napi-rs#1658
-   fix(cli): zig 0.11 link args by [@&#8203;Brooooooklyn](https://togithub.com/Brooooooklyn) in [napi-rs/napi-rs#1698

**Full Changelog**: https://github.com/napi-rs/napi-rs/compare/[@&#8203;napi-rs/cli](https://togithub.com/napi-rs/cli)[@&#8203;2](https://togithub.com/2).16.2...[@&#8203;napi-rs/cli](https://togithub.com/napi-rs/cli)[@&#8203;2](https://togithub.com/2).16.3

### [`v2.16.2`](https://togithub.com/napi-rs/napi-rs/releases/tag/%40napi-rs/cli%402.16.2)

[Compare Source](https://togithub.com/napi-rs/napi-rs/compare/@napi-rs/cli@2.16.1...@napi-rs/cli@2.16.2)

#### What's Changed

-   fix(cli): ts constEnum option not working when set in package.json by [@&#8203;pengx17](https://togithub.com/pengx17) in [napi-rs/napi-rs#1647

#### New Contributors

-   [@&#8203;pengx17](https://togithub.com/pengx17) made their first contribution in [napi-rs/napi-rs#1647

**Full Changelog**: https://github.com/napi-rs/napi-rs/compare/[@&#8203;napi-rs/cli](https://togithub.com/napi-rs/cli)[@&#8203;2](https://togithub.com/2).16.1...[@&#8203;napi-rs/cli](https://togithub.com/napi-rs/cli)[@&#8203;2](https://togithub.com/2).16.2

### [`v2.16.1`](https://togithub.com/napi-rs/napi-rs/compare/@napi-rs/cli@2.16.0...@napi-rs/cli@2.16.1)

[Compare Source](https://togithub.com/napi-rs/napi-rs/compare/@napi-rs/cli@2.16.0...@napi-rs/cli@2.16.1)

### [`v2.16.0`](https://togithub.com/napi-rs/napi-rs/releases/tag/%40napi-rs/cli%402.16.0)

[Compare Source](https://togithub.com/napi-rs/napi-rs/compare/@napi-rs/cli@2.15.2...@napi-rs/cli@2.16.0)

#### What's Changed

-   feat(cli): support --profile flag by [@&#8203;Brooooooklyn](https://togithub.com/Brooooooklyn)  napi-rs/napi-rs@dfbe464

**Full Changelog**: https://github.com/napi-rs/napi-rs/compare/[@&#8203;napi-rs/cli](https://togithub.com/napi-rs/cli)[@&#8203;2](https://togithub.com/2).15.2...[@&#8203;napi-rs/cli](https://togithub.com/napi-rs/cli)[@&#8203;2](https://togithub.com/2).16.0

### [`v2.15.2`](https://togithub.com/napi-rs/napi-rs/releases/tag/%40napi-rs/cli%402.15.2)

[Compare Source](https://togithub.com/napi-rs/napi-rs/compare/@napi-rs/cli@2.15.1...@napi-rs/cli@2.15.2)

#### What's Changed

-   fix(cli,napi-derive): backward compatible with older cli with [#&#8203;1531](https://togithub.com/napi-rs/napi-rs/issues/1531) by [@&#8203;Brooooooklyn](https://togithub.com/Brooooooklyn) in [napi-rs/napi-rs#1536

**Full Changelog**: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.12.1...[@&#8203;napi-rs/cli](https://togithub.com/napi-rs/cli)[@&#8203;2](https://togithub.com/2).15.2

### [`v2.15.1`](https://togithub.com/napi-rs/napi-rs/releases/tag/%40napi-rs/cli%402.15.1)

[Compare Source](https://togithub.com/napi-rs/napi-rs/compare/@napi-rs/cli@2.15.0...@napi-rs/cli@2.15.1)

#### What's Changed

-   fix(cli,napi-derive): re-export types from shared crate by [@&#8203;Brooooooklyn](https://togithub.com/Brooooooklyn) in [napi-rs/napi-rs#1531
-   fix(cli): dts pipe by [@&#8203;Brooooooklyn](https://togithub.com/Brooooooklyn) in [napi-rs/napi-rs#1532

**Full Changelog**: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.12.0...[@&#8203;napi-rs/cli](https://togithub.com/napi-rs/cli)[@&#8203;2](https://togithub.com/2).15.1

### [`v2.15.0`](https://togithub.com/napi-rs/napi-rs/releases/tag/%40napi-rs/cli%402.15.0)

[Compare Source](https://togithub.com/napi-rs/napi-rs/compare/@napi-rs/cli@2.14.8...@napi-rs/cli@2.15.0)

#### What's Changed

-   fix(cli): export non const enums when generating typedefs by [@&#8203;nebarf](https://togithub.com/nebarf) in [napi-rs/napi-rs#1527
-   fix(napi): ThreadsafeFunctionHandle never being dropped by [@&#8203;Brooooooklyn](https://togithub.com/Brooooooklyn) in [napi-rs/napi-rs#1530
-   feat: export registers in wasm32 target by [@&#8203;Brooooooklyn](https://togithub.com/Brooooooklyn) in [napi-rs/napi-rs#1529

#### New Contributors

-   [@&#8203;meowtec](https://togithub.com/meowtec) made their first contribution in [napi-rs/napi-rs#1525
-   [@&#8203;nebarf](https://togithub.com/nebarf) made their first contribution in [napi-rs/napi-rs#1527
-   [@&#8203;victorteokw](https://togithub.com/victorteokw) made their first contribution in [napi-rs/napi-rs#1526

**Full Changelog**: https://github.com/napi-rs/napi-rs/compare/napi@2.11.4...[@&#8203;napi-rs/cli](https://togithub.com/napi-rs/cli)[@&#8203;2](https://togithub.com/2).15.0

### [`v2.14.8`](https://togithub.com/napi-rs/napi-rs/releases/tag/%40napi-rs/cli%402.14.8)

[Compare Source](https://togithub.com/napi-rs/napi-rs/compare/@napi-rs/cli@2.14.7...@napi-rs/cli@2.14.8)

##### Bug Fixes

-   **cli:** always generate typedef file even native code never changes ([#&#8203;1489](https://togithub.com/napi-rs/napi-rs/issues/1489)) ([7281f53](https://togithub.com/napi-rs/napi-rs/commit/7281f533bd73d6c6255244c9f1556a0e39c47738))

### [`v2.14.7`](https://togithub.com/napi-rs/napi-rs/releases/tag/%40napi-rs/cli%402.14.7)

[Compare Source](https://togithub.com/napi-rs/napi-rs/compare/@napi-rs/cli@2.14.6...@napi-rs/cli@2.14.7)

##### Bug Fixes

-   **cli:** JS bindgen file now respects destDir ([#&#8203;1481](https://togithub.com/napi-rs/napi-rs/issues/1481)) ([cb529d2](https://togithub.com/napi-rs/napi-rs/commit/cb529d21cf92dfaa279bfe10dde5ad87441b47ba))

### [`v2.14.6`](https://togithub.com/napi-rs/napi-rs/releases/tag/%40napi-rs/cli%402.14.6)

[Compare Source](https://togithub.com/napi-rs/napi-rs/compare/@napi-rs/cli@2.14.5...@napi-rs/cli@2.14.6)

**Note:** Version bump only for package [@&#8203;napi-rs/cli](https://togithub.com/napi-rs/cli)

### [`v2.14.5`](https://togithub.com/napi-rs/napi-rs/releases/tag/%40napi-rs/cli%402.14.5)

[Compare Source](https://togithub.com/napi-rs/napi-rs/compare/@napi-rs/cli@2.14.4...@napi-rs/cli@2.14.5)

##### Bug Fixes

-   **cli:** upload GitHub assets issue ([a302c9c](https://togithub.com/napi-rs/napi-rs/commit/a302c9cb18710d8d71045d11780f09d4eaf1ecde))

### [`v2.14.4`](https://togithub.com/napi-rs/napi-rs/releases/tag/%40napi-rs/cli%402.14.4)

[Compare Source](https://togithub.com/napi-rs/napi-rs/compare/@napi-rs/cli@2.14.3...@napi-rs/cli@2.14.4)

##### Bug Fixes

-   **napi:** build error with zig@0.10.1 ([2f52793](https://togithub.com/napi-rs/napi-rs/commit/2f527938b27074116a89b9248e218a2ed073be34))

### [`v2.14.3`](https://togithub.com/napi-rs/napi-rs/releases/tag/%40napi-rs/cli%402.14.3)

[Compare Source](https://togithub.com/napi-rs/napi-rs/compare/@napi-rs/cli@2.14.2...@napi-rs/cli@2.14.3)

#### What's Changed

-   Fix broken zig behaviors by [@&#8203;controversial](https://togithub.com/controversial) in [napi-rs/napi-rs#1432

#### New Contributors

-   [@&#8203;controversial](https://togithub.com/controversial) made their first contribution in [napi-rs/napi-rs#1432

**Full Changelog**: https://github.com/napi-rs/napi-rs/compare/napi@2.10.6...[@&#8203;napi-rs/cli](https://togithub.com/napi-rs/cli)[@&#8203;2](https://togithub.com/2).14.3

### [`v2.14.2`](https://togithub.com/napi-rs/napi-rs/releases/tag/%40napi-rs/cli%402.14.2)

[Compare Source](https://togithub.com/napi-rs/napi-rs/compare/@napi-rs/cli@2.14.1...@napi-rs/cli@2.14.2)

#### What's Changed

-   Fix CARGO env var in `napi build` by [@&#8203;overlookmotel](https://togithub.com/overlookmotel) in [napi-rs/napi-rs#1426

**Full Changelog**: https://github.com/napi-rs/napi-rs/compare/napi@2.10.5...[@&#8203;napi-rs/cli](https://togithub.com/napi-rs/cli)[@&#8203;2](https://togithub.com/2).14.2

### [`v2.14.1`](https://togithub.com/napi-rs/napi-rs/releases/tag/%40napi-rs/cli%402.14.1)

[Compare Source](https://togithub.com/napi-rs/napi-rs/compare/@napi-rs/cli@2.14.0...@napi-rs/cli@2.14.1)

#### What's Changed

-   \[Fix] Quote toml path by [@&#8203;TheBrenny](https://togithub.com/TheBrenny) in [napi-rs/napi-rs#1410
-   chore(cli): update CI template by [@&#8203;Brooooooklyn](https://togithub.com/Brooooooklyn) in [napi-rs/napi-rs#1416

#### New Contributors

-   [@&#8203;TheBrenny](https://togithub.com/TheBrenny) made their first contribution in [napi-rs/napi-rs#1410

**Full Changelog**: https://github.com/napi-rs/napi-rs/compare/napi@2.10.4...[@&#8203;napi-rs/cli](https://togithub.com/napi-rs/cli)[@&#8203;2](https://togithub.com/2).14.1

### [`v2.14.0`](https://togithub.com/napi-rs/napi-rs/releases/tag/%40napi-rs/cli%402.14.0)

[Compare Source](https://togithub.com/napi-rs/napi-rs/compare/@napi-rs/cli@2.13.3...@napi-rs/cli@2.14.0)

#### What's Changed

-   feat(cli): `Darwin` universal architecture by [@&#8203;skirsdeda](https://togithub.com/skirsdeda) in [napi-rs/napi-rs#1397
-   feat(cli): add --zig-link-only option by [@&#8203;Brooooooklyn](https://togithub.com/Brooooooklyn) in [napi-rs/napi-rs#1400

#### New Contributors

-   [@&#8203;skirsdeda](https://togithub.com/skirsdeda) made their first contribution in [napi-rs/napi-rs#1397

**Full Changelog**: https://github.com/napi-rs/napi-rs/compare/napi@2.10.3...[@&#8203;napi-rs/cli](https://togithub.com/napi-rs/cli)[@&#8203;2](https://togithub.com/2).14.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/X-oss-byte/Canary-nextjs).
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.

None yet

3 participants