-
Notifications
You must be signed in to change notification settings - Fork 41
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
fix: Skip lipo
if native module is already universal. Add native module fixtures for lipo
tests
#126
base: main
Are you sure you want to change the base?
Conversation
…e-mac-permissions` fixture from https://github.com/codebytere/node-mac-permissions and resolves 3 `it.todo` test cases
lipo
if native module is already universal. Add native module tests for lipo
testslipo
if native module is already universal. Add native module fixtures for lipo
tests
…ve-module-tests # Conflicts: # test/index.spec.ts
…g into asar to leverage `unpack: "**/*.node"` properly.
…ve-module-tests # Conflicts: # src/index.ts # test/util.ts
Quick update: Well this is interesting. Now I'm receiving this in the debug logs:
It's almost like The Buffer for x64 is basically twice the size of the arm64, so something else is happening that is unexpected. Moving this back into Draft state [UPDATE] Debugging it was straightforward, but I could use some of your guidance @erikian . The x64 Lines 190 to 196 in 2b67c90
It outputs the universal It looks like the arm64 app may need to be copied as well to a tmp directory, which then also has the |
@mmaietta all tests pass for me after changing this... Lines 155 to 157 in 7e3167b
...into this: if (isUniversalMachO(x64Content)) {
continue;
} From what I could gather, since we're already joining the single-arch Mach-O files into one universal file in... Lines 190 to 196 in 2b67c90
x64Content (which comes from the .asar that we're generating in... Lines 255 to 258 in 7e3167b
.asar ) is a universal Mach-O file in mergeASARs , we should skip that file, otherwise we'd try to join the already-universal "x64" Mach-O file and the arm64 version into another universal file in...Lines 197 to 200 in 7e3167b
Notice that we never touch the arm64 version in the last snippet — we only use it as one of the inputs for generating a new universal file —, so it's safe to remove the The naming is a bit confusing throughout the project because we start out by copying the x64 app into a temp folder that will eventually become our final universal bundle, so in a lot of places where we use Hope that helps! |
That's amazing, thank you for the advice and investigation! That makes perfect sense.
Would you like me to add some |
test/fixtures/native/README.txt
Outdated
Arch-specific modules generated from `node-mac-permissions` (https://github.com/codebytere/node-mac-permissions) using `electron/rebuild` | ||
|
||
Universal module generated with `lipo` | ||
``` | ||
lipo ./test/fixtures/native/node-mac-permissions.x64.node ./test/fixtures/native/node-mac-permissions.arm64.node -create -output ./test/fixtures/native/node-mac-permissions.universal.node | ||
``` |
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.
Would you mind adding some logic for installing / cloning a specific version of node-mac-permissions
and generating the native artifacts locally before running the tests for better reproducibility?
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.
As in add to the README.txt instructions to do so or to add additional logic to the jest setup script to clone and build locally?
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.
Nvm, ignore the comment above. @MarshallOfSound recommended I just create a basic HelloWorld.s
file as a fixture, compile into a macho file during runtime, and then lipo at runtime as well into the fixture output dir. Total time should only add a few seconds to the test duration. 🙂
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.
Updated unit tests to runtime-generate a macho file off a very simple hello-world.c
. Note, this did require adjusting the snapshot logic to remove blocks
, hash
, and integrity
fields, specifically when it contains a runtime-generated asset as the macho file in this case is always a unique hash per-build machine.
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.
Thanks Mike, and sorry for the delay reviewing this PR — I'll take another look in the next couple of days!
47c0921
to
24d5d2c
Compare
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.
LGTM
Leveraged TDD from
it.todo
to discover issue of build failing due to universal file not being added toknownMergedMachOFiles
Detected file "Contents/Resources/app/node-mac-permissions.node" that's the same in both x64 and arm64 builds and not covered by the x64ArchFiles rule: "undefined"
lipo
attempting to merge universal filesFixes #130
Functionality added:
lipo
stepisUniversalMachO(buffer: Buffer)
to leverage MachO magic header validation in multiple locationsTestability:
it.todo
test cases and adds some more 💪identical app dirs with universal macho files (e.g., do not shim, just copy x64 dir)
different app dirs with universal macho files (e.g. shim but don't lipo)
identical app dirs with different macho files (e.g. do not shim, but still lipo)
different app dirs with different macho files (e.g. shim and lipo)
works for lipo binary resources
Fixtures added:
hello-world.c
is generated into macho files at test runtime (~1 second added in global test setup) and lipo'd together for a universal fixture.