Skip to content

Commit 00a8c87

Browse files
committed
fix(sea): inject elf resources with postject
1 parent dba49af commit 00a8c87

1 file changed

Lines changed: 30 additions & 22 deletions

File tree

scripts/repo/cli-build/sea/build.mts

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import crypto from 'node:crypto'
2-
import { mkdir, readFile, writeFile } from 'node:fs/promises'
2+
import { copyFile, mkdir, readFile, writeFile } from 'node:fs/promises'
33
import path from 'node:path'
44
import { spawn } from '@socketsecurity/lib-stable/process/spawn/child'
55
import { getDefaultLogger } from '@socketsecurity/lib-stable/logger/default'
@@ -142,28 +142,36 @@ async function buildSeaTarget(
142142
`SEA blob generation failed for ${target}. Inspect node-smol output.`,
143143
)
144144
}
145-
const result = await spawn(
146-
injector,
147-
[
148-
'inject',
149-
'--executable',
150-
base,
151-
'--output',
152-
output,
153-
'--sea',
154-
blob,
155-
'--vfs-compat',
156-
'--skip-repack',
157-
],
158-
{
159-
stdio: process.argv.includes('--json') ? 'pipe' : 'inherit',
160-
timeout: 600_000,
161-
},
162-
)
163-
if (result.code !== 0) {
164-
throw new Error(
165-
`SEA build failed for ${target}: exit ${result.code}. Inspect binject output.`,
145+
if (target.startsWith('linux-')) {
146+
const { inject } = await import('postject')
147+
await copyFile(base, output)
148+
await inject(output, 'NODE_SEA_BLOB', await readFile(blob), {
149+
sentinelFuse: 'NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2',
150+
})
151+
} else {
152+
const result = await spawn(
153+
injector,
154+
[
155+
'inject',
156+
'--executable',
157+
base,
158+
'--output',
159+
output,
160+
'--sea',
161+
blob,
162+
'--vfs-compat',
163+
'--skip-repack',
164+
],
165+
{
166+
stdio: process.argv.includes('--json') ? 'pipe' : 'inherit',
167+
timeout: 600_000,
168+
},
166169
)
170+
if (result.code !== 0) {
171+
throw new Error(
172+
`SEA build failed for ${target}: exit ${result.code}. Inspect binject output.`,
173+
)
174+
}
167175
}
168176
return crypto
169177
.createHash('sha256')

0 commit comments

Comments
 (0)