From 6dfee919b4c72b875208e6f1dc9b6647085c7c42 Mon Sep 17 00:00:00 2001 From: Pabloader Date: Fri, 30 Aug 2024 15:40:23 +0000 Subject: [PATCH] Fix c compilation --- build/wasmPlugin.ts | 4 ++-- src/games/life/life.c | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/build/wasmPlugin.ts b/build/wasmPlugin.ts index f209375..95f8d32 100644 --- a/build/wasmPlugin.ts +++ b/build/wasmPlugin.ts @@ -12,11 +12,11 @@ const wasmPlugin = ({ production, portable }: WasmLoaderConfig = {}): BunPlugin name: "WASM loader", async setup(build) { build.onLoad({ filter: /\.(c(pp)?|wasm(\.ts)?)$/ }, async (args) => { - let wasmPath = path.resolve(import.meta.dir, '..', '..', 'dist', 'tmp.wasm'); + let wasmPath = path.resolve(import.meta.dir, '..', 'dist', 'tmp.wasm'); let jsContent: string = ` async function instantiate(url) { const memory = new WebAssembly.Memory({ - initial: 16, + initial: 32, }); let data = new DataView(memory.buffer); const { instance } = await WebAssembly.instantiateStreaming(fetch(url), { diff --git a/src/games/life/life.c b/src/games/life/life.c index 4a09696..3dd57d7 100644 --- a/src/games/life/life.c +++ b/src/games/life/life.c @@ -1,4 +1,5 @@ #include +#include #define width 512 #define height 512 @@ -7,15 +8,14 @@ static uint8_t field[width * height]; static uint8_t nextField[width * height]; static uint8_t pixels[width * height * 4]; -void* malloc(uint32_t n); static uint8_t rand8(void); static int countNeighbours(int x, int y); -int getWidth(void) { return width; } -int getHeight(void) { return height; } -uint8_t* getPixels(void) { return pixels; } +EXPORT(getWidth) int get_width(void) { return width; } +EXPORT(getHeight) int get_height(void) { return height; } +EXPORT(getPixels) uint8_t* get_pixels(void) { return pixels; } -void step(void) +EXPORT(step) void step(void) { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { @@ -93,7 +93,7 @@ static uint8_t rand8(void) return x; } -void initField(uint32_t randomSeed) +EXPORT(initField) void init_field(uint32_t randomSeed) { *((uint32_t*)&rand_state[STATE_BYTES - sizeof(uint32_t)]) = randomSeed; // Voodoo