Skip to content

Commit 3d87d5e

Browse files
authored
Avoid exporting EM_CONFIG for modern SDK versions (#1110)
Newer versions of emscipten, starting all the way back in 1.39.13, can automatically locate the `.emscripten` config file that emsdk creates so there is no need for the explicit EM_CONFIG environment variable. Its redundant and adds unnessary noisce/complexity. Really, adding emcc to the PATH is all the is needed these days. One nice thing about this change is that it allows folks to run whichever emcc they want to and have it just work, even if they have configured emsdk. Without this change, if I activate emsdk and I run `some/other/emcc` then emsdk's `EM_CONFIG` will still be present and override the configuration embedded in `some/other/emcc`. e.g. in the same shell, with emsdk activated, I can run both these commands and have them both just work as expected. ``` $ emcc --version $ /path/to/my/emcc --version ```
1 parent b4fd475 commit 3d87d5e

File tree

5 files changed

+8
-15
lines changed

5 files changed

+8
-15
lines changed

docker/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ COPY --from=stage_build /emsdk /emsdk
6464
# This will let use tools offered by this image inside other Docker images
6565
# (sub-stages) or with custom / no entrypoint
6666
ENV EMSDK=/emsdk \
67-
EM_CONFIG=/emsdk/.emscripten \
6867
EMSDK_NODE=/emsdk/node/14.18.2_64bit/bin/node \
6968
PATH="/emsdk:/emsdk/upstream/emscripten:/emsdk/upstream/bin:/emsdk/node/14.18.2_64bit/bin:${PATH}"
7069

emsdk.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2676,7 +2676,6 @@ def get_env_vars_to_add(tools_to_activate, system, user):
26762676

26772677
# A core variable EMSDK points to the root of Emscripten SDK directory.
26782678
env_vars_to_add += [('EMSDK', to_unix_path(emsdk_path()))]
2679-
env_vars_to_add += [('EM_CONFIG', os.path.normpath(dot_emscripten_path()))]
26802679

26812680
for tool in tools_to_activate:
26822681
config = tool.activated_config()
@@ -2692,6 +2691,9 @@ def get_env_vars_to_add(tools_to_activate, system, user):
26922691
# https://github.com/emscripten-core/emscripten/pull/11091
26932692
# - Default to embedded cache also started in 1.39.16
26942693
# https://github.com/emscripten-core/emscripten/pull/11126
2694+
# - Emscripten supports automatically locating the embedded
2695+
# config in 1.39.13:
2696+
# https://github.com/emscripten-core/emscripten/pull/10935
26952697
#
26962698
# Since setting EM_CACHE in the environment effects the entire machine
26972699
# we want to avoid this except when installing these older emscripten
@@ -2700,6 +2702,8 @@ def get_env_vars_to_add(tools_to_activate, system, user):
27002702
if version < [1, 39, 16]:
27012703
em_cache_dir = os.path.join(config['EMSCRIPTEN_ROOT'], 'cache')
27022704
env_vars_to_add += [('EM_CACHE', em_cache_dir)]
2705+
if version < [1, 39, 13]:
2706+
env_vars_to_add += [('EM_CONFIG', os.path.normpath(dot_emscripten_path()))]
27032707

27042708
envs = tool.activated_environment()
27052709
for env in envs:
@@ -2764,7 +2768,7 @@ def construct_env_with_vars(env_vars_to_add):
27642768
'EMSDK_NUM_CORES', 'EMSDK_NOTTY', 'EMSDK_KEEP_DOWNLOADS'])
27652769
env_keys_to_add = set(pair[0] for pair in env_vars_to_add)
27662770
for key in os.environ:
2767-
if key.startswith('EMSDK_') or key.startswith('EM_CACHE'):
2771+
if key.startswith('EMSDK_') or key in ('EM_CACHE', 'EM_CONFIG'):
27682772
if key not in env_keys_to_add and key not in ignore_keys:
27692773
info('Clearing existing environment variable: %s' % key)
27702774
env_string += unset_env(key)

