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.

fix(aot): -fPIC is not a thing you can say to clang on the MSVC ABI

yhh0c938dcbb906
diff --git a/compiler/src/hostCC.ts b/compiler/src/hostCC.ts
index 3b7d34d3f..bf421fadf 100644
--- a/compiler/src/hostCC.ts
+++ b/compiler/src/hostCC.ts
@@ -37,8 +37,13 @@ export function nativeModuleExt(platform: string = process.platform): string {
* `-fPIC` because it is loaded, not linked; nothing else, because the C calls
* only what `estella_abi.h` defines `static inline` — the module has no
* undefined symbol to resolve and wants none of libc.
+ *
+ * Windows takes only `-shared`: a DLL is position-independent by construction,
+ * and clang on the MSVC ABI REJECTS `-fPIC` rather than ignoring it.
*/
-export const NATIVE_LINK_FLAGS: readonly string[] = ['-shared', '-fPIC'];
+export function nativeLinkFlags(platform: string = process.platform): readonly string[] {
+ return platform === 'win32' ? ['-shared'] : ['-shared', '-fPIC'];
+}
/**
* The host C compiler, or null where this machine has none.
diff --git a/compiler/tests/native-module.test.ts b/compiler/tests/native-module.test.ts
index 22cb422b3..f5462867d 100644
--- a/compiler/tests/native-module.test.ts
+++ b/compiler/tests/native-module.test.ts
@@ -30,7 +30,7 @@ import { inlineSystem } from '../src/inline';
import { builtinShapes } from '../src/builtins';
import { packLayout } from '../src/abi';
import { CFLAGS, cSymbol, emitC } from '../src/codegen';
-import { NATIVE_LINK_FLAGS, findHostCC, nativeModuleExt } from '../src/hostCC';
+import { nativeLinkFlags, findHostCC, nativeModuleExt } from '../src/hostCC';
const ROOT = resolve(fileURLToPath(new URL('../..', import.meta.url)));
const CC = findHostCC();
@@ -67,7 +67,7 @@ describe('the compiled systems, as a module a native host loads', () => {
const out = join(dir, `systems${nativeModuleExt()}`);
const built = spawnSync(CC!, [
- ...CFLAGS, '-Wall', '-Wextra', ...NATIVE_LINK_FLAGS,
+ ...CFLAGS, '-Wall', '-Wextra', ...nativeLinkFlags(),
'-o', out, join(dir, 'systems.c'), join(dir, 'systems_decl.c'),
], { encoding: 'utf8', cwd: dir });
diff --git a/pipeline/src/bundle/buildCompiledSystems.ts b/pipeline/src/bundle/buildCompiledSystems.ts
index 64fd03289..1fa553643 100644
--- a/pipeline/src/bundle/buildCompiledSystems.ts
+++ b/pipeline/src/bundle/buildCompiledSystems.ts
@@ -29,7 +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 { nativeLinkFlags, nativeModuleExt } from '../../../compiler/src/hostCC';
import { AOT_MANIFEST, AOT_WASM } from './aotArtifacts';
/** Where the C and the wasm land, beside the script bundle. */
@@ -118,7 +118,7 @@ const TARGETS: Record<CompileTarget, TargetPlan> = {
native: {
addressBytes: 8,
module: `systems${nativeModuleExt()}`,
- linkFlags: () => [...NATIVE_LINK_FLAGS],
+ linkFlags: () => [...nativeLinkFlags()],
compilesDecls: true,
missing: 'this machine has no C compiler — install clang or gcc and put it on PATH',
},