Skip to content

Commit 9e63595

Browse files
committed
Speed up emcc -v by not running sanity checks.
Since some build tools run `emcc -v` regularly we want to be fast. This change avoid running sanity checks which means fewer subprocesses. On my machine this takes `emcc -v ` from ~300 ro ~200 ms. Add a new options `--check` which will force the running of sanity checks. See: #13004
1 parent cc8223f commit 9e63595

File tree

8 files changed

+37
-27
lines changed

8 files changed

+37
-27
lines changed

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ Current Trunk
2323

2424
2.0.11: 12/17/2020
2525
------------------
26+
- `emcc -v` no longer forces the running the sanity checks. Sanity checks
27+
are always run on first use or can be forced with `--check` or by setting
28+
`EMCC_DEBUG` is set in the environment.
2629
- An upstream LLVM regression with global initializer linking has been fixed
2730
(#13038).
2831
- Remove a racy unneeded assertion about async dynamic linking (#13060).

docs/emcc.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,8 @@ Options that are modified or new in *emcc* are listed below:
401401
"-v"
402402
Turns on verbose output.
403403

404-
This will pass "-v" to *Clang*, and also enable "EMCC_DEBUG" to
405-
generate intermediate files for the compiler's various stages. It
406-
will also run Emscripten's internal sanity checks on the toolchain,
407-
etc.
404+
This will print the internal sub-commands run by emscripten as well
405+
as "-v" to *Clang*.
408406

409407
Tip:
410408

emcc.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -781,11 +781,11 @@ def run(args):
781781
revision = open(shared.path_from_root('emscripten-revision.txt')).read().strip()
782782
if revision:
783783
revision = ' (%s)' % revision
784-
print('''emcc (Emscripten gcc/clang-like replacement) %s%s
784+
print('''%s%s
785785
Copyright (C) 2014 the Emscripten authors (see AUTHORS.txt)
786786
This is free and open source software under the MIT license.
787787
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
788-
''' % (shared.EMSCRIPTEN_VERSION, revision))
788+
''' % (version_string(), revision))
789789
return 0
790790

791791
if run_via_emxx:
@@ -795,10 +795,8 @@ def run(args):
795795

796796
if len(args) == 1 and args[0] == '-v': # -v with no inputs
797797
# autoconf likes to see 'GNU' in the output to enable shared object support
798-
print('emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) %s' % shared.EMSCRIPTEN_VERSION, file=sys.stderr)
799-
code = shared.check_call([clang, '-v'] + shared.get_clang_flags(), check=False).returncode
800-
shared.check_sanity(force=True)
801-
return code
798+
print(version_string(), file=sys.stderr)
799+
return shared.check_call([clang, '-v'] + shared.get_clang_flags(), check=False).returncode
802800

803801
if '-dumpmachine' in args:
804802
print(shared.get_llvm_target())
@@ -2347,6 +2345,10 @@ def post_link(options, in_wasm, wasm_target, target):
23472345
return 0
23482346

23492347

2348+
def version_string():
2349+
return 'emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) %s' % shared.EMSCRIPTEN_VERSION
2350+
2351+
23502352
def parse_args(newargs):
23512353
options = EmccOptions()
23522354
settings_changes = []
@@ -2528,7 +2530,6 @@ def consume_arg_file():
25282530
options.ignore_dynamic_linking = True
25292531
elif arg == '-v':
25302532
shared.PRINT_STAGES = True
2531-
shared.check_sanity(force=True)
25322533
elif check_arg('--shell-file'):
25332534
options.shell_path = consume_arg_file()
25342535
elif check_arg('--source-map-base'):
@@ -2546,6 +2547,10 @@ def consume_arg_file():
25462547
shared.Cache.erase()
25472548
shared.check_sanity(force=True) # this is a good time for a sanity check
25482549
should_exit = True
2550+
elif check_flag('--check'):
2551+
print(version_string(), file=sys.stderr)
2552+
shared.check_sanity(force=True) # this is a good time for a sanity check
2553+
should_exit = True
25492554
elif check_flag('--clear-ports'):
25502555
logger.info('clearing ports and cache as requested by --clear-ports')
25512556
system_libs.Ports.erase()

site/source/docs/building_from_source/verify_emscripten_environment.rst

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ Testing the environment
1313
Sanity tests
1414
------------
1515

16-
The first step in verifying the environment is to run Emscripten with the version command (``-v``). The command prints out information about the toolchain and runs some basic sanity tests to check that the required tools are available.
16+
The first step in verifying the environment is to run Emscripten with ``--check``. The option prints out information about the toolchain and runs some basic sanity tests to check that the required tools are available.
1717

1818
Open a terminal in the directory in which you installed Emscripten (on Windows open the :ref:`Emscripten Command Prompt <emcmdprompt>`). Then call the :ref:`Emscripten Compiler Frontend (emcc) <emccdoc>` as shown::
1919

20-
./emcc -v
20+
./emcc --check
2121

2222
.. note:: On Windows, invoke the tool with **emcc** instead of **./emcc**.
2323

@@ -27,13 +27,10 @@ For example, the following output reports an installation where Java is missing:
2727
:emphasize-lines: 6
2828
2929
emcc (Emscripten GCC-like replacement + linker emulating GNU ld ) 1.21.0
30-
clang version 3.3
31-
Target: x86_64-pc-win32
32-
Thread model: posix
33-
INFO root: (Emscripten: Running sanity checks)
34-
WARNING root: java does not seem to exist, required for closure compiler. -O2 and above will fail. You need to define JAVA in .emscripten
30+
shared:INFO: (Emscripten: Running sanity checks)
31+
shared:WARNING: java does not seem to exist, required for closure compiler. -O2 and above will fail. You need to define JAVA in .emscripten
3532
36-
At this point you need to :ref:`Install and activate <fixing-missing-components-emcc>` any missing components. When everything is set up properly, ``emcc -v`` should give no warnings, and if you just enter ``emcc`` (without any input files), it will give an error ::
33+
At this point you need to :ref:`Install and activate <fixing-missing-components-emcc>` any missing components. When everything is set up properly, ``emcc ---check`` should give no warnings, and if you just enter ``emcc`` (without any input files), it will give an error ::
3734

3835
emcc: error: no input files
3936

@@ -64,7 +61,7 @@ Emscripten has a comprehensive test suite which may be used to further validate
6461
Troubleshooting
6562
===============
6663

67-
First run ``./emcc -v`` and examine the output to find missing components. You can also try ``./emcc --clear-cache`` to empty the :ref:`compiler's internal cache <emcc-clear-cache>` and reset it to a known good state.
64+
First run ``./emcc --check`` and examine the output to find missing components. You can also try ``./emcc --clear-cache`` to empty the :ref:`compiler's internal cache <emcc-clear-cache>` and reset it to a known good state.
6865

6966

7067
.. _fixing-missing-components-emcc:

site/source/docs/getting_started/FAQ.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Why do I get multiple errors building basic code and the tests?
1717

1818
All the tests in the :ref:`Emscripten test suite <emscripten-test-suite>` are known to build and pass on our test infrastructure, so if you see failures locally it is likely that there is some problem with your environment. (Rarely, there may be temporary breakage, but never on a tagged release version.)
1919

20-
First call ``emcc -v``, which runs basic sanity checks and prints out useful environment information. If that doesn't help, follow the instructions in :ref:`verifying-the-emscripten-environment`.
20+
First call ``emcc --check``, which runs basic sanity checks and prints out useful environment information. If that doesn't help, follow the instructions in :ref:`verifying-the-emscripten-environment`.
2121

2222
You might also want to go through the :ref:`Tutorial` again, as it is updated as Emscripten changes.
2323

site/source/docs/porting/Debugging.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ directory (e.g. **/tmp** on UNIX).
5757

5858
The debug logs can be analysed to profile and review the changes that were made in each step.
5959

60-
.. note:: The debug mode can also be enabled by specifying the :ref:`verbose output <debugging-emcc-v>` compiler flag (``emcc -v``).
60+
.. note:: The more limited amount of debug information can also be enabled by specifying the :ref:`verbose output <debugging-emcc-v>` compiler flag (``emcc -v``).
6161

6262

6363
.. _debugging-compilation-settings:
@@ -121,10 +121,8 @@ Emscripten also supports some of Clang's sanitizers, such as :ref:`sanitizer_ubs
121121
emcc verbose output
122122
===================
123123

124-
Compiling with the :ref:`emcc -v <emcc-verbose>` option passes ``-v`` to LLVM and runs Emscripten's internal sanity checks on the toolchain.
125-
126-
The verbose mode also enables Emscripten's :ref:`debugging-EMCC_DEBUG` to generate intermediate files for the compiler’s various stages.
127-
124+
Compiling with the :ref:`emcc -v <emcc-verbose>` will cause Emscripten to output
125+
the sub-command that it runs as well as passes ``-v`` to Clang.
128126

129127
.. _debugging-manual-debugging:
130128

site/source/docs/tools_reference/emcc.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,8 @@ Options that are modified or new in *emcc* are listed below:
323323
``-v``
324324
Turns on verbose output.
325325

326-
This will pass ``-v`` to *Clang*, and also enable ``EMCC_DEBUG`` to generate intermediate files for the compiler's various stages. It will also run Emscripten's internal sanity checks on the toolchain, etc.
326+
This will print the internal sub-commands run by emscripten as well as ``-v``
327+
to *Clang*.
327328

328329
.. tip:: ``emcc -v`` is a useful tool for diagnosing errors. It works with or without other arguments.
329330

tests/test_other.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@ def test_emcc_v(self):
170170
self.assertContained('Target: wasm32-unknown-emscripten', proc.stderr)
171171
self.assertNotContained('this is dangerous', proc.stderr)
172172

173+
def test_emcc_check(self):
174+
proc = self.run_process([EMCC, '--check'], stdout=PIPE, stderr=PIPE)
175+
self.assertEqual(proc.stdout, '')
176+
self.assertContained('emcc (Emscripten gcc/clang-like replacement', proc.stderr)
177+
self.assertContained('Running sanity checks', proc.stderr)
178+
proc = self.run_process([EMCC, '--check'], stdout=PIPE, stderr=PIPE)
179+
self.assertContained('Running sanity checks', proc.stderr)
180+
173181
def test_emcc_generate_config(self):
174182
for compiler in [EMCC, EMXX]:
175183
config_path = './emscripten_config'

0 commit comments

Comments
 (0)