Skip to content

Commit

Permalink
Merge pull request #26 from gwsystems/fix-mac
Browse files Browse the repository at this point in the history
Resolve Mac Build Issues
  • Loading branch information
bushidocodes authored Mar 25, 2021
2 parents fa6e003 + f03c366 commit a8c473b
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 29 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ silverfish.iml
.vagrant
Vagrantfile
*-cloudimg-console.log

wasi-sdk
.vscode
9 changes: 8 additions & 1 deletion code_benches/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
35 changes: 35 additions & 0 deletions install_mac.sh
Original file line number Diff line number Diff line change
@@ -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
12 changes: 0 additions & 12 deletions runtime/libc/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
16 changes: 16 additions & 0 deletions runtime/libc/wasi_sdk_backing.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions runtime/libc/wasmception_backing.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

17 changes: 1 addition & 16 deletions runtime/runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 3 additions & 0 deletions runtime/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit a8c473b

Please sign in to comment.