electron / universal

Create Universal macOS applications from two x64 and arm64 Electron applications
MIT License
112 stars 43 forks source link

feat: merge ASARs #34

Closed indutny-signal closed 2 years ago

indutny-signal commented 2 years ago

In short, this adds a new option fuseASARs that, instead of checking that ASARs are exactly the same, will attempt to fuse them together into one and run lipo on shared bindings.

uniqueAllowList` option handles files that are unique to each ASAR. Ultimately the goal is to put all of them together in the final ASAR, but I decided to go with an explicit allowlist so that the end user will always be aware of the extra files.

This helped us reduce universal .dmg size from 300mb to 240mb because we have quite a lot of data in our asar file at Signal.

Example of debug output

  electron-universal fusing x64 and arm64 asars +16ms
  electron-universal Fusing /var/folders/9f/5h519zwn7kz7rbwr_wr7sptm0000gn/T/electron-universal-VDiwOl/Tmp.app/Contents/Resources/app.asar and /Users/indutny/Code/signalapp/Signal-Desktop-Private/release/mac-universal--arm64/Signal.app/Contents/Resources/app.asar +1ms
  electron-universal Extracting /var/folders/9f/5h519zwn7kz7rbwr_wr7sptm0000gn/T/electron-universal-VDiwOl/Tmp.app/Contents/Resources/app.asar to /var/folders/9f/5h519zwn7kz7rbwr_wr7sptm0000gn/T/x64-Vfv57T +985ms
  electron-universal Extracting /Users/indutny/Code/signalapp/Signal-Desktop-Private/release/mac-universal--arm64/Signal.app/Contents/Resources/app.asar to /var/folders/9f/5h519zwn7kz7rbwr_wr7sptm0000gn/T/arm64-imyBcQ +2s
  electron-universal Creating unique directory: node_modules/@signalapp/signal-client/prebuilds/darwin-arm64 +2s
  electron-universal Copying unique file: node_modules/@signalapp/signal-client/prebuilds/darwin-arm64/node.napi.node +1ms
  electron-universal Copying unique file: node_modules/ringrtc/build/darwin/libringrtc-arm64.node +6ms
  electron-universal Creating unique directory: node_modules/sharp/vendor/8.11.3/darwin-arm64v8 +12ms
  electron-universal Copying unique file: node_modules/sharp/vendor/8.11.3/darwin-arm64v8/platform.json +0ms
  electron-universal Copying unique file: node_modules/sharp/vendor/8.11.3/darwin-arm64v8/versions.json +2ms
  electron-universal Creating unique directory: node_modules/sharp/vendor/8.11.3/darwin-arm64v8/lib +0ms
  electron-universal Copying unique file: node_modules/sharp/vendor/8.11.3/darwin-arm64v8/lib/libvips-cpp.42.dylib +0ms
  electron-universal Copying unique file: node_modules/sharp/build/Release/sharp-darwin-arm64v8.node +22ms
  electron-universal Fusing binding: node_modules/better-sqlite3/build/Release/better_sqlite3.node +3ms
  electron-universal Creating archive at /var/folders/9f/5h519zwn7kz7rbwr_wr7sptm0000gn/T/electron-universal-VDiwOl/Tmp.app/Contents/Resources/app.asar +28ms
  electron-universal Done fusing +11s
  electron-universal copying snapshot file Contents/Frameworks/Electron Framework.framework/Versions/A/Resources/v8_context_snapshot.arm64.bin to target application +2s
  electron-universal moving final universal app to target destination +4ms
indutny-signal commented 2 years ago

Thanks for looking into this @MarshallOfSound . I've addressed your feedback with the latest push.

indutny-signal commented 2 years ago

Realized that I forgot to drop Universal signatures from MACHO_MAGIC. Should be ready for another look if you have time. Thanks!

indutny-signal commented 2 years ago

Friendly ping @MarshallOfSound

electron-bot commented 2 years ago

:tada: This PR is included in version 1.2.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

indutny-signal commented 2 years ago

Yay, thank you so much!