Separate compilation of stdlib
This commit is contained in:
parent
691d698ba9
commit
23b2e53038
|
|
@ -105,7 +105,7 @@ export async function buildHTML(game: string, { production = false, portable = f
|
||||||
}
|
}
|
||||||
|
|
||||||
const resultHTML = html
|
const resultHTML = html
|
||||||
.replace('<!--$SCRIPT$-->', () => `${scriptPrefix}<script type="module">${script}</script>`)
|
.replace('<!--$SCRIPT$-->', `${scriptPrefix}<script type="module">${script}</script>`)
|
||||||
.replace('<!--$TITLE$-->', title)
|
.replace('<!--$TITLE$-->', title)
|
||||||
.replace('<!--$ICON$-->', icon)
|
.replace('<!--$ICON$-->', icon)
|
||||||
.replace('<!--$MANIFEST$-->', manifest)
|
.replace('<!--$MANIFEST$-->', manifest)
|
||||||
|
|
|
||||||
|
|
@ -92,11 +92,19 @@ const wasmPlugin = ({ production, portable }: WasmLoaderConfig = {}): BunPlugin
|
||||||
const glob = new Bun.Glob(`${buildAssets}/lib/**/*.c`);
|
const glob = new Bun.Glob(`${buildAssets}/lib/**/*.c`);
|
||||||
const stdlib = await Array.fromAsync(glob.scan());
|
const stdlib = await Array.fromAsync(glob.scan());
|
||||||
const opt = production ? '-O3' : '-O0';
|
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');
|
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();
|
const wasmContent = await Bun.file(wasmPath).arrayBuffer();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
--target=wasm32
|
--target=wasm32
|
||||||
|
-std=gnu++23
|
||||||
-fno-builtin
|
-fno-builtin
|
||||||
--no-standard-libraries
|
--no-standard-libraries
|
||||||
-I
|
-I
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,15 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
union {
|
||||||
|
int a;
|
||||||
|
char b;
|
||||||
|
};
|
||||||
|
const char* string;
|
||||||
|
} awoorwa;
|
||||||
|
|
||||||
EXPORT(main) void init() {
|
EXPORT(main) void init() {
|
||||||
uint32_t result = 42;
|
awoorwa result = {.a = 42, .string = "awoo"};
|
||||||
|
|
||||||
printf("%d\n", result);
|
printf("%d\n", result);
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue