Skip to content

Commit

Permalink
Add wasm target to Makefile
Browse files Browse the repository at this point in the history
Allows building an WASM-ready archive with emscripten.

This allows e.g. to compile to the `wasm32-unknown-unknown`
target with Rust.

Related matrix-rust-sdk PR:
matrix-org/matrix-rust-sdk#31

Signed-off-by: stoically <stoically@protonmail.com>
  • Loading branch information
stoically authored and uhoreg committed May 7, 2020
1 parent 9cc2394 commit 611d394
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ JS_OPTIMIZE_FLAGS ?= -O3
FUZZING_OPTIMIZE_FLAGS ?= -O3
CC = gcc
EMCC = emcc
EMAR = emar
AFL_CC = afl-gcc
AFL_CXX = afl-g++
AR = ar
Expand All @@ -29,6 +30,7 @@ STATIC_RELEASE_TARGET := $(BUILD_DIR)/libolm.a
DEBUG_TARGET := $(BUILD_DIR)/libolm_debug.$(SO).$(VERSION)
JS_WASM_TARGET := javascript/olm.js
JS_ASMJS_TARGET := javascript/olm_legacy.js
WASM_TARGET := $(BUILD_DIR)/wasm/libolm.a

JS_EXPORTED_FUNCTIONS := javascript/exported_functions.json
JS_EXTRA_EXPORTED_RUNTIME_METHODS := ALLOC_STACK
Expand All @@ -52,6 +54,7 @@ FUZZER_BINARIES := $(addprefix $(BUILD_DIR)/,$(basename $(FUZZER_SOURCES)))
FUZZER_DEBUG_BINARIES := $(patsubst $(BUILD_DIR)/fuzzers/fuzz_%,$(BUILD_DIR)/fuzzers/debug_%,$(FUZZER_BINARIES))
TEST_BINARIES := $(patsubst tests/%,$(BUILD_DIR)/tests/%,$(basename $(TEST_SOURCES)))
JS_OBJECTS := $(addprefix $(BUILD_DIR)/javascript/,$(OBJECTS))
WASM_OBJECTS := $(addprefix $(BUILD_DIR)/wasm/,$(OBJECTS))

# pre & post are the js-pre/js-post options to emcc.
# They are injected inside the modularised code and
Expand Down Expand Up @@ -182,6 +185,12 @@ $(STATIC_RELEASE_TARGET): $(RELEASE_OBJECTS)
js: $(JS_WASM_TARGET) $(JS_ASMJS_TARGET)
.PHONY: js

wasm: $(WASM_TARGET)
.PHONY: wasm

$(WASM_TARGET): $(WASM_OBJECTS)
$(EMAR) rcs $@ $^

# Note that the output file we give to emcc determines the name of the
# wasm file baked into the js, hence messing around outputting to olm.js
# and then renaming it.
Expand Down Expand Up @@ -278,6 +287,14 @@ $(BUILD_DIR)/javascript/%.o: %.cpp
$(call mkdir,$(dir $@))
$(EMCC.cc) $(OUTPUT_OPTION) $<

$(BUILD_DIR)/wasm/%.o: %.c
$(call mkdir,$(dir $@))
$(EMCC.c) $(OUTPUT_OPTION) $<

$(BUILD_DIR)/wasm/%.o: %.cpp
$(call mkdir,$(dir $@))
$(EMCC.cc) $(OUTPUT_OPTION) $<

$(BUILD_DIR)/tests/%: tests/%.c $(DEBUG_OBJECTS)
$(call mkdir,$(dir $@))
$(LINK.c) $< $(DEBUG_OBJECTS) $(LOADLIBES) $(LDLIBS) -o $@
Expand Down

0 comments on commit 611d394

Please sign in to comment.