forked from cloudflare/workers-wasi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
70 lines (56 loc) · 2.49 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# disable built-in rules
.SUFFIXES:
all: dist/index.mjs
ci: test
npm pack --pack-destination ./build --quiet
@git diff --exit-code HEAD # error on unexpected changes, eg. out of date package-lock.json
test: all
cd ./test && $(MAKE)
clean:
rm -rf ./dist/
rm -rf ./build/
rm -rf ./node_modules/
rm -rf ./test/node_modules/
WASI_SDK_PATH := ./deps/wasi-sdk-16.0
WASI_SYSROOT := $(abspath ${WASI_SDK_PATH}/share/wasi-sysroot)
WASM_OPT_PATH := ./deps/binaryen
export CC := $(abspath ${WASI_SDK_PATH}/bin/clang) -target wasm32-wasi --sysroot=${WASI_SYSROOT}
export CFLAGS := -Oz -flto -I ./deps/rapidjson/include -I./deps/littlefs -fno-exceptions -include ./src/config.h -Wexit-time-destructors
export LDFLAGS := -lstdc++ -flto -Wl,--allow-undefined # -mexec-model=reactor
export CXXFLAGS := -std=c++20
WASM_OBJ := \
./build/obj/deps/littlefs/lfs.o \
./build/obj/deps/littlefs/lfs_util.o \
./build/obj/deps/littlefs/bd/lfs_rambd.o \
./build/obj/src/memfs.o \
./build/obj/src/util.o
HEADERS := $(wildcard ./src/*.h)
build/obj/%.o: %.c $(HEADERS) $(WASI_SDK_PATH)
mkdir -p $(@D)
$(CC) -c $(CFLAGS) $< -o $@
build/obj/%.o: %.cc $(HEADERS) $(WASI_SDK_PATH)
mkdir -p $(@D)
$(CC) -c $(CFLAGS) $(CXXFLAGS) $< -o $@
dist/memfs.wasm: $(WASM_OBJ)
mkdir -p $(@D)
PATH=${PATH}:$(abspath ${WASM_OPT_PATH}/bin) $(CC) $(CFLAGS) $(LDFLAGS) $(WASM_OBJ) -o $@
node_modules: ./package.json ./package-lock.json
npm install --no-audit --no-optional --no-fund --no-progress --quiet
touch $@
dist/index.mjs: $(wildcard ./src/**) node_modules dist/memfs.wasm
sed -i 's/^class Asyncify/export class Asyncify/g' ./deps/asyncify/asyncify.mjs
$(shell npm bin)/tsc -p ./tsconfig.json
$(shell npm bin)/esbuild --bundle ./src/index.ts --outfile=$@ --format=esm --log-level=warning --external:*.wasm
$(WASI_SDK_PATH): $(WASM_OPT_PATH)
mkdir -p $(@D)
curl -sLo wasi-sdk.tar.gz https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-16/wasi-sdk-16.0-linux.tar.gz
echo '10df3418485e60b9283c1132102f8d3ca34b4fbe8c4649e30282ee84fe42d788 wasi-sdk.tar.gz' | sha256sum -c
tar zxf wasi-sdk.tar.gz --touch -C deps
rm wasi-sdk.tar.gz
$(WASM_OPT_PATH):
@$(call color,"downloading binaryen")
mkdir -p $(@)
curl -Lo binaryen.tar.gz https://github.com/WebAssembly/binaryen/releases/download/version_110/binaryen-version_110-x86_64-linux.tar.gz
echo '978d794d3cd608b2c10573f7b7b2341a011a9804f4aae7efb608ed8751970faa binaryen.tar.gz' | sha256sum -c
tar zxvf binaryen.tar.gz --strip-components=1 --touch -C ./deps/binaryen
rm binaryen.tar.gz