Skip to content

Commit

Permalink
Add implicit wasm feature disabling based on min browser versions
Browse files Browse the repository at this point in the history
With https://reviews.llvm.org/D125728 about to land in LLVM we have four
features which will be enabled by default.  In order to allow users to
continue to target older browsers we want to turn these features off by
default when users opt into older browser support.

As part of this change we are bumping the default minimum browser
versions for Safari and Firefox to the minimum version needed to
supported these 4 features which are about to be enabled by default:

- firefix: 65 -> 79
- safari: 12 - 15
  • Loading branch information
sbc100 committed Aug 19, 2022
1 parent 3a32a77 commit f6ee99a
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 3 deletions.
3 changes: 2 additions & 1 deletion emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from tools import wasm2c
from tools import webassembly
from tools import config
from tools import feature_matrix
from tools.settings import settings, MEM_SIZE_SETTINGS, COMPILE_TIME_SETTINGS
from tools.utils import read_file, write_file, read_binary

Expand Down Expand Up @@ -829,7 +830,7 @@ def get_target_flags():


def get_clang_flags(user_args):
flags = get_target_flags()
flags = get_target_flags() + feature_matrix.get_feature_flags()

# if exception catching is disabled, we can prevent that code from being
# generated in the frontend
Expand Down
4 changes: 2 additions & 2 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1732,7 +1732,7 @@ var AUTO_NATIVE_LIBRARIES = true;
// Firefox ESR 60.5 (Firefox 65) was released on 2019-01-29.
// MAX_INT (0x7FFFFFFF, or -1) specifies that target is not supported.
// [link]
var MIN_FIREFOX_VERSION = 65;
var MIN_FIREFOX_VERSION = 79;

// Specifies the oldest version of desktop Safari to target. Version is encoded
// in MMmmVV, e.g. 70101 denotes Safari 7.1.1.
Expand All @@ -1743,7 +1743,7 @@ var MIN_FIREFOX_VERSION = 65;
// see https://github.com/emscripten-core/emscripten/pull/7191.
// MAX_INT (0x7FFFFFFF, or -1) specifies that target is not supported.
// [link]
var MIN_SAFARI_VERSION = 120000;
var MIN_SAFARI_VERSION = 150000;

// Specifies the oldest version of Internet Explorer to target. E.g. pass -s
// MIN_IE_VERSION = 11 to drop support for IE 10 and older.
Expand Down
70 changes: 70 additions & 0 deletions tools/feature_matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import logging
from enum import IntEnum, auto

from .settings import settings

logger = logging.getLogger('feature_matrix')


class Feature(IntEnum):
NON_TRAPPING_FPTOINT = auto()
SIGN_EXT = auto()
BULK_MEMORY = auto()
MUTABLE_GLOBALS = auto()


min_browser_versions = {
Feature.NON_TRAPPING_FPTOINT: {
'chrome': 75,
'firefox': 65,
'safari': 150000,
},
Feature.SIGN_EXT: {
'chrome': 74,
'firefox': 62,
'safari': 141000,
},
Feature.BULK_MEMORY: {
'chrome': 75,
'firefox': 79,
'safari': 150000,
},
Feature.MUTABLE_GLOBALS: {
'chrome': 74,
'firefox': -1, # Firefox has always supported mutable globals apparently
'safari': 120000,
},
}


def caniuse(feature):
min_versions = min_browser_versions[feature]
if settings.MIN_CHROME_VERSION < min_versions['chrome']:
return False
if settings.MIN_FIREFOX_VERSION < min_versions['firefox']:
return False
if settings.MIN_SAFARI_VERSION < min_versions['safari']:
return False
return True


def get_feature_flags():
flags = []

if not caniuse(Feature.NON_TRAPPING_FPTOINT):
logger.debug('adding -mno-nontrapping-fptoint due to target browser selection')
flags.append('-mno-nontrapping-fptoint')

if not caniuse(Feature.SIGN_EXT):
logger.debug('adding -mnosign-ext due to target browser selection')
flags.append('-mno-sign-ext')

if not caniuse(Feature.BULK_MEMORY):
logger.debug('adding -mnobulk-memory due to target browser selection')
flags.append('-mno-bulk-memory')

if not caniuse(Feature.MUTABLE_GLOBALS):
logger.debug('adding -mnomutable-globals due to target browser selection')
flags.append('-mno-mutable-globals')

return flags
5 changes: 5 additions & 0 deletions tools/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@
'WASM_OBJECT_FILES',
'WASM_WORKERS',

# These are needed at compile time to calulate feature flags
'MIN_CHROME_VERSION',
'MIN_FIREFOX_VERSION',
'MIN_SAFARI_VERSION',

# Internal settings used during compilation
'EXCEPTION_CATCHING_ALLOWED',
'WASM_EXCEPTIONS',
Expand Down

0 comments on commit f6ee99a

Please sign in to comment.