test/test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
WINDOWS = sys.platform.startswith('win')
1111
MACOS = sys.platform == 'darwin'
1212

13-
assert 'EM_CONFIG' in os.environ, "emsdk should be activated before running this script"
13+
emconfig = os.path.abspath('.emscripten')
14+
assert os.path.exists(emconfig)
1415

15-
emconfig = os.environ['EM_CONFIG']
1616
upstream_emcc = os.path.join('upstream', 'emscripten', 'emcc')
1717
fastcomp_emcc = os.path.join('fastcomp', 'emscripten', 'emcc')
1818
emsdk = './emsdk'

test/test_activation.ps1

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ try {
2828
}
2929

3030
$EMSDK = [System.Environment]::GetEnvironmentVariable("EMSDK", $env_type)
31-
$EM_CONFIG = [System.Environment]::GetEnvironmentVariable("EM_CONFIG", $env_type)
3231
$EMSDK_NODE = [System.Environment]::GetEnvironmentVariable("EMSDK_NODE", $env_type)
3332
$EMSDK_PYTHON = [System.Environment]::GetEnvironmentVariable("EMSDK_PYTHON", $env_type)
3433
$JAVA_HOME = [System.Environment]::GetEnvironmentVariable("JAVA_HOME", $env_type)
@@ -37,9 +36,6 @@ try {
3736
if (!$EMSDK) {
3837
throw "EMSDK is not set for the user"
3938
}
40-
if (!$EM_CONFIG) {
41-
throw "EM_CONFIG is not set for the user"
42-
}
4339
if (!$EMSDK_NODE) {
4440
throw "EMSDK_NODE is not set for the user"
4541
}
@@ -83,22 +79,19 @@ finally {
8379

8480
# Recover pre activation env variables
8581
[Environment]::SetEnvironmentVariable("EMSDK", $null, "User")
86-
[Environment]::SetEnvironmentVariable("EM_CONFIG", $null, "User")
8782
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "User")
8883
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "User")
8984
[Environment]::SetEnvironmentVariable("JAVA_HOME", $null, "User")
9085

9186
try {
9287
[Environment]::SetEnvironmentVariable("EMSDK", $null, "Machine")
93-
[Environment]::SetEnvironmentVariable("EM_CONFIG", $null, "Machine")
9488
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "Machine")
9589
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "Machine")
9690
[Environment]::SetEnvironmentVariable("JAVA_HOME", $null, "Machine")
9791
} catch {}
9892

9993

10094
[Environment]::SetEnvironmentVariable("EMSDK", $null, "Process")
101-
[Environment]::SetEnvironmentVariable("EM_CONFIG", $null, "Process")
10295
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "Process")
10396
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "Process")
10497
[Environment]::SetEnvironmentVariable("JAVA_HOME", $null, "Process")

test/test_path_preservation.ps1

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,19 @@ finally {
123123

124124
# Recover pre activation env variables
125125
[Environment]::SetEnvironmentVariable("EMSDK", $null, "User")
126-
[Environment]::SetEnvironmentVariable("EM_CONFIG", $null, "User")
127126
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "User")
128127
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "User")
129128
[Environment]::SetEnvironmentVariable("JAVA_HOME", $null, "User")
130129

131130
try {
132131
[Environment]::SetEnvironmentVariable("EMSDK", $null, "Machine")
133-
[Environment]::SetEnvironmentVariable("EM_CONFIG", $null, "Machine")
134132
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "Machine")
135133
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "Machine")
136134
[Environment]::SetEnvironmentVariable("JAVA_HOME", $null, "Machine")
137135
} catch {}
138136

139137

140138
[Environment]::SetEnvironmentVariable("EMSDK", $null, "Process")
141-
[Environment]::SetEnvironmentVariable("EM_CONFIG", $null, "Process")
142139
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "Process")
143140
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "Process")
144141
[Environment]::SetEnvironmentVariable("JAVA_HOME", $null, "Process")

0 commit comments

Comments
 (0)