Skip to content

Commit f4e8a27

Browse files
RandoTechNerdclaude
andcommitted
build-smlib-wasm.mjs: tracked (root .mjs files are ignored unless listed)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 4ccb5df commit f4e8a27

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ viewer/locked-key.js
4747
# the LAST matching rule wins.
4848
/*.mjs
4949
!/build-site.mjs
50+
!/build-smlib-wasm.mjs
5051

5152
# Scratch stashes of model code saved while iterating on an example. The
5253
# example itself lives in examples/; these are the drafts.

‎build-smlib-wasm.mjs‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Stages the SMLib kernel as WebAssembly for the website:
2+
// ../smlib-wasm (github.com/RandoTechNerd/smlib-wasm) -> vendor/brep-kernel-smlib/
3+
//
4+
// The same SMLib (from NVIDIA's open-source usd-brep) the desktop alpha runs
5+
// as a native addon, compiled with Emscripten in its own repo. The worker
6+
// (viewer/kernel-worker.js) runs it behind native/nvidia-kernel/adapter.cjs,
7+
// exactly as the desktop does, when the kernel picker says "nvidia". The
8+
// result is committed (as vendor/brep-kernel-rust is), so a site build needs
9+
// no Emscripten.
10+
//
11+
// node build-smlib-wasm.mjs copy the smlib-wasm repo's dist/ here
12+
// node build-smlib-wasm.mjs --build rebuild it there first (needs its Emscripten SDK)
13+
//
14+
// SMLIB_WASM=<dir> points at the smlib-wasm checkout (default: ../smlib-wasm
15+
// beside this repo's main checkout).
16+
17+
import { execFileSync } from "node:child_process";
18+
import { copyFileSync, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
19+
import { dirname, join, resolve } from "node:path";
20+
import { fileURLToPath } from "node:url";
21+
22+
const here = dirname(fileURLToPath(import.meta.url));
23+
const candidates = [process.env.SMLIB_WASM, join(here, "..", "smlib-wasm"), join(here, "..", "..", "smlib-wasm")].filter(Boolean);
24+
const SRC = candidates.map((p) => resolve(p)).find((p) => existsSync(join(p, "src", "api.mjs")));
25+
if (!SRC) {
26+
console.error(`build-smlib-wasm: no smlib-wasm checkout (looked in ${candidates.join(", ")}); set SMLIB_WASM`);
27+
process.exit(1);
28+
}
29+
const OUT = join(here, "vendor", "brep-kernel-smlib");
30+
31+
if (process.argv.includes("--build")) execFileSync(process.execPath, ["build.mjs"], { cwd: SRC, stdio: "inherit" });
32+
for (const f of ["smlib.mjs", "smlib.wasm"]) {
33+
if (!existsSync(join(SRC, "dist", f))) { console.error(`build-smlib-wasm: ${SRC}/dist/${f} is missing: node build.mjs there first (or --build)`); process.exit(1); }
34+
}
35+
36+
mkdirSync(OUT, { recursive: true });
37+
copyFileSync(join(SRC, "dist", "smlib.mjs"), join(OUT, "smlib.mjs"));
38+
copyFileSync(join(SRC, "dist", "smlib.wasm"), join(OUT, "smlib.wasm"));
39+
copyFileSync(join(SRC, "LICENSE"), join(OUT, "LICENSE"));
40+
copyFileSync(join(SRC, "THIRD_PARTY_NOTICES.md"), join(OUT, "THIRD_PARTY_NOTICES.md"));
41+
// api.mjs sits beside the module here, not one folder up
42+
writeFileSync(join(OUT, "api.mjs"), readFileSync(join(SRC, "src", "api.mjs"), "utf8").split('"../dist/smlib.mjs"').join('"./smlib.mjs"'));
43+
44+
let commit = "unknown";
45+
try { commit = execFileSync("git", ["rev-parse", "--short", "HEAD"], { cwd: SRC }).toString().trim(); } catch { /* not a git checkout */ }
46+
writeFileSync(join(OUT, "README.md"), `# vendor/brep-kernel-smlib
47+
48+
The SMLib B-rep kernel, based on NVIDIA's open-source usd-brep (SMLib +
49+
SM_API, v1.0.1, Apache-2.0), compiled to WebAssembly in
50+
https://github.com/RandoTechNerd/smlib-wasm (commit ${commit}). Staged here by
51+
\`node build-smlib-wasm.mjs\`; don't edit these files by hand.
52+
53+
\`api.mjs\` gives the same functions as the desktop's native addon, so
54+
\`native/nvidia-kernel/adapter.cjs\` runs on it unchanged (see
55+
viewer/kernel-worker.js). See LICENSE and THIRD_PARTY_NOTICES.md.
56+
`);
57+
console.log(`build-smlib-wasm: ${OUT} from ${SRC} @ ${commit} (smlib.wasm ${(statSync(join(OUT, "smlib.wasm")).size / 1e6).toFixed(1)} MB)`);

0 commit comments

Comments
 (0)