Skip to content

Commit

Permalink
fix: follow exact SEA baking procedure for Mac (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
getlarge authored Oct 28, 2024
1 parent e41355c commit d818a04
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
17 changes: 16 additions & 1 deletion lib/mach-o.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ function patchCommand(type: number, buf: Buffer, file: Buffer) {
}
}

/**
* It would be nice to explain the purpose of this patching function
* @param file
* @returns
*/
function patchMachOExecutable(file: Buffer) {
const align = 8;
const hsize = 32;
Expand Down Expand Up @@ -67,4 +72,14 @@ function signMachOExecutable(executable: string) {
}
}

export { patchMachOExecutable, signMachOExecutable };
function removeMachOExecutableSignature(executable: string) {
execFileSync('codesign', ['--remove-signature', executable], {
stdio: 'inherit',
});
}

export {
patchMachOExecutable,
removeMachOExecutableSignature,
signMachOExecutable,
};
19 changes: 15 additions & 4 deletions lib/sea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import unzipper from 'unzipper';
import { extract as tarExtract } from 'tar';
import { log } from './log';
import { NodeTarget, Target } from './types';
import { patchMachOExecutable, signMachOExecutable } from './mach-o';
import {
patchMachOExecutable,
removeMachOExecutableSignature,
signMachOExecutable,
} from './mach-o';

const exec = util.promisify(cExec);

Expand Down Expand Up @@ -277,9 +281,16 @@ async function bake(
await copyFile(nodePath, outPath);

log.info(`Injecting the blob into ${outPath}...`);
await exec(
`npx postject "${outPath}" NODE_SEA_BLOB "${blobPath}" --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2`,
);
if (target.platform === 'macos') {
removeMachOExecutableSignature(outPath);
await exec(
`npx postject "${outPath}" NODE_SEA_BLOB "${blobPath}" --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 --macho-segment-name NODE_SEA`,
);
} else {
await exec(
`npx postject "${outPath}" NODE_SEA_BLOB "${blobPath}" --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2`,
);
}
}

/** Create NodeJS executable using sea */
Expand Down
11 changes: 5 additions & 6 deletions test/test-00-sea/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ if (process.platform === 'linux') {
'Output matches',
);
} else if (process.platform === 'darwin') {
// FIXME: not working, needs investigation
// assert.equal(
// utils.spawn.sync('./test-sea-macos', []),
// 'Hello world\n',
// 'Output matches',
// );
assert.equal(
utils.spawn.sync('./test-sea-macos', []),
'Hello world\n',
'Output matches',
);
} else if (process.platform === 'win32') {
// FIXME: output doesn't match on windows
// assert.equal(
Expand Down

0 comments on commit d818a04

Please # to comment.