Skip to content

Commit

Permalink
Merge pull request #5283 from systeminit/arm
Browse files Browse the repository at this point in the history
fix: arm rootfs needs an arm linker
  • Loading branch information
sprutton1 authored Jan 17, 2025
2 parents d75899f + 019d01b commit 9bf8328
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 72 deletions.
1 change: 1 addition & 0 deletions bin/lang-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"joi": "^17.11.0",
"js-yaml": "^4.1.0",
"node-fetch": "^2",
"proper-lockfile": "^4.1.2",
"toml": "^3.0.0",
"typescript": "^4.9.5"
},
Expand Down
26 changes: 1 addition & 25 deletions bin/lang-js/src/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Debugger } from "./debug.ts";
import { transpile } from "jsr:@deno/emit";
import { Debug } from "./debug.ts";
import * as _worker from "./worker.js";
import { bundleCode } from "./transpile.ts";

const debug = Debug("langJs:function");

Expand Down Expand Up @@ -264,28 +265,3 @@ export async function runCode(
};
});
}

async function bundleCode(code: string): Promise<string> {
debug({ "code before bundle": code });
const tempDir = await Deno.makeTempDir();
const tempFile = `${tempDir}/script.ts`;

await Deno.writeTextFile(tempFile, code);
const fileUrl = new URL(tempFile, import.meta.url);

try {
const result = await transpile(fileUrl);

const bundled = result.get(fileUrl.href) as string;
if (!bundled) {
throw new Error("Transpilation resulted in empty output");
}

debug({ "code after bundle": code });
return bundled;
} catch (error) {
throw error;
} finally {
await Deno.remove(tempDir, { recursive: true });
}
}
2 changes: 1 addition & 1 deletion bin/lang-js/src/function_kinds/management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface ManagementCreate {
}

export interface ManagementOperations {
create?: ManagementCreate,
create?: ManagementCreate;
update?: {
[key: string]: {
properties?: object;
Expand Down
61 changes: 61 additions & 0 deletions bin/lang-js/src/transpile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import * as _ from "npm:lodash-es";
import { transpile } from "jsr:@deno/emit";
import { Debug } from "./debug.ts";
import { lock } from "npm:proper-lockfile";

const debug = Debug("langJs:transpile");

const LOCK_FILE = "/tmp/lang-js-transpile";

async function ensureLockfile() {
try {
await Deno.writeTextFile(LOCK_FILE, "");
} catch (err) {
if (!(err instanceof Deno.errors.AlreadyExists)) {
throw err;
}
}
}

export function bundleCode(code: string): Promise<string> {
return (async () => {
let release;

await ensureLockfile();

try {
release = await lock("/tmp/lang-js-transpile", {
stale: 30000,
updateInterval: 1000,
retries: {
retries: 60,
minTimeout: 100,
maxTimeout: 1000,
},
});

debug({ "code before bundle": code });
const tempDir = await Deno.makeTempDir();
const tempFile = `${tempDir}/script.ts`;

await Deno.writeTextFile(tempFile, code);
const fileUrl = new URL(tempFile, import.meta.url);

try {
const result = await transpile(fileUrl);
const bundled = result.get(fileUrl.href) as string;
if (!bundled) {
throw new Error("Transpilation resulted in empty output");
}
debug({ "code after bundle": bundled });
return bundled;
} finally {
await Deno.remove(tempDir, { recursive: true });
}
} finally {
if (release) {
await release();
}
}
})();
}
16 changes: 16 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@
# /lib64/ld-linux-x86-64.so.2 -> /nix/store/*/ld-linux-x86-64.20.2
mkdir -p $out/lib64
ln -sf ${pkgs.glibc}/lib/ld-linux-x86-64.so.2 $out/lib64/ld-linux-x86-64.so.2
ln -sf ${pkgs.glibc}/lib/ld-linux-aarch64.so.1 $out/lib64/ld-linux-aarch64.so.1
wrapProgram $out/bin/lang-js \
--set LD_LIBRARY_PATH "${pkgs.lib.makeLibraryPath [
Expand Down
Loading

0 comments on commit 9bf8328

Please sign in to comment.