diff --git a/.gitignore b/.gitignore index 97811b6a..635a0249 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,6 @@ silverfish.iml .vagrant Vagrantfile *-cloudimg-console.log + +wasi-sdk +.vscode diff --git a/code_benches/run.py b/code_benches/run.py index a0bdc07b..1b9e3044 100755 --- a/code_benches/run.py +++ b/code_benches/run.py @@ -91,9 +91,16 @@ def getmtime_or_zero(x): WASI_SDK_SYSROOT = WASI_SDK_PATH + "/share/wasi-sysroot" WASI_SDK_FLAGS = "--target=wasm32-wasi -mcpu=mvp -nostartfiles -O3 -flto" WASI_SDK_BACKING = "wasi_sdk_backing.c" -WASI_SDK_URL = "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-8/wasi-sdk-8.0-linux.tar.gz" # download WASI-SDK if it is not in the expected path +if sys.platform == "linux" or sys.platform == "linux2": + WASI_SDK_URL = "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-8/wasi-sdk-8.0-linux.tar.gz" +elif sys.platform == "darwin": + WASI_SDK_URL = "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-8/wasi-sdk-8.0-macos.tar.gz" +else: + print("awsm supports Linux and Mac OS, saw {}".format(sys.platform)) + exit(1) + if args.wasi_sdk: if not os.path.exists(WASI_SDK_PATH): cwd = os.path.dirname(WASI_SDK_PATH) diff --git a/install_mac.sh b/install_mac.sh new file mode 100755 index 00000000..1a242de6 --- /dev/null +++ b/install_mac.sh @@ -0,0 +1,35 @@ +#!/bin/zsh +git submodule update --init --recursive + +# Install brew +if [[ -x "$(command -v brew)" ]]; then + echo "Brew install detected" +else + curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh | bash -s -- -y +fi + +# Install required tools +brew install svn +brew install wget +brew install cmake + +# Install LLVM and clang stuff +xcode-select install +if [[ -x "$(command -v rustup)" ]]; then + echo "LLVM detected" +else + brew install llvm + echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >>~/.zshrc +fi + +# Install Rust +if [[ -x "$(command -v rustup)" ]]; then + rustup update +else + curl https://sh.rustup.rs -sSf | bash -s -- -y +fi +source "$HOME/.cargo/env" +export PATH="$HOME/.cargo/bin:$PATH" + +# Build project +cargo build --release diff --git a/runtime/libc/env.c b/runtime/libc/env.c index a55d6172..51719865 100644 --- a/runtime/libc/env.c +++ b/runtime/libc/env.c @@ -145,15 +145,3 @@ env_getcycles(void) #endif } - -// Floating point routines -// TODO: Do a fair comparison between musl and wasm-musl -INLINE double -env_sin(double d) { - return sin(d); -} - -INLINE double -env_cos(double d) { - return cos(d); -} diff --git a/runtime/libc/wasi_sdk_backing.c b/runtime/libc/wasi_sdk_backing.c index 7a5b3576..a7f34df3 100644 --- a/runtime/libc/wasi_sdk_backing.c +++ b/runtime/libc/wasi_sdk_backing.c @@ -17,6 +17,16 @@ #include "../runtime.h" +/* POSIX compatibility shims */ +#ifndef O_RSYNC +#define O_RSYNC O_SYNC +#endif + +#ifdef __APPLE__ +#undef fdatasync +#define fdatasync fsync +#endif + int main(int argc, char* argv[]) { runtime_main(argc, argv); printf("mem use = %d\n", (int) memory_size); @@ -276,7 +286,13 @@ static i32 wasi_fromerrno(int errno_) { case ETIMEDOUT: return WASI_ETIMEDOUT; case ETXTBSY: return WASI_ETXTBSY; case EXDEV: return WASI_EXDEV; + default: + fprintf(stderr, "wasi_fromerrno unexpectedly received: %s\n", strerror(errno_)); + fflush(stderr); } + + silverfish_assert(0); + return 0; } // file operations diff --git a/runtime/libc/wasmception_backing.c b/runtime/libc/wasmception_backing.c index 20df928e..59dfd8c6 100644 --- a/runtime/libc/wasmception_backing.c +++ b/runtime/libc/wasmception_backing.c @@ -627,3 +627,15 @@ void env___unmapself(u32 base, u32 size) { // Just do some no op } +// Floating point routines +// TODO: Do a fair comparison between musl and wasm-musl +INLINE double +env_sin(double d) { + return sin(d); +} + +INLINE double +env_cos(double d) { + return cos(d); +} + diff --git a/runtime/runtime.c b/runtime/runtime.c index 30a843d5..44c9cfc9 100644 --- a/runtime/runtime.c +++ b/runtime/runtime.c @@ -207,22 +207,7 @@ INLINE double f64_copysign(double a, double b) { return copysign(a, b); } -// Memory related instructions -i32 instruction_memory_size() { - return memory_size / WASM_PAGE_SIZE; -} - -i32 instruction_memory_grow(i32 count) { - i32 prev_size = instruction_memory_size(); - for (int i = 0; i < count; i++) { - expand_memory(); - } - - return prev_size; -} - - -// We want to have some allocation logic +// We want to have some allocation logic here, so we can use it to implement libc WEAK u32 wasmg___heap_base = 0; u32 runtime_heap_base; diff --git a/runtime/runtime.h b/runtime/runtime.h index 1cbb621d..d5c03e15 100644 --- a/runtime/runtime.h +++ b/runtime/runtime.h @@ -113,6 +113,9 @@ INLINE double get_f64(u32 offset); INLINE void set_f32(u32 offset, float); INLINE void set_f64(u32 offset, double); +i32 instruction_memory_size(); +i32 instruction_memory_grow(); + static inline void* get_memory_ptr_void(u32 offset, u32 bounds_check) { return (void*) get_memory_ptr_for_runtime(offset, bounds_check); }