1
0
Fork 0

Separate compilation of stdlib

This commit is contained in:
Pabloader 2025-05-29 15:39:25 +00:00
parent 691d698ba9
commit 23b2e53038
4 changed files with 21 additions and 4 deletions

View File

@ -105,7 +105,7 @@ export async function buildHTML(game: string, { production = false, portable = f
}
const resultHTML = html
.replace('<!--$SCRIPT$-->', () => `${scriptPrefix}<script type="module">${script}</script>`)
.replace('<!--$SCRIPT$-->', `${scriptPrefix}<script type="module">${script}</script>`)
.replace('<!--$TITLE$-->', title)
.replace('<!--$ICON$-->', icon)
.replace('<!--$MANIFEST$-->', manifest)

View File

@ -92,11 +92,19 @@ const wasmPlugin = ({ production, portable }: WasmLoaderConfig = {}): BunPlugin
const glob = new Bun.Glob(`${buildAssets}/lib/**/*.c`);
const stdlib = await Array.fromAsync(glob.scan());
const opt = production ? '-O3' : '-O0';
const result = await $`clang --target=wasm32 ${opt} -flto -fno-builtin --no-standard-libraries -I ${include} -Wall -Wextra -Wpedantic -Werror -Wno-gnu-anonymous-struct -Wl,--lto-O3 -Wl,--no-entry -Wl,--import-memory -o ${wasmPath} ${args.path} ${stdlib}`;
const objPath = wasmPath + '.o';
const std = args.path.endsWith('.cpp') ? '-std=gnu++23': '-std=gnu23';
const compileResult = await $`clang -c --target=wasm32 ${opt} -flto -fno-builtin --no-standard-libraries -I ${include} -Wall -Wextra -Wpedantic -Werror ${std} -o ${objPath} ${args.path}`;
if (result.exitCode !== 0) {
if (compileResult.exitCode !== 0) {
throw new Error('Compile failed, check output');
}
const linkResult = await $`clang --target=wasm32 ${opt} -flto -fno-builtin --no-standard-libraries -I ${include} -Wall -Wextra -Wpedantic -Werror -std=gnu23 -Wl,--lto-O3 -Wl,--no-entry -Wl,--import-memory -o ${wasmPath} ${objPath} ${stdlib}`;
if (linkResult.exitCode !== 0) {
throw new Error('Link failed, check output');
}
}
const wasmContent = await Bun.file(wasmPath).arrayBuffer();

View File

@ -1,4 +1,5 @@
--target=wasm32
-std=gnu++23
-fno-builtin
--no-standard-libraries
-I

View File

@ -1,7 +1,15 @@
#include <stdlib.h>
typedef struct {
union {
int a;
char b;
};
const char* string;
} awoorwa;
EXPORT(main) void init() {
uint32_t result = 42;
awoorwa result = {.a = 42, .string = "awoo"};
printf("%d\n", result);
}