Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions test/test_sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,3 +846,26 @@ def test_bootstrap_without_em_config(self):

# Running bootstrap.py should not fail
self.run_process([utils.exe_path_from_root('bootstrap')], env=env)

# Verify that if user specifies a relative path to Python executable, then
# Emscripten is still able to build.
def test_emcc_with_relative_python_path(self):
restore_and_set_up()
# Clear the cache, since rebuilding the cache has been observed to fail
# if Python path is specified as relative.
self.clear_cache()

try:
relative_python = os.path.relpath(os.environ.get('EMSDK_PYTHON'), os.getcwd())
except ValueError:
self.skipTest('Python and Emscripten are located on different drives, cannot run this test.')

relative_python_escaped = relative_python.replace("\\", "\\\\")
add_to_config(f'PYTHON = "{relative_python_escaped}"')

env = os.environ.copy()
env['EMSDK_PYTHON'] = relative_python

output = self.do([EMCC, test_file('hello_world.c')], env=env)
self.assertNotContained('error', output)
self.assertExists('a.out.js')
15 changes: 15 additions & 0 deletions tools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ def normalize_config_settings():
PORTS = os.path.join(CACHE, 'ports')


def normalize_relative_python_path():
# User may have specified the EMSDK_PYTHON environment variable to point to
# the Python interpreter, e.g.
#
# EMSDK_PYTHON=../../path/to/python emcc test/hello_world.c
#
# As part of its operation, emcc may spawn sub-emcc tasks when building
# libraries to cache. These sub-emcc tasks will run in a different CWD, so
# reinitialize EMSDK_PYTHON here so that sub-tool spawns will use the same
# Python interpreter as the parent.
if os.environ.get('EMSDK_PYTHON'):
os.environ['EMSDK_PYTHON'] = sys.executable

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! That seems much better.

I also think we could probably localize this to run_build_commands in system_libs.py (since that is the only place its really needed.

But if you want to land as-is and can do some followups.



def set_config_from_tool_location(config_key, tool_binary, f):
val = globals()[config_key]
if val is None:
Expand Down Expand Up @@ -168,6 +182,7 @@ def read_config():
set_config_from_tool_location('BINARYEN_ROOT', 'wasm-opt', lambda x: os.path.dirname(os.path.dirname(x)))

normalize_config_settings()
normalize_relative_python_path()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of has the wrong name now.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, yeah, not sure what's a better name here. Though I'll leave it if you want to address further.

@sbc100 sbc100 Apr 28, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah no worries, feel free to land



def generate_config(path):
Expand Down
Loading