Skip to content

Commit

Permalink
Merge pull request #522 from ChinYikMing/safari-wasm-lto
Browse files Browse the repository at this point in the history
Check Safari version if it supports TCO for Wasm
  • Loading branch information
jserv authored Dec 21, 2024
2 parents ff829ee + c617a29 commit 5b90d0f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,9 @@ $ tools/rv_profiler [--start-address|--stop-address|--graph-ir] [test_program]
Thus, the target system should have the Emscripten version 3.1.51 installed.

Moreover, `rv32emu` leverages the tail call optimization (TCO) and we have tested the WebAssembly
execution in Chrome with at least MAJOR 112 and Firefox with at least MAJOR 121 since they supports
tail call feature. Thus, please check and update your browsers if necessary or install the suitable browsers
before going further.
execution in Chrome with at least MAJOR 112, Firefox with at least MAJOR 121 and Safari with at least version 18.2
since they supports tail call feature. Please check your browser version and update if necessary, or install a compatible
browser before proceeding.

Source your Emscripten SDK environment before make. For macOS and Linux user:
```shell
Expand Down
26 changes: 25 additions & 1 deletion mk/wasm.mk
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ $(OUT)/elf_list.js: tools/gen-elf-list-js.py
# used to download all dependencies of elf executable and bundle into single wasm
deps_emcc += artifact $(OUT)/elf_list.js $(DOOM_DATA) $(QUAKE_DATA) $(TIMIDITY_DATA)

# check browser MAJOR version if supports TCO
# check browser version if supports TCO
CHROME_MAJOR :=
CHROME_MAJOR_VERSION_CHECK_CMD :=
CHROME_SUPPORT_TCO_AT_MAJOR := 112
Expand All @@ -57,10 +57,21 @@ FIREFOX_SUPPORT_TCO_AT_MAJOR := 121
FIREFOX_SUPPORT_TCO_INFO := Firefox supports TCO, you can use Firefox to request the wasm
FIREFOX_NO_SUPPORT_TCO_WARNING := Firefox not found or Firefox must have at least version $(FIREFOX_SUPPORT_TCO_AT_MAJOR) in MAJOR to support TCO in wasm

# Check WebAssembly section at https://webkit.org/blog/16301/webkit-features-in-safari-18-2/
ifeq ($(UNAME_S),Darwin)
SAFARI_MAJOR :=
SAFARI_MINOR :=
SAFARI_VERSION_CHECK_CMD :=
SAFARI_SUPPORT_TCO_AT_MAJOR_MINOR := 18.2
SAFARI_SUPPORT_TCO_INFO := Safari supports TCO, you can use Safari to request the wasm
SAFARI_NO_SUPPORT_TCO_WARNING := Safari not found or Safari must have at least version $(SAFARI_SUPPORT_TCO_AT_MAJOR_MINOR) to support TCO in wasm
endif

# FIXME: for Windows
ifeq ($(UNAME_S),Darwin)
CHROME_MAJOR_VERSION_CHECK_CMD := "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --version | awk '{print $$3}' | cut -f1 -d.
FIREFOX_MAJOR_VERSION_CHECK_CMD := /Applications/Firefox.app/Contents/MacOS/firefox --version | awk '{print $$3}' | cut -f1 -d.
SAFARI_VERSION_CHECK_CMD := mdls -name kMDItemVersion /Applications/Safari.app | sed 's/"//g' | awk '{print $$3}'
else ifeq ($(UNAME_S),Linux)
CHROME_MAJOR_VERSION_CHECK_CMD := google-chrome --version | awk '{print $$3}' | cut -f1 -d.
FIREFOX_MAJOR_VERSION_CHECK_CMD := firefox -v | awk '{print $$3}' | cut -f1 -d.
Expand All @@ -82,6 +93,19 @@ else
$(warning $(shell echo "$(YELLOW)$(FIREFOX_NO_SUPPORT_TCO_WARNING)$(NC)"))
endif

# Safari
ifeq ($(UNAME_S),Darwin)
# ignore PATCH because the expression with PATCH(e.g., double dots x.x.x) becomes invalid number for the following bc cmd
SAFARI_VERSION := $(shell $(SAFARI_VERSION_CHECK_CMD))
SAFARI_MAJOR := $(shell echo $(SAFARI_VERSION) | cut -f1 -d.)
SAFARI_MINOR := $(shell echo $(SAFARI_VERSION) | cut -f2 -d.)
ifeq ($(shell echo "$(SAFARI_MAJOR).$(SAFARI_MINOR)>=$(SAFARI_SUPPORT_TCO_AT_MAJOR_MINOR)" | bc), 1)
$(info $(shell echo "$(GREEN)$(SAFARI_SUPPORT_TCO_INFO)$(NC)"))
else
$(warning $(shell echo "$(YELLOW)$(SAFARI_NO_SUPPORT_TCO_WARNING)$(NC)"))
endif
endif

# used to serve wasm locally
DEMO_IP := 127.0.0.1
DEMO_PORT := 8000
Expand Down

0 comments on commit 5b90d0f

Please sign in to comment.