shithub: puzzles

Download patch

ref: d505f08f671c2f0a3fdd0b7d733e4ce987aa4786
parent: b5f87e6175db229e3e84e054ce23a1194cc535e4
author: Ben Harris <bjh21@bjh21.me.uk>
date: Thu Apr 6 05:58:21 EDT 2023

js: explicitly tell Emscripten which browsers to target

Emscripten has settings indicating which browser versions it should
build code for.  These are now by default slightly newer than I'd been
targeting with my hand-written JavaScript.  They also don't include
Firefox 48, which KaiOS 2.5 is based on.

This commit adds CMake variables to set the minimum versions that we
pass to Emscripten.  They default to the earliest versions with
WebAssembly support, except that Firefox 48 is also supported.

I think the main consequence of this change is to stop Emscripten using
sign-extension and mutable-globals in WebAssembly, which it's done by
default since version 3.1.26.

--- a/cmake/platforms/emscripten.cmake
+++ b/cmake/platforms/emscripten.cmake
@@ -6,6 +6,20 @@
 set(WASM ON
   CACHE BOOL "Compile to WebAssembly rather than plain JavaScript")
 
+# The minimal versions here are the ones that Puzzles' own JavaScript
+# is written for.  For most browsers, that's the earliest version with
+# WebAssembly support according to https://caniuse.com/wasm.  For
+# Firefox we go back to Firefox 48 because that's what KaiOS 2.5 is
+# based on.
+set(MIN_FIREFOX_VERSION 48 CACHE STRING
+  "Oldest major version of Firefox to target")
+set(MIN_SAFARI_VERSION 110000 CACHE STRING
+  "Oldest version of desktop Safari to target (XXYYZZ for version XX.YY.ZZ)")
+set(MIN_EDGE_VERSION 16 CACHE STRING
+  "Oldest version of (non-Chromium-based) Edge to target")
+set(MIN_CHROME_VERSION 57 CACHE STRING
+  "Oldest version of Chrome to target")
+
 find_program(HALIBUT halibut)
 if(NOT HALIBUT)
   message(WARNING "HTML documentation cannot be built (did not find halibut)")
@@ -44,6 +58,11 @@
 -s ENVIRONMENT=web \
 -s EXPORTED_FUNCTIONS='[${emcc_export_string}]' \
 -s EXPORTED_RUNTIME_METHODS='[cwrap]' \
+-s MIN_FIREFOX_VERSION=${MIN_FIREFOX_VERSION} \
+-s MIN_SAFARI_VERSION=${MIN_SAFARI_VERSION} \
+-s MIN_EDGE_VERSION=${MIN_EDGE_VERSION} \
+-s MIN_CHROME_VERSION=${MIN_CHROME_VERSION} \
+-s MIN_NODE_VERSION=0x7FFFFFFF \
 -s STRICT_JS=1")
 if(WASM)
   set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -s WASM=1")