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

Electron MacOS Universal Build not working #153

Closed
hrueger opened this issue Sep 13, 2022 · 9 comments
Closed

Electron MacOS Universal Build not working #153

hrueger opened this issue Sep 13, 2022 · 9 comments

Comments

@hrueger
Copy link

hrueger commented Sep 13, 2022

Hi @yisibl,
first of all, thanks for this excellent library, it is working really well. I just have the following problem:

I have an Electron app which uses resvg-js. For MacOS it is packaged using electron-builder. The configuration creates a universal build, which means, that the application is packaged for x86 and for arm64 (M1) and then bundled into a single .dmg file. This is done using a GitHub Action running macos-latest.

The problem now is, that when I try to start the App on a M1 Mac, I get the following error:
grafik
As you can see, the binary for darwin arm64 is missing.
It also does not help to add that package to the dependencies manually, because it is not being installed on the build system (the arch in the package.json does not match).

Can I somehow "force" this package to be installed / included?

@hrueger
Copy link
Author

hrueger commented Sep 13, 2022

Could you maybe publish a package which includes both binaries for darwin for universal builds?

@yisibl
Copy link
Owner

yisibl commented Sep 14, 2022

In fact, each platform is a separate package, which we distribute through optionalDependencies. I'm not sure why optionalDependencies is not working in electron, but you can install the binary packages for the Mac platform separately.

All npm packages:
https://github.com/yisibl/resvg-js#support-matrix

@hrueger
Copy link
Author

hrueger commented Sep 14, 2022

Hi @yisibl,
thanks for the quick answer. optionalPackages does work correctly with Electron, the problem is as follows:
In order to make the universal build, electron-builder builds the app for x86, then (on the same machine which in my case is an x86 Mac) for arm64 and then merges the two apps into one installer.
There's no dependency installation step between the build for x64 and arm64 and even if there was one, the arm64 package would not be installed since its running on the x86 platform.
Do you understand what I mean?

Dependencies using node-gyp are handled correctly and rebuild using some emulator mode for arm64.

A darwin-universal package which just has the os requirement in the package.json would be great. It could be added to the dependencies manually if someone wants to build a universal app.

@Brooooooklyn
Copy link
Collaborator

@hrueger I believe you are talking about the cross-compiling scenario. There is no universal binary concept for Node.js addons because Node.js addon is dynamic libraries, not executable binary.

What package manager are you using? See npm/rfcs#519 (comment) for how to install dependencies for cross-compiling.

@hrueger
Copy link
Author

hrueger commented Sep 14, 2022

There is no universal binary concept for Node.js addons because Node.js addon is dynamic libraries, not executable binary.

I know. It is called a universal installer, here's the docs: https://github.com/electron/universal

@hrueger
Copy link
Author

hrueger commented Sep 14, 2022

What package manager are you using? See npm/rfcs#519 (comment) for how to install dependencies for cross-compiling.

Ah, thanks, I somehow couldn't find this. I'm using yarn. This will probably fix the issue, I'll test it and then close this issue.

@yisibl
Copy link
Owner

yisibl commented Sep 14, 2022

@hrueger It looks like you can work around it with yarn or pnpm.

Thanks to @Brooooooklyn's expert advice.

@yisibl
Copy link
Owner

yisibl commented Sep 26, 2022

@hrueger Is your problem solved?

@hrueger
Copy link
Author

hrueger commented Sep 27, 2022

Hm, more or less...
I still haven't found the perfect solution. I'd like to add this to my package.json that yarn install just works on every system. I can't conditionally install it with the supportedArchitectures config entry, because then it screws with other dependencies...
When I tried installing it manually in the CI workflow (on MacOS only), I ran into the error that the lockfile should not be modified in the CI (which does make sense).

But I also agree with you that publishing another package which is almost a duplicate of another packages does not make a lot sense...

For now, I'll just keep my fork up to date.

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

No branches or pull requests

3 participants