Skip to content

Commit 9fac19c

Browse files
committed
fix(std): correctly handle script files
1 parent 881c75e commit 9fac19c

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

packages/std/wrap.tg.ts

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -258,35 +258,39 @@ export namespace wrap {
258258
let host = host_;
259259
if (host === undefined) {
260260
if (executable instanceof tg.File) {
261-
const metadata = await std.file.executableMetadata(executable);
262-
let os;
263-
let arch;
264-
if (metadata.format === "mach-o") {
265-
os = "darwin";
266-
if (metadata.arches.length === 1) {
267-
arch = metadata.arches[0];
268-
tg.assert(arch);
269-
host = std.triple.fromComponents({ arch, os });
270-
} else {
271-
// Check if the detected arch matches any. Error if not?
272-
const detectedArch = std.triple.arch(detectedHost);
273-
if (metadata.arches.includes(detectedArch)) {
274-
arch = detectedArch;
261+
try {
262+
const metadata = await std.file.executableMetadata(executable);
263+
let os;
264+
let arch;
265+
if (metadata.format === "mach-o") {
266+
os = "darwin";
267+
if (metadata.arches.length === 1) {
268+
arch = metadata.arches[0];
269+
tg.assert(arch);
275270
host = std.triple.fromComponents({ arch, os });
276271
} else {
277-
const id = await executable.store();
278-
throw new Error(
279-
`fat binary detected containing only unsupported architectures: ${id}`,
280-
);
272+
// Check if the detected arch matches any. Error if not?
273+
const detectedArch = std.triple.arch(detectedHost);
274+
if (metadata.arches.includes(detectedArch)) {
275+
arch = detectedArch;
276+
host = std.triple.fromComponents({ arch, os });
277+
} else {
278+
const id = await executable.store();
279+
throw new Error(
280+
`fat binary detected containing only unsupported architectures: ${id}`,
281+
);
282+
}
281283
}
284+
} else if (metadata.format === "elf") {
285+
os = "linux";
286+
arch = metadata.arch;
287+
host = std.sdk.canonicalTriple(
288+
std.triple.fromComponents({ arch, os }),
289+
);
290+
} else {
291+
host = detectedHost;
282292
}
283-
} else if (metadata.format === "elf") {
284-
os = "linux";
285-
arch = metadata.arch;
286-
host = std.sdk.canonicalTriple(
287-
std.triple.fromComponents({ arch, os }),
288-
);
289-
} else {
293+
} catch (_) {
290294
host = detectedHost;
291295
}
292296
} else {

0 commit comments

Comments
 (0)