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(pipeline): the build mode decides whether a promise is collected

yhh2d8fecf6dbb4
diff --git a/pipeline/src/bundle/buildCompiledSystems.ts b/pipeline/src/bundle/buildCompiledSystems.ts
index 2aef2d51b..c4473162c 100644
--- a/pipeline/src/bundle/buildCompiledSystems.ts
+++ b/pipeline/src/bundle/buildCompiledSystems.ts
@@ -15,11 +15,11 @@
* build step; a marked system that will not compile IS one, because that is what
* the marker means.
*
- * NOT yet called by `estella build`. Wiring it in makes emcc a requirement for
- * any project carrying a marker, and whether that is an error or a warning is a
- * question the dev / release / ship modes answer — they do not exist yet, and
- * failing every build on a machine without emsdk is the wrong default to pick
- * by accident.
+ * The mode decides whether it runs at all. `dev` never compiles: §9 says the
+ * editor's preview always interprets, so a machine with no emsdk builds and runs
+ * every project. `release` and `ship` do compile, and there a promise the subset
+ * cannot keep is an error rather than a quiet fallback — which is the difference
+ * the marker exists to make.
*/
import { existsSync, mkdirSync, readdirSync, rmSync, statSync, writeFileSync, readFileSync } from 'node:fs';
import path from 'node:path';
@@ -53,6 +53,12 @@ export interface CompiledSystemsManifest {
systems: CompiledSystemInfo[];
}
+/**
+ * Which build this is. Not a verbosity setting: it decides whether a `@compiled`
+ * marker is a promise anyone is collecting on.
+ */
+export type BuildMode = 'dev' | 'release' | 'ship';
+
export interface BuildCompiledResult {
ok: boolean;
/** Absolute path to the wasm, or null when there was nothing to build. */
@@ -88,12 +94,20 @@ function sources(root: string): string[] {
export async function buildCompiledSystems(
root: string,
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;
/** 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> {
+ 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: [] };
+ }
const files = sources(root);
if (files.length === 0) {
return { ok: true, wasmPath: null, manifest: null, errors: [], notes: [] };
diff --git a/pipeline/tests/build-compiled-systems.test.ts b/pipeline/tests/build-compiled-systems.test.ts
index 140e194cb..f19927925 100644
--- a/pipeline/tests/build-compiled-systems.test.ts
+++ b/pipeline/tests/build-compiled-systems.test.ts
@@ -88,7 +88,7 @@ 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, { emcc: EMCC, run });
+ const out = await buildCompiledSystems(root, { mode: 'release', emcc: EMCC, run });
expect(out.ok).toBe(true);
expect(out.wasmPath).toBeNull();
// The refusal is still reported, as information: §3.2's fallback is the
@@ -97,13 +97,13 @@ describe('the AOT build step', () => {
});
it('a project with no sources at all is fine', async () => {
- const out = await buildCompiledSystems(project({}), { emcc: EMCC, run });
+ const out = await buildCompiledSystems(project({}), { mode: 'release', emcc: EMCC, run });
expect(out).toMatchObject({ ok: true, wasmPath: 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, { emcc: EMCC, run });
+ const out = await buildCompiledSystems(root, { mode: 'release', emcc: EMCC, run });
expect(out.ok).toBe(false);
expect(out.wasmPath).toBeNull();
expect(out.errors).toHaveLength(1);
@@ -114,14 +114,14 @@ 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, { emcc: null, run });
+ const out = await buildCompiledSystems(root, { mode: 'release', emcc: 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, { emcc: EMCC, run });
+ const out = await buildCompiledSystems(root, { mode: 'release', emcc: EMCC, run });
expect(out.errors).toEqual([]);
expect(out.ok).toBe(true);
expect(out.wasmPath).not.toBeNull();
@@ -148,12 +148,35 @@ 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, { emcc: EMCC, run });
+ await buildCompiledSystems(root, { mode: 'release', emcc: EMCC, run });
writeFileSync(path.join(root, '.esengine/cache/aot/stale.c'), 'int leftover;\n');
- await buildCompiledSystems(root, { emcc: EMCC, run });
+ await buildCompiledSystems(root, { mode: 'release', emcc: 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);
});
+
+ it('a dev build never compiles, so a marker costs it nothing', async () => {
+ const root = project({ 'src/components.ts': COMPONENTS, 'src/systems.ts': PROMISED });
+ // 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: [] });
+ });
+
+ 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 });
+ 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 });
+ expect(ship.ok).toBe(true);
+ expect(ship.manifest?.systems.map((s) => s.name)).toEqual(['MoveSystem']);
+ });
});