-
Notifications
You must be signed in to change notification settings - Fork 43
feat: merge ASARs #34
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
feat: merge ASARs #34
Conversation
d11807e
to
3cfc895
Compare
3cfc895
to
2bcde3c
Compare
src/asar-utils.ts
Outdated
0xcffaedfe, | ||
|
||
// Universal | ||
0xcafebabe, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe there's a slight risk of misidentifying Java bytecode files as macho, but in that case lipo
will fail anyway so maybe we shouldn't bother?
src/asar-utils.ts
Outdated
x64, | ||
arm64, | ||
output, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can these all be more specific, I assume they're paths to asar files?
So x64AsarPath
, arm64AsarPath
, outputAsarPath
, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack.
src/asar-utils.ts
Outdated
x64, | ||
arm64, | ||
output, | ||
lipo = 'lipo', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the path / name of the lipo
binary? If so let's go with lipoPath
, more indicative
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also why is this an option, it isn't a user-facing option and afaics we don't do anything similar elsewhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Let's drop this.
src/index.ts
Outdated
/** | ||
* Fuse x64 and arm64 ASARs into one. | ||
*/ | ||
fuseASARs?: boolean; | ||
/** | ||
* Minimatch pattern of paths that are allowed to be unique in ASARs. | ||
*/ | ||
fuseASARsAllowList?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if they're on this list, does it take the x64 file? the arm64 file? etc.
I think it would be better to somehow allow folks to choose, or preferably not allow this at all. It leads to uncertainty, you should just form your ASAR file correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if they're on this list, does it take the x64 file? the arm64 file? etc.
It takes either x64 or arm64 file that is not present in the other platform's asar.
I think it would be better to somehow allow folks to choose, or preferably not allow this at all. It leads to uncertainty, you should just form your ASAR file correctly.
The "unique" files in this jargon will likely have platform specific name (e.g. node_modules/sharp/build/${platform}-${arch}
, at least this is what we see at Signal Desktop), and so I believe that this option is usable in the current form. The motivation for introducing it is that I wanted users to have complete control over which files are going to be introduced into ASAR. My worry is that there might be a package that won't play well with such merging scheme and users won't know about it until it will start crashing in production.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see, so these files to be clear exist in one asar but do not exist in the other? 🤔 I don't know what a better name is but it's definitely not clear what that does if I didn't grok it first try.
Maybe singleArchFiles
or something idk, open to ideas here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see, so these files to be clear exist in one asar but do not exist in the other? 🤔 I don't know what a better name is but it's definitely not clear what that does if I didn't grok it first try.
You got it right.
Maybe
singleArchFiles
or something idk, open to ideas here.
singleArchFiles
certainly sounds better than what I came up with, let me change it to this. I'm out of ideas, otherwise!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed.
src/index.ts
Outdated
/** | ||
* Fuse x64 and arm64 ASARs into one. | ||
*/ | ||
fuseASARs?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not use the word "fuse" here as fuses are a different Electron concept.
Either mergeASARs
or lipoNativeModules
might be better options here. The latter definition if we remove the allow list option below because then that's all this option does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to mergeASARs
, which is frankly what I came up originally 😂
src/asar-utils.ts
Outdated
const destination = await fs.realpath(path.resolve(x64Dir, binding)); | ||
|
||
d(`fusing binding: ${binding}`); | ||
execFileSync(lipo, [source, destination, '-create', '-output', destination]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of the way MACHO_MAGIC works couldn't this be trying to fuse universal/x64 or x64 and x64 that don't match? Not familiar enough with lipo
to know what happens when you try to merge things like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I should just drop the Universal constant from MACHO_MAGIC
. The merging of x64 and x64 would fail AFAIK and it should be fine because the binding binaries shouldn't be different unless they were compiled for different platforms!
Thanks for looking into this @MarshallOfSound . I've addressed your feedback with the latest push. |
Realized that I forgot to drop Universal signatures from MACHO_MAGIC. Should be ready for another look if you have time. Thanks! |
Friendly ping @MarshallOfSound |
🎉 This PR is included in version 1.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Yay, thank you so much! |
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 runlipo
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 from300mb
to240mb
because we have quite a lot of data in our asar file at Signal.Example of debug output