Skip to content

Commit a8c473b

Browse files
authored
Merge pull request #26 from gwsystems/fix-mac
Resolve Mac Build Issues
2 parents fa6e003 + f03c366 commit a8c473b

File tree

8 files changed

+78
-29
lines changed

8 files changed

+78
-29
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ silverfish.iml
2222
.vagrant
2323
Vagrantfile
2424
*-cloudimg-console.log
25+
26+
wasi-sdk
27+
.vscode

code_benches/run.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,16 @@ def getmtime_or_zero(x):
9191
WASI_SDK_SYSROOT = WASI_SDK_PATH + "/share/wasi-sysroot"
9292
WASI_SDK_FLAGS = "--target=wasm32-wasi -mcpu=mvp -nostartfiles -O3 -flto"
9393
WASI_SDK_BACKING = "wasi_sdk_backing.c"
94-
WASI_SDK_URL = "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-8/wasi-sdk-8.0-linux.tar.gz"
9594

9695
# download WASI-SDK if it is not in the expected path
96+
if sys.platform == "linux" or sys.platform == "linux2":
97+
WASI_SDK_URL = "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-8/wasi-sdk-8.0-linux.tar.gz"
98+
elif sys.platform == "darwin":
99+
WASI_SDK_URL = "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-8/wasi-sdk-8.0-macos.tar.gz"
100+
else:
101+
print("awsm supports Linux and Mac OS, saw {}".format(sys.platform))
102+
exit(1)
103+
97104
if args.wasi_sdk:
98105
if not os.path.exists(WASI_SDK_PATH):
99106
cwd = os.path.dirname(WASI_SDK_PATH)

install_mac.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/zsh
2+
git submodule update --init --recursive
3+
4+
# Install brew
5+
if [[ -x "$(command -v brew)" ]]; then
6+
echo "Brew install detected"
7+
else
8+
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh | bash -s -- -y
9+
fi
10+
11+
# Install required tools
12+
brew install svn
13+
brew install wget
14+
brew install cmake
15+
16+
# Install LLVM and clang stuff
17+
xcode-select install
18+
if [[ -x "$(command -v rustup)" ]]; then
19+
echo "LLVM detected"
20+
else
21+
brew install llvm
22+
echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >>~/.zshrc
23+
fi
24+
25+
# Install Rust
26+
if [[ -x "$(command -v rustup)" ]]; then
27+
rustup update
28+
else
29+
curl https://sh.rustup.rs -sSf | bash -s -- -y
30+
fi
31+
source "$HOME/.cargo/env"
32+
export PATH="$HOME/.cargo/bin:$PATH"
33+
34+
# Build project
35+
cargo build --release

runtime/libc/env.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,3 @@ env_getcycles(void)
145145

146146
#endif
147147
}
148-
149-
// Floating point routines
150-
// TODO: Do a fair comparison between musl and wasm-musl
151-
INLINE double
152-
env_sin(double d) {
153-
return sin(d);
154-
}
155-
156-
INLINE double
157-
env_cos(double d) {
158-
return cos(d);
159-
}

runtime/libc/wasi_sdk_backing.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@
1717

1818
#include "../runtime.h"
1919

20+
/* POSIX compatibility shims */
21+
#ifndef O_RSYNC
22+
#define O_RSYNC O_SYNC
23+
#endif
24+
25+
#ifdef __APPLE__
26+
#undef fdatasync
27+
#define fdatasync fsync
28+
#endif
29+
2030
int main(int argc, char* argv[]) {
2131
runtime_main(argc, argv);
2232
printf("mem use = %d\n", (int) memory_size);
@@ -276,7 +286,13 @@ static i32 wasi_fromerrno(int errno_) {
276286
case ETIMEDOUT: return WASI_ETIMEDOUT;
277287
case ETXTBSY: return WASI_ETXTBSY;
278288
case EXDEV: return WASI_EXDEV;
289+
default:
290+
fprintf(stderr, "wasi_fromerrno unexpectedly received: %s\n", strerror(errno_));
291+
fflush(stderr);
279292
}
293+
294+
silverfish_assert(0);
295+
return 0;
280296
}
281297

282298
// file operations

runtime/libc/wasmception_backing.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,3 +627,15 @@ void env___unmapself(u32 base, u32 size) {
627627
// Just do some no op
628628
}
629629

630+
// Floating point routines
631+
// TODO: Do a fair comparison between musl and wasm-musl
632+
INLINE double
633+
env_sin(double d) {
634+
return sin(d);
635+
}
636+
637+
INLINE double
638+
env_cos(double d) {
639+
return cos(d);
640+
}
641+

runtime/runtime.c

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -207,22 +207,7 @@ INLINE double f64_copysign(double a, double b) {
207207
return copysign(a, b);
208208
}
209209

210-
// Memory related instructions
211-
i32 instruction_memory_size() {
212-
return memory_size / WASM_PAGE_SIZE;
213-
}
214-
215-
i32 instruction_memory_grow(i32 count) {
216-
i32 prev_size = instruction_memory_size();
217-
for (int i = 0; i < count; i++) {
218-
expand_memory();
219-
}
220-
221-
return prev_size;
222-
}
223-
224-
225-
// We want to have some allocation logic
210+
// We want to have some allocation logic here, so we can use it to implement libc
226211
WEAK u32 wasmg___heap_base = 0;
227212
u32 runtime_heap_base;
228213

runtime/runtime.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ INLINE double get_f64(u32 offset);
113113
INLINE void set_f32(u32 offset, float);
114114
INLINE void set_f64(u32 offset, double);
115115

116+
i32 instruction_memory_size();
117+
i32 instruction_memory_grow();
118+
116119
static inline void* get_memory_ptr_void(u32 offset, u32 bounds_check) {
117120
return (void*) get_memory_ptr_for_runtime(offset, bounds_check);
118121
}

0 commit comments

Comments
 (0)