Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(aot): the build step asks which machine, not which compiler

yhhea960f299c6b
diff --git a/pipeline/src/bundle/buildCompiledSystems.ts b/pipeline/src/bundle/buildCompiledSystems.ts
index 791e5c5bd..64fd03289 100644
--- a/pipeline/src/bundle/buildCompiledSystems.ts
+++ b/pipeline/src/bundle/buildCompiledSystems.ts
@@ -29,6 +29,7 @@ import { inlineSystem } from '../../../compiler/src/inline';
import { builtinShapes } from '../../../compiler/src/builtins';
import { packLayout, planFor } from '../../../compiler/src/abi';
import { CFLAGS, WASM_LINK_FLAGS, cSymbol, emitC } from '../../../compiler/src/codegen';
+import { NATIVE_LINK_FLAGS, nativeModuleExt } from '../../../compiler/src/hostCC';
import { AOT_MANIFEST, AOT_WASM } from './aotArtifacts';
/** Where the C and the wasm land, beside the script bundle. */
@@ -73,10 +74,61 @@ export interface CompiledSystemsManifest {
*/
export type BuildMode = 'dev' | 'release' | 'ship';
+/**
+ * Which machine the systems are compiled FOR.
+ *
+ * `wasm` imports the engine's memory; `native` is a library a host loads into
+ * its own process, where an address is a pointer and not an offset into one
+ * block. The same C either way — the header picks the typedef.
+ */
+export type CompileTarget = 'wasm' | 'native';
+
+/** Everything that differs between the two, in one place rather than in ifs. */
+interface TargetPlan {
+ /** `sizeof(es_addr_t)` there. It rides the handshake, so an artifact built
+ * for one host is refused by the other rather than reading half a pointer. */
+ readonly addressBytes: 4 | 8;
+ /** What the module is called in the cache. */
+ readonly module: string;
+ /** Link flags, plus whatever names the exports on this target. */
+ linkFlags(symbols: readonly string[]): string[];
+ /** Whether the declaration table is compiled in. It is the DATA half: a wasm
+ * module must not carry it, since its data section would land at an address
+ * the engine already owns, and a library in the host's process is who does. */
+ readonly compilesDecls: boolean;
+ /** What to say when this machine has no compiler for it. */
+ readonly missing: string;
+}
+
+const TARGETS: Record<CompileTarget, TargetPlan> = {
+ wasm: {
+ addressBytes: 4,
+ module: WASM,
+ linkFlags: (symbols) => [
+ // No entry point and no JS glue, so the module's only import is the memory
+ // it is given. An empty import section is a property of this command line
+ // as much as of the C.
+ ...WASM_LINK_FLAGS,
+ `-sEXPORTED_FUNCTIONS=${symbols.map((s) => `_${s}`).join(',')}`,
+ ],
+ compilesDecls: false,
+ missing: 'there is no emcc — install the emscripten toolchain and point EMSDK'
+ + ' at it (in this repo: `pnpm emsdk:setup`)',
+ },
+ native: {
+ addressBytes: 8,
+ module: `systems${nativeModuleExt()}`,
+ linkFlags: () => [...NATIVE_LINK_FLAGS],
+ compilesDecls: true,
+ missing: 'this machine has no C compiler — install clang or gcc and put it on PATH',
+ },
+};
+
export interface BuildCompiledResult {
ok: boolean;
- /** Absolute path to the wasm, or null when there was nothing to build. */
- wasmPath: string | null;
+ /** Absolute path to the built module, or null when there was nothing to
+ * build. Which KIND of module is the target the caller asked for. */
+ modulePath: string | null;
manifest: CompiledSystemsManifest | null;
errors: string[];
/** Systems the subset refused that were NOT promised — information, not failure. */
@@ -129,8 +181,8 @@ export function promisesCompilation(root: string): boolean {
/**
* Compile the project's `@compiled` systems to `<root>/.esengine/cache/aot/`.
*
- * `emcc` is the caller's to supply, because finding it is the toolchain's job
- * and not this module's; without one a project that promised nothing still
+ * The compiler is the caller's to supply, because finding it is the toolchain's
+ * job and not this module's; without one a project that promised nothing still
* builds, and one that promised something says so.
*/
export async function buildCompiledSystems(
@@ -138,34 +190,39 @@ export async function buildCompiledSystems(
opts: {
/** dev never compiles; release and ship require what the markers promised. */
mode: BuildMode;
- /** Absolute path to emcc, or null when the toolchain has none. */
- emcc: string | null;
+ /** Which machine this build is for. Absent ⇒ wasm, the road every
+ * browser and mini-game host takes. */
+ target?: CompileTarget;
+ /** Absolute path to the compiler FOR that target — emcc for wasm, the
+ * host's own cc for native — or null when this machine has none. */
+ cc: string | null;
/** Runs a command; the toolchain's own runner, so env and logging match. */
run: (cmd: string, args: string[], cwd: string) => Promise<{ code: number; stderr: string }>;
},
): Promise<BuildCompiledResult> {
+ const plan = TARGETS[opts.target ?? 'wasm'];
if (opts.mode === 'dev') {
// Nothing is compiled and nothing is checked, so a marker costs a dev build
// nothing at all — not a toolchain, not a second of build time, not a
// failure on a machine that has neither.
- return { ok: true, wasmPath: null, manifest: null, errors: [], notes: [] };
+ return { ok: true, modulePath: null, manifest: null, errors: [], notes: [] };
}
const files = sources(root);
if (files.length === 0) {
- return { ok: true, wasmPath: null, manifest: null, errors: [], notes: [] };
+ return { ok: true, modulePath: null, manifest: null, errors: [], notes: [] };
}
// A project with no `@compiled` anywhere promised nothing, so it must not pay
// for a TypeScript Program over its sources. Nothing is decided here: the parse
// below still decides, this only skips having nothing to decide.
if (!anyPromise(files)) {
- return { ok: true, wasmPath: null, manifest: null, errors: [], notes: [] };
+ return { ok: true, modulePath: null, manifest: null, errors: [], notes: [] };
}
let lowered;
try {
lowered = lowerProgram(files, builtinShapes());
} catch (err) {
- return { ok: false, wasmPath: null, manifest: null, notes: [], errors: [String(err)] };
+ return { ok: false, modulePath: null, manifest: null, notes: [], errors: [String(err)] };
}
const broken = brokenPromises(lowered);
@@ -174,7 +231,7 @@ export async function buildCompiledSystems(
// with a line, not a silent fall back to the interpreter.
return {
ok: false,
- wasmPath: null,
+ modulePath: null,
manifest: null,
notes: [],
errors: broken.map((d) => `${d.file}:${d.line}: ${d.system ?? ''} is @compiled but ${d.message}`),
@@ -188,29 +245,28 @@ export async function buildCompiledSystems(
.map((d) => `${d.system}: ${d.message}`);
if (chosen.length === 0) {
// Nothing was promised, so there is nothing to build and nothing to say.
- return { ok: true, wasmPath: null, manifest: null, errors: [], notes };
+ return { ok: true, modulePath: null, manifest: null, errors: [], notes };
}
const bad = chosen.flatMap((s) => verifySystem(s, lowered.module.comps, lowered.module.fns));
if (bad.length > 0) {
return {
- ok: false, wasmPath: null, manifest: null, notes,
+ ok: false, modulePath: null, manifest: null, notes,
errors: bad.map((e) => `${e.system}: ${e.message}`),
};
}
- if (!opts.emcc) {
+ if (!opts.cc) {
return {
- ok: false, wasmPath: null, manifest: null, notes,
- errors: [`${chosen.length} system(s) are marked @compiled but there is no emcc`
- + ' — install the emscripten toolchain and point EMSDK at it (in this repo:'
- + ' `pnpm emsdk:setup`), or remove the marker'],
+ ok: false, modulePath: null, manifest: null, notes,
+ errors: [`${chosen.length} system(s) are marked @compiled but ${plan.missing}`
+ + ', or remove the marker'],
};
}
const layout = packLayout(lowered.module.comps);
const inlined = chosen.map((s) => inlineSystem(s, lowered.module.fns));
- const c = emitC(lowered.module, layout, inlined);
+ const c = emitC(lowered.module, layout, inlined, plan.addressBytes);
const dir = path.join(root, CACHE_DIR);
rmSync(dir, { recursive: true, force: true });
@@ -218,22 +274,20 @@ export async function buildCompiledSystems(
writeFileSync(path.join(dir, 'estella_abi.h'), c.header);
writeFileSync(path.join(dir, 'estella_offsets.h'), c.offsets);
writeFileSync(path.join(dir, 'systems.c'), c.source);
+ const units = [path.join(dir, 'systems.c')];
+ if (plan.compilesDecls) {
+ writeFileSync(path.join(dir, 'systems_decl.c'), c.decls);
+ units.push(path.join(dir, 'systems_decl.c'));
+ }
- const wasmPath = path.join(dir, WASM);
- const exported = c.symbols.map((s) => `_${s}`).join(',');
- const built = await opts.run(opts.emcc, [
+ const modulePath = path.join(dir, plan.module);
+ const built = await opts.run(opts.cc, [
...CFLAGS, '-Wall', '-Wextra',
- // No entry point and no JS glue, so the module's only import is the memory
- // it is given. An empty import section is a property of this command line
- // as much as of the C.
- ...WASM_LINK_FLAGS,
- `-sEXPORTED_FUNCTIONS=${exported}`,
- // `c.decls` is deliberately NOT compiled here. It is the data half, and a
- // data section is written at a link-time address the engine already owns.
- '-o', wasmPath, path.join(dir, 'systems.c'),
+ ...plan.linkFlags(c.symbols),
+ '-o', modulePath, ...units,
], dir);
- if (built.code !== 0 || !existsSync(wasmPath)) {
- return { ok: false, wasmPath: null, manifest: null, notes, errors: [built.stderr.trim()] };
+ if (built.code !== 0 || !existsSync(modulePath)) {
+ return { ok: false, modulePath: null, manifest: null, notes, errors: [built.stderr.trim()] };
}
const manifest: CompiledSystemsManifest = {
@@ -260,7 +314,7 @@ export async function buildCompiledSystems(
}),
};
writeFileSync(path.join(dir, MANIFEST), `${JSON.stringify(manifest, null, 2)}\n`);
- return { ok: true, wasmPath, manifest, errors: [], notes };
+ return { ok: true, modulePath, manifest, errors: [], notes };
}
/** Read back what a previous build wrote, or null. */
diff --git a/pipeline/src/export/exportGame.ts b/pipeline/src/export/exportGame.ts
index 719c4ab09..6250a1d48 100644
--- a/pipeline/src/export/exportGame.ts
+++ b/pipeline/src/export/exportGame.ts
@@ -719,16 +719,16 @@ async function produceExport(opts: ExportGameOptions): Promise<ExportGameResult>
// promise someone is collecting on, so a promise the subset cannot keep
// fails the build rather than quietly falling back to the interpreter.
const built = await buildCompiledSystems(opts.root, {
- mode: opts.aotMode ?? 'release', emcc: resolveEmcc(opts.emcc), run: runEmcc,
+ mode: opts.aotMode ?? 'release', cc: resolveEmcc(opts.emcc), run: runEmcc,
});
if (!built.ok) {
errors.push(...built.errors);
return { ok: false, platform, outDir: absOut, included: cook.included.length, warnings, errors };
}
- if (built.wasmPath && built.manifest) {
+ if (built.modulePath && built.manifest) {
progress({ phase: 'Compiling systems', detail: `${built.manifest.systems.length} system(s)` });
await mkdir(path.join(payloadDir, 'aot'), { recursive: true });
- await cp(built.wasmPath, path.join(payloadDir, 'aot', 'systems.wasm'));
+ await cp(built.modulePath, path.join(payloadDir, 'aot', 'systems.wasm'));
aot = { wasm: 'aot/systems.wasm', manifest: built.manifest };
}
}
diff --git a/pipeline/src/export/exportMiniGame.ts b/pipeline/src/export/exportMiniGame.ts
index 745032626..646bc9ba7 100644
--- a/pipeline/src/export/exportMiniGame.ts
+++ b/pipeline/src/export/exportMiniGame.ts
@@ -327,17 +327,17 @@ export async function exportMiniGame(profile: MiniGameExportProfile, opts: {
// the target AOT exists for (docs/REARCH_AOT.md §1.1: iOS mini-games have no
// JIT). A PATH, because WXWebAssembly cannot compile bytes.
const built = await buildCompiledSystems(opts.root, {
- mode: opts.aotMode ?? 'release', emcc: resolveEmcc(opts.emcc), run: runEmcc,
+ mode: opts.aotMode ?? 'release', cc: resolveEmcc(opts.emcc), run: runEmcc,
});
if (!built.ok) {
errors.push(...built.errors);
return { ok: false, platform: profile.id, outDir: absOut, included: cook.included.length, warnings, errors };
}
let aotArg = '';
- if (built.wasmPath && built.manifest) {
+ if (built.modulePath && built.manifest) {
progress({ phase: 'Compiling systems', detail: `${built.manifest.systems.length} system(s)` });
await mkdir(path.join(absOut, 'aot'), { recursive: true });
- await cp(built.wasmPath, path.join(absOut, 'aot', 'systems.wasm'));
+ await cp(built.modulePath, path.join(absOut, 'aot', 'systems.wasm'));
aotArg = `, aot: ${JSON.stringify({ wasm: 'aot/systems.wasm', manifest: built.manifest })}`;
}
const entrySrc =
diff --git a/pipeline/tests/aot-end-to-end.test.ts b/pipeline/tests/aot-end-to-end.test.ts
index 00eeda6e7..0ad7daf5f 100644
--- a/pipeline/tests/aot-end-to-end.test.ts
+++ b/pipeline/tests/aot-end-to-end.test.ts
@@ -164,8 +164,8 @@ describe('a project that promised compilation gets it', () => {
rmSync(PROJECT, { recursive: true, force: true });
mkdirSync(path.join(PROJECT, 'src'), { recursive: true });
writeFileSync(path.join(PROJECT, 'src', 'move.ts'), SOURCE);
- built = await buildCompiledSystems(PROJECT, { mode: 'release', emcc: EMCC, run });
- if (built.wasmPath) wasm = Uint8Array.from(readFileSync(built.wasmPath));
+ built = await buildCompiledSystems(PROJECT, { mode: 'release', cc: EMCC, run });
+ if (built.modulePath) wasm = Uint8Array.from(readFileSync(built.modulePath));
// The same file the compiler read, as the runtime's own definitions — not a
// second copy that would only ever agree with its own mistakes.
fixture = await import(/* @vite-ignore */
@@ -174,8 +174,8 @@ describe('a project that promised compilation gets it', () => {
rmSync(PROBE, { recursive: true, force: true });
mkdirSync(path.join(PROBE, 'src'), { recursive: true });
writeFileSync(path.join(PROBE, 'src', 'move.ts'), PROBE_SOURCE);
- probe = await buildCompiledSystems(PROBE, { mode: 'release', emcc: EMCC, run });
- if (probe.wasmPath) probeWasm = Uint8Array.from(readFileSync(probe.wasmPath));
+ probe = await buildCompiledSystems(PROBE, { mode: 'release', cc: EMCC, run });
+ if (probe.modulePath) probeWasm = Uint8Array.from(readFileSync(probe.modulePath));
}, 180_000);
it('reports whether this gate could run at all', () => {
diff --git a/pipeline/tests/build-compiled-systems.test.ts b/pipeline/tests/build-compiled-systems.test.ts
index 4112566eb..7f8eeed83 100644
--- a/pipeline/tests/build-compiled-systems.test.ts
+++ b/pipeline/tests/build-compiled-systems.test.ts
@@ -17,10 +17,12 @@ import path from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { buildCompiledSystems, readCompiledManifest } from '../src/bundle/buildCompiledSystems';
import { emccPath } from '../../build-tools/utils/emscripten.js';
+import { findHostCC, nativeModuleExt } from '../../compiler/src/hostCC';
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..');
const EMCC = emccPath();
+const HOST_CC = findHostCC();
/**
* A memory shaped like the engine's: growable to 2GB, and already 16MB, which
@@ -134,7 +136,7 @@ describe.skipIf(!EMCC || !ENGINE_GLUE)('loaded into the engine the build produce
it('instantiates against the real memory and leaves the engine intact', async () => {
const root = project({ 'src/components.ts': COMPONENTS, 'src/systems.ts': PROMISED });
- const out = await buildCompiledSystems(root, { mode: 'release', emcc: EMCC, run });
+ const out = await buildCompiledSystems(root, { mode: 'release', cc: EMCC, run });
expect(out.errors).toEqual([]);
const { default: createEngine } = await import(pathToFileURL(ENGINE_GLUE!).href) as
@@ -147,7 +149,7 @@ describe.skipIf(!EMCC || !ENGINE_GLUE)('loaded into the engine the build produce
expect(engine.HEAPU8.buffer).toBe(engine.wasmMemory.buffer);
const canary = engine.HEAPU8.slice(1024, 1024 + 4096);
- const bytes = readFileSync(out.wasmPath!);
+ const bytes = readFileSync(out.modulePath!);
new WebAssembly.Instance(new WebAssembly.Module(bytes as unknown as BufferSource),
{ env: { memory: engine.wasmMemory } });
@@ -165,24 +167,24 @@ describe('the AOT build step', () => {
it('a project that promised nothing is not a build step', async () => {
const root = project({ 'src/components.ts': COMPONENTS, 'src/systems.ts': UNMARKED });
- const out = await buildCompiledSystems(root, { mode: 'release', emcc: EMCC, run });
+ const out = await buildCompiledSystems(root, { mode: 'release', cc: EMCC, run });
expect(out.ok).toBe(true);
- expect(out.wasmPath).toBeNull();
+ expect(out.modulePath).toBeNull();
// The refusal is still reported, as information: §3.2's fallback is the
// design, and a build that shouted about it would be crying wolf.
expect(out.errors).toEqual([]);
});
it('a project with no sources at all is fine', async () => {
- const out = await buildCompiledSystems(project({}), { mode: 'release', emcc: EMCC, run });
- expect(out).toMatchObject({ ok: true, wasmPath: null, errors: [] });
+ const out = await buildCompiledSystems(project({}), { mode: 'release', cc: EMCC, run });
+ expect(out).toMatchObject({ ok: true, modulePath: null, errors: [] });
});
it('a broken promise fails the build, naming the file and the line', async () => {
const root = project({ 'src/components.ts': COMPONENTS, 'src/systems.ts': BROKEN });
- const out = await buildCompiledSystems(root, { mode: 'release', emcc: EMCC, run });
+ const out = await buildCompiledSystems(root, { mode: 'release', cc: EMCC, run });
expect(out.ok).toBe(false);
- expect(out.wasmPath).toBeNull();
+ expect(out.modulePath).toBeNull();
expect(out.errors).toHaveLength(1);
expect(out.errors[0]).toContain('BrokenSystem');
expect(out.errors[0]).toMatch(/Math\.sin is implementation-defined/);
@@ -191,19 +193,19 @@ describe('the AOT build step', () => {
it('says what is missing when a promise needs a toolchain that is absent', async () => {
const root = project({ 'src/components.ts': COMPONENTS, 'src/systems.ts': PROMISED });
- const out = await buildCompiledSystems(root, { mode: 'release', emcc: null, run });
+ const out = await buildCompiledSystems(root, { mode: 'release', cc: null, run });
expect(out.ok).toBe(false);
expect(out.errors[0]).toMatch(/marked @compiled but there is no emcc/);
});
it.skipIf(!EMCC)('builds a module the engine can load, and a manifest for it', async () => {
const root = project({ 'src/components.ts': COMPONENTS, 'src/systems.ts': PROMISED });
- const out = await buildCompiledSystems(root, { mode: 'release', emcc: EMCC, run });
+ const out = await buildCompiledSystems(root, { mode: 'release', cc: EMCC, run });
expect(out.errors).toEqual([]);
expect(out.ok).toBe(true);
- expect(out.wasmPath).not.toBeNull();
+ expect(out.modulePath).not.toBeNull();
- const bytes = await import('node:fs').then((fs) => fs.readFileSync(out.wasmPath!));
+ const bytes = await import('node:fs').then((fs) => fs.readFileSync(out.modulePath!));
const module = new WebAssembly.Module(bytes as unknown as BufferSource);
// The property the whole shape rests on: the engine's memory, and nothing
// else — no function import, so no second channel back into the engine.
@@ -237,9 +239,9 @@ describe('the AOT build step', () => {
let bytes: Buffer;
beforeAll(async () => {
const root = project({ 'src/components.ts': COMPONENTS, 'src/systems.ts': PROMISED });
- const out = await buildCompiledSystems(root, { mode: 'release', emcc: EMCC, run });
+ const out = await buildCompiledSystems(root, { mode: 'release', cc: EMCC, run });
expect(out.errors).toEqual([]);
- bytes = readFileSync(out.wasmPath!);
+ bytes = readFileSync(out.modulePath!);
});
it('carries no data section, because those bytes are the engine\'s', () => {
@@ -303,10 +305,10 @@ describe('the AOT build step', () => {
it.skipIf(!EMCC)('rebuilding is not additive: the cache is what this build made', async () => {
const root = project({ 'src/components.ts': COMPONENTS, 'src/systems.ts': PROMISED });
- await buildCompiledSystems(root, { mode: 'release', emcc: EMCC, run });
+ await buildCompiledSystems(root, { mode: 'release', cc: EMCC, run });
writeFileSync(path.join(root, '.esengine/cache/aot/stale.c'), 'int leftover;\n');
- await buildCompiledSystems(root, { mode: 'release', emcc: EMCC, run });
+ await buildCompiledSystems(root, { mode: 'release', cc: EMCC, run });
// A file from a previous shape of the project must not survive into the one
// the engine loads next.
expect(existsSync(path.join(root, '.esengine/cache/aot/stale.c'))).toBe(false);
@@ -317,21 +319,77 @@ describe('the AOT build step', () => {
// No emcc, and a project that promised something: in release this is an
// error, and in dev it is not a build step at all. §9 — the preview
// interprets, so a machine with no emsdk still builds and runs everything.
- const out = await buildCompiledSystems(root, { mode: 'dev', emcc: null, run });
- expect(out).toMatchObject({ ok: true, wasmPath: null, errors: [] });
+ const out = await buildCompiledSystems(root, { mode: 'dev', cc: null, run });
+ expect(out).toMatchObject({ ok: true, modulePath: null, errors: [] });
});
it('and a dev build does not fail on a promise it is not collecting', async () => {
const root = project({ 'src/components.ts': COMPONENTS, 'src/systems.ts': BROKEN });
- const out = await buildCompiledSystems(root, { mode: 'dev', emcc: EMCC, run });
+ const out = await buildCompiledSystems(root, { mode: 'dev', cc: EMCC, run });
expect(out.ok).toBe(true);
expect(out.errors).toEqual([]);
});
it.skipIf(!EMCC)('ship compiles exactly as release does', async () => {
const root = project({ 'src/components.ts': COMPONENTS, 'src/systems.ts': PROMISED });
- const ship = await buildCompiledSystems(root, { mode: 'ship', emcc: EMCC, run });
+ const ship = await buildCompiledSystems(root, { mode: 'ship', cc: EMCC, run });
expect(ship.ok).toBe(true);
expect(ship.manifest?.systems.map((s) => s.name)).toEqual(['MoveSystem']);
});
});
+
+/**
+ * The other machine. Desktop hosts the engine in their own process, so an
+ * address there is a pointer and the module is a library they load — the same
+ * C at the other width, since the header picks the typedef.
+ */
+describe('the AOT build step, for a host that loads a library', () => {
+ it('reports whether this gate could run at all', () => {
+ if (!HOST_CC) console.warn('[aot-native] NO HOST C COMPILER — the native build did NOT run.');
+ });
+
+ it.skipIf(!HOST_CC)('builds a library named for this platform, and a manifest for it', async () => {
+ const root = project({ 'src/components.ts': COMPONENTS, 'src/systems.ts': PROMISED });
+ const out = await buildCompiledSystems(root, { mode: 'release', target: 'native', cc: HOST_CC, run });
+
+ expect(out.ok, out.errors.join('; ')).toBe(true);
+ expect(out.modulePath).toBe(path.join(root, '.esengine/cache/aot', `systems${nativeModuleExt()}`));
+ expect(existsSync(out.modulePath!)).toBe(true);
+ expect(out.manifest?.systems.map((s) => s.name)).toEqual(['MoveSystem']);
+ });
+
+ it.skipIf(!HOST_CC)('compiles the declaration table, which the wasm module must not carry', async () => {
+ const root = project({ 'src/components.ts': COMPONENTS, 'src/systems.ts': PROMISED });
+ await buildCompiledSystems(root, { mode: 'release', target: 'native', cc: HOST_CC, run });
+ expect(existsSync(path.join(root, '.esengine/cache/aot/systems_decl.c'))).toBe(true);
+
+ // And the wasm build of the SAME project does not write one: its data
+ // section would land at an address the engine already owns.
+ if (EMCC) {
+ const wasmRoot = project({ 'src/components.ts': COMPONENTS, 'src/systems.ts': PROMISED });
+ await buildCompiledSystems(wasmRoot, { mode: 'release', cc: EMCC, run });
+ expect(existsSync(path.join(wasmRoot, '.esengine/cache/aot/systems_decl.c'))).toBe(false);
+ }
+ });
+
+ it.skipIf(!(HOST_CC && EMCC))('bakes a different handshake, so neither host takes the other artifact', async () => {
+ const src = { 'src/components.ts': COMPONENTS, 'src/systems.ts': PROMISED };
+ const native = await buildCompiledSystems(project(src), { mode: 'release', target: 'native', cc: HOST_CC, run });
+ const web = await buildCompiledSystems(project(src), { mode: 'release', cc: EMCC, run });
+
+ expect(native.manifest!.engineAbi).not.toBe(web.manifest!.engineAbi);
+ // The project's own shapes are the contract and do NOT move with the width.
+ expect(native.manifest!.projectShapes).toBe(web.manifest!.projectShapes);
+ });
+
+ it.skipIf(!HOST_CC)('says what is missing when this machine has no C compiler', async () => {
+ const root = project({ 'src/components.ts': COMPONENTS, 'src/systems.ts': PROMISED });
+ const out = await buildCompiledSystems(root, { mode: 'release', target: 'native', cc: null, run });
+
+ expect(out.ok).toBe(false);
+ // Not emcc: a machine can have one and lack the other, and being sent to
+ // install the wrong toolchain is worse than being told nothing.
+ expect(out.errors[0]).toMatch(/no C compiler/);
+ expect(out.errors[0]).not.toMatch(/emsdk/);
+ });
+});