-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from turbolent/bootstrapping
- Loading branch information
Showing
5 changed files
with
101 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/bin/bash -ex | ||
|
||
WASI_SDK_PATH=/opt/wasi-sdk | ||
CC=${WASI_SDK_PATH}/bin/clang | ||
|
||
cat >w2c2_main.c <<END | ||
#include <stdio.h> | ||
#include "w2c2_base.h" | ||
#include "wasi.h" | ||
#include "w2c2.h" | ||
void | ||
trap( | ||
Trap trap | ||
) { | ||
fprintf(stderr, "TRAP: %s\n", trapDescription(trap)); | ||
abort(); | ||
} | ||
wasmMemory* | ||
wasiMemory( | ||
void* instance | ||
) { | ||
return w2c2_memory((w2c2Instance*)instance); | ||
} | ||
extern char** environ; | ||
/* Main */ | ||
int main(int argc, char* argv[]) { | ||
/* Initialize WASI */ | ||
if (!wasiInit(argc, argv, environ)) { | ||
fprintf(stderr, "failed to init WASI\n"); | ||
return 1; | ||
} | ||
if (!wasiFileDescriptorAdd(-1, "/", NULL)) { | ||
fprintf(stderr, "failed to add preopen\n"); | ||
return 1; | ||
} | ||
{ | ||
w2c2Instance instance; | ||
w2c2Instantiate(&instance, NULL); | ||
w2c2__start(&instance); | ||
w2c2FreeInstance(&instance); | ||
} | ||
return 0; | ||
} | ||
END | ||
|
||
if ! [ -d build ]; then | ||
mkdir build | ||
cd build | ||
mkdir w2c2 | ||
cd w2c2 | ||
CFLAGS="-Wl,--stack-first -Wl,-z,stack-size=1048576" cmake ../../../w2c2 -DCMAKE_TOOLCHAIN_FILE=${WASI_SDK_PATH}/share/cmake/wasi-sdk.cmake -DCMAKE_BUILD_TYPE=Debug | ||
make | ||
cd .. | ||
mkdir wasi | ||
cd wasi | ||
CFLAGS="-Wl,--stack-first -Wl,-z,stack-size=1048576" cmake ../../../wasi -DCMAKE_TOOLCHAIN_FILE=${WASI_SDK_PATH}/share/cmake/wasi-sdk.cmake -DCMAKE_BUILD_TYPE=Debug | ||
make | ||
cd ../.. | ||
fi | ||
|
||
rm -rf silly | ||
mkdir -p silly/gen1 | ||
cp build/w2c2/w2c2 silly/gen1/w2c2.wasm | ||
|
||
function breed() { | ||
genX=gen$1 | ||
genY=gen$(($1 + 1)) | ||
echo "=======> breeding ${genX} into ${genY}" >&2 | ||
|
||
mkdir -p silly/${genY} | ||
wasmtime run --dir . "silly/${genX}/w2c2.wasm" "silly/${genX}/w2c2.wasm" "silly/${genY}/w2c2.c" | ||
${CC} -I../w2c2 -I../wasi -Isilly/${genY} build/wasi/libw2c2wasi.a silly/${genY}/w2c2.c w2c2_main.c -o silly/${genY}/w2c2.wasm | ||
} | ||
|
||
for gen in $(seq 1 10); do | ||
breed "$gen" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,4 +69,4 @@ gen-%: | |
$(PYTHON3) gen.py $* | ||
|
||
clean: | ||
-rm -f main.o test_*.o | ||
-rm -f main.o test_*.o test_*.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters