-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 universal builds for macOS only include the .dylib file for a single architecture #3622
Comments
sharp does not provide universal binaries for macOS. Does the following change to electron-builder.js do what you need? - arch: 'universal',
+ arch: ['x64', 'arm64'], In summary, you need to get it to run the same commands as the final example in https://sharp.pixelplumbing.com/install#cross-platform I note you commented on electron-userland/electron-builder#5689 where this has been discussed previously, and which may still be relevant. |
Thanks for your reply @lovell. If I understand correctly the only option we have is to build an entirely separate installer for ARM64 - but our build process doesn't depend on universal binaries per se, so I still feel confused about why (and whether) this truly isn't possible. I don't know how familiar you are with the workings of Rather than using universal binaries, From their README:
So, since prebuilt libvips binaries are available for both architectures, it should be possible to include both architectures in the app with that approach, no? The If simply getting the ARM64 libvips binary bundled into the proper location would fix this, then I'm thinking I need to continue this with |
Ah I see, so "universal" in Electron parlance doesn't refer to a single "fat" dylib for multiple architectures. sharp supports multiple architectures and platforms in the same installation tree so in theory I guess it can work, but I don't know enough about the internals of electron-builder/universal to say what's missing here. |
@slapbox Were you able to make any progress with this? |
Thanks for the follow-up @lovell! I see I forgot to link the issue I created here. I think if this issue is addressed in So I think there's nothing to do on the Sharp side for now. |
@slapbox Thank you for your tireless efforts on this issue. Currently, I also encountered this problem and tried many methods but none of them worked. |
It does, Ref: https://github.com/electron/universal/blob/main/src/index.ts#L163-L169 |
@mmaietta and @lovell - thank you for your patience with all of my posts while I worked through this issue on multiple fronts. I wonder if you have any thoughts on how to approach a final resolution for this issue in light of this comment from @MarshallOfSound which outlines the problem - copied below:
|
@slapbox please try this
|
@slapbox If you're going down the universal binary route, have you tried building your own libvips dylib via npm install --platform=darwin --arch=x64 sharp
npm rebuild --platform=darwin --arch=arm64 sharp
lipo node_modules/sharp/vendor/8.14.2/darwin-x64/lib/libvips-cpp.dylib.42 node_modules/sharp/vendor/8.14.2/darwin-arm64/lib/libvips-cpp.dylib.42 -create -output ... You might also need to verify or set Otherwise I'd stick to shipping multiple single-architecture files and let sharp (continue to) select the most relevant at runtime. |
Thanks so much to both of you for your help in addition to all of the great works you've already shared; I appreciate it a lot! @lovell thanks for the idea! I'll keep that in mind, but I'm hoping to avoid it as I have only a superficial knowledge of the required tools and ideas and it seems like we're closer than I'd thought to having this working thanks for your suggestion about @mmaietta I tried your patch but it seems that I'm unable to get Sharp to rebuild from source with or without the patch - perhaps due to not having the Note that this image is the state of the If I run @mmaietta this is the output of the build command when enabling Without patchTOUCH Release/obj.target/libvips-cpp.stamp CC(target) Release/obj.target/nothing/node_modules/node-addon-api/nothing.o LIBTOOL-STATIC Release/nothing.a warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: archive library: Release/nothing.a the table of contents is empty (no object file members in the library define global symbols) CXX(target) Release/obj.target/sharp-darwin-x64/src/common.o ../src/common.cc:13:10: fatal error: 'vips/vips8' file not found #include ^~~~~~~~~~~~ 1 error generated. make: *** [Release/obj.target/sharp-darwin-x64/src/common.o] Error 1 Error: `make` failed with exit code: 2 at ChildProcess.onExit (/Users/me/Documents/project/node_modules/node-gyp/lib/build.js:203:23) at ChildProcess.emit (node:events:513:28) at ChildProcess._handle.onexit (node:internal/child_process:291:12)⨯ node-gyp failed to rebuild '/Users/me/Documents/project/node_modules/sharp' failedTask=build stackTrace=Error: node-gyp failed to rebuild '/Users/me/Documents/project/node_modules/sharp' With the patch it fails with a more interesting error that I've never seen before where a monorepo package is causing the failure due to (apparently) not being able to find With patch• installing production dependencies platform=darwin arch=x64 appDir=/Users/me/Documents/project ⨯ /Users/me/.nvm/versions/node/v18.16.0/bin/node process failed ERR_ELECTRON_BUILDER_CANNOT_EXECUTE Exit code: 127 Output: [1/4] Resolving packages... [2/4] Fetching packages... [3/4] Linking dependencies... [4/4] Building fresh packages... info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.Error output: error /Users/me/Documents/project/node_modules/project-mobile: Command failed. error /Users/me/Documents/project/node_modules/project-mobile: Command failed. Lastly here's the output if I enable Without patch - `buildDependenciesFromSource` AND `nodeGypRebuild` set to `true`• executing @electron/rebuild arch=x64 version=22.3.6 appDir=/Users/me/Documents/project • packaging platform=darwin arch=x64 electron=22.3.6 appOutDir=release/dev/mac-universal-x64-temp • executing @electron/rebuild arch=arm64 version=22.3.6 appDir=/Users/me/Documents/project • executing @electron/rebuild arch=arm64 version=22.3.6 appDir=/Users/me/Documents/project • packaging platform=darwin arch=arm64 electron=22.3.6 appOutDir=release/dev/mac-universal-arm64-temp • packaging platform=darwin arch=universal electron=22.3.6 appOutDir=release/dev/mac-universal ⨯ Detected unique file "node_modules/sharp/build/Release/sharp-darwin-arm64v8.node" in "/Users/me/Documents/project/release/dev/mac-universal-arm64-temp/project-Dev.app/Contents/Resources/app.asar" not covered by allowList rule: "undefined" failedTask=build stackTrace=Error: Detected unique file "node_modules/sharp/build/Release/sharp-darwin-arm64v8.node" in "/Users/me/Documents/project/release/dev/mac-universal-arm64-temp/project-Dev.app/Contents/Resources/app.asar" not covered by allowList rule: "undefined" at checkSingleArch (/Users/me/Documents/project/node_modules/@electron/universal/src/asar-utils.ts:69:11) at Object.exports.mergeASARs (/Users/me/Documents/project/node_modules/@electron/universal/src/asar-utils.ts:123:7) at exports.makeUniversalApp (/Users/me/Documents/project/node_modules/@electron/universal/src/index.ts:231:13) at MacPackager.doPack (/Users/me/Documents/project/node_modules/app-builder-lib/src/macPackager.ts:129:9) at MacPackager.pack (/Users/me/Documents/project/node_modules/app-builder-lib/src/macPackager.ts:196:7) at Packager.doBuild (/Users/me/Documents/project/node_modules/app-builder-lib/src/packager.ts:442:9) at executeFinally (/Users/me/Documents/project/node_modules/builder-util/src/promise.ts:12:14) at Packager._build (/Users/me/Documents/project/node_modules/app-builder-lib/src/packager.ts:376:31) at Packager.build (/Users/me/Documents/project/node_modules/app-builder-lib/src/packager.ts:337:12) at executeFinally (/Users/me/Documents/project/node_modules/builder-util/src/promise.ts:12:14) error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. |
@mmaietta I'm so sorry to be such a pain with this issue. I wonder if you had any other thoughts about possible resolution via It seems like we can use the workaround of Can I help move to move us forward on this? If so, just let me know how. I'd be happy to prepare another installer with this method for you to try to validate the fix, if it might be possible to leverage the workaround. Or to make a repro of Electron with Sharp so you can try the workaround yourself. I'd assume |
Hey @slapbox ! Not a pain at all 🙂 Can you put together a small sample gist/repo that I can fork/look into this and replicate? |
@mmaietta I apologize for taking so long to get around to this. Startup life indeed! I've put together a very basic repro here that runs the relevant Testing whether this fix works on your ARM64 should be as simple as:
No errors upon running suggests success. The expected visual output is something like this: @lovell are the |
@slapbox the |
@slapbox confirming it works. Also, electron-builder had to migrate back to using the golang library for native modules as it has prebuild-install directly integrated in, latest version is now 24.6.3 |
Thanks for testing @mmaietta! Did you happen to test using the latest version of Electron-Builder? I saw that the new version existed but I didn't want to throw any extra variables into the mix at that point. |
I'm hoping that most of this problem will go away with the forthcoming sharp v0.33.0 and that anyone building electron apps can simply add the platforms they wish to support as explicit There's a release candidate available should anyone wish to test - details at #3750 (comment) |
Thank you so much for your great work @lovell! |
v0.33.0 is now available. |
Possible bug
It seems like the
.node
binaries for x64 and ARM64 are bundled in our app, but the.dylib
file is only for x64. Is that expected? I'm guessing not.Relevant comment on another issue: electron-userland/electron-builder#7512 (comment)
Is this a possible bug in a feature of sharp, unrelated to installation?
My first thought was to say "no, this is an installation-related bug, I believe" - but now I'm not clear one where this falls.
npm install sharp
completes without error.node -e "require('sharp')"
completes without error.If you cannot confirm both of these, please open an installation issue instead.
Are you using the latest version of sharp?
sharp
as reported bynpm view sharp dist-tags.latest
.If you cannot confirm this, please upgrade to the latest version and try again before opening an issue.
If you are using another package which depends on a version of
sharp
that is not the latest, please open an issue against that package instead.What is the output of running
npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp
?What are the steps to reproduce?
Clone this repo (specifically the
sharpIssue
branch) and runyarn
- this will install and build with electron-builder. You can see the.dylib
file is only available for the x64 version as in my screenshot (or presumably only the ARM64 version if running on a Mac ARM64 machine.)What is the expected behaviour?
Universal builds have access to the necessary assets for running on either x64 or ARM64
I'm unsure if this is a Sharp issue or an
@electron/universal
issue.Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem
Clone this repo - see instructions above
Please provide sample image(s) that help explain this problem
The text was updated successfully, but these errors were encountered: