Skip to content

Commit ed92a0b

Browse files
authored
Add emstrip wrapper around llvm-strip (emscripten-core#16431)
Fixes: emscripten-core#16430
1 parent b25abd5 commit ed92a0b

File tree

5 files changed

+107
-0
lines changed

5 files changed

+107
-0
lines changed

emstrip

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh
2+
# Copyright 2020 The Emscripten Authors. All rights reserved.
3+
# Emscripten is available under two separate licenses, the MIT license and the
4+
# University of Illinois/NCSA Open Source License. Both these licenses can be
5+
# found in the LICENSE file.
6+
#
7+
# Entry point for running python scripts on UNIX systems.
8+
#
9+
# Automatically generated by `create_entry_points.py`; DO NOT EDIT.
10+
#
11+
# To make modifications to this file, edit `tools/run_python.sh` and then run
12+
# `tools/create_entry_points.py`
13+
14+
if [ -z "$PYTHON" ]; then
15+
PYTHON=$EMSDK_PYTHON
16+
fi
17+
18+
if [ -z "$PYTHON" ]; then
19+
PYTHON=$(command -v python3 2> /dev/null)
20+
fi
21+
22+
if [ -z "$PYTHON" ]; then
23+
PYTHON=$(command -v python 2> /dev/null)
24+
fi
25+
26+
if [ -z "$PYTHON" ]; then
27+
echo 'unable to find python in $PATH'
28+
exit 1
29+
fi
30+
31+
exec "$PYTHON" "$0.py" "$@"

emstrip.bat

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
:: Entry point for running python scripts on windows systems.
2+
::
3+
:: Automatically generated by `create_entry_points.py`; DO NOT EDIT.
4+
::
5+
:: To make modifications to this file, edit `tools/run_python.bat` and then run
6+
:: `tools/create_entry_points.py`
7+
8+
:: All env. vars specified in this file are to be local only to this script.
9+
@setlocal
10+
11+
@set EM_PY=%EMSDK_PYTHON%
12+
@if "%EM_PY%"=="" (
13+
set EM_PY=python
14+
)
15+
16+
:: Python Windows bug https://bugs.python.org/issue34780: If this script was invoked via a
17+
:: shared stdin handle from the parent process, and that parent process stdin handle is in
18+
:: a certain state, running python.exe might hang here. To work around this, if
19+
:: EM_WORKAROUND_PYTHON_BUG_34780 is defined, invoke python with '< NUL' stdin to avoid
20+
:: sharing the parent's stdin handle to it, avoiding the hang.
21+
22+
:: On Windows 7, the compiler batch scripts are observed to exit with a non-zero errorlevel,
23+
:: even when the python executable above did succeed and quit with errorlevel 0 above.
24+
:: On Windows 8 and newer, this issue has not been observed. It is possible that this
25+
:: issue is related to the above python bug, but this has not been conclusively confirmed,
26+
:: so using a separate env. var EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG to enable the known
27+
:: workaround this issue, which is to explicitly quit the calling process with the previous
28+
:: errorlevel from the above command.
29+
30+
:: Also must use goto to jump to the command dispatch, since we cannot invoke emcc from
31+
:: inside a if() block, because if a cmdline param would contain a char '(' or ')', that
32+
:: would throw off the parsing of the cmdline arg.
33+
@if "%EM_WORKAROUND_PYTHON_BUG_34780%"=="" (
34+
@if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" (
35+
goto NORMAL
36+
) else (
37+
goto NORMAL_EXIT
38+
)
39+
) else (
40+
@if "%EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG%"=="" (
41+
goto MUTE_STDIN
42+
) else (
43+
goto MUTE_STDIN_EXIT
44+
)
45+
)
46+
47+
:NORMAL_EXIT
48+
@"%EM_PY%" "%~dp0\%~n0.py" %*
49+
@exit %ERRORLEVEL%
50+
51+
:MUTE_STDIN
52+
@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL
53+
@exit /b %ERRORLEVEL%
54+
55+
:MUTE_STDIN_EXIT
56+
@"%EM_PY%" "%~dp0\%~n0.py" %* < NUL
57+
@exit %ERRORLEVEL%
58+
59+
:NORMAL
60+
@"%EM_PY%" "%~dp0\%~n0.py" %*

emstrip.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env python3
2+
# Copyright 2022 The Emscripten Authors. All rights reserved.
3+
# Emscripten is available under two separate licenses, the MIT license and the
4+
# University of Illinois/NCSA Open Source License. Both these licenses can be
5+
# found in the LICENSE file.
6+
7+
"""Wrapper script around `llvm-strip`.
8+
"""
9+
10+
import sys
11+
from tools import shared
12+
13+
cmd = [shared.LLVM_STRIP] + sys.argv[1:]
14+
sys.exit(shared.run_process(cmd, stdin=sys.stdin, check=False).returncode)

tools/create_entry_points.py

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
emprofile
3838
emdwp
3939
emnm
40+
emstrip
4041
tools/file_packager
4142
tools/webidl_binder
4243
tests/runner

tools/shared.py

+1
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ def get_llvm_target():
702702
LLVM_COMPILER = os.path.expanduser(build_llvm_tool_path(exe_suffix('llc')))
703703
LLVM_DWARFDUMP = os.path.expanduser(build_llvm_tool_path(exe_suffix('llvm-dwarfdump')))
704704
LLVM_OBJCOPY = os.path.expanduser(build_llvm_tool_path(exe_suffix('llvm-objcopy')))
705+
LLVM_STRIP = os.path.expanduser(build_llvm_tool_path(exe_suffix('llvm-strip')))
705706
WASM_LD = os.path.expanduser(build_llvm_tool_path(exe_suffix('wasm-ld')))
706707

707708
EMCC = bat_suffix(path_from_root('emcc'))

0 commit comments

Comments
 (0)