Skip to content

Commit d0d12c7

Browse files
authored
Speed up emcc -v by not running sanity checks. (#13176)
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 to ~200 ms. Add a new options `--check` which will force the running of sanity checks. See: #13004
1 parent 0ec8cda commit d0d12c7

File tree

8 files changed

+48
-30
lines changed

8 files changed

+48
-30
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: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,16 +401,18 @@ 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

411409
"emcc -v" is a useful tool for diagnosing errors. It works with
412410
or without other arguments.
413411

412+
"--check"
413+
Runs Emscripten's internal sanity checks and reports any issues
414+
with the current configuration.
415+
414416
"--cache"
415417
Sets the directory to use as the Emscripten cache. The Emscripten
416418
cache is used to store pre-built versions of "libc", "libcxx" and

emcc.py

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

792792
if run_via_emxx:
@@ -796,10 +796,8 @@ def run(args):
796796

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

804802
if '-dumpmachine' in args:
805803
print(shared.get_llvm_target())
@@ -2348,6 +2346,10 @@ def post_link(options, in_wasm, wasm_target, target):
23482346
return 0
23492347

23502348

2349+
def version_string():
2350+
return 'emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) %s' % shared.EMSCRIPTEN_VERSION
2351+
2352+
23512353
def parse_args(newargs):
23522354
options = EmccOptions()
23532355
settings_changes = []
@@ -2529,7 +2531,6 @@ def consume_arg_file():
25292531
options.ignore_dynamic_linking = True
25302532
elif arg == '-v':
25312533
shared.PRINT_STAGES = True
2532-
shared.check_sanity(force=True)
25332534
elif check_arg('--shell-file'):
25342535
options.shell_path = consume_arg_file()
25352536
elif check_arg('--source-map-base'):
@@ -2553,6 +2554,10 @@ def consume_arg_file():
25532554
shared.Cache.erase()
25542555
shared.check_sanity(force=True) # this is a good time for a sanity check
25552556
should_exit = True
2557+
elif check_flag('--check'):
2558+
print(version_string(), file=sys.stderr)
2559+
shared.check_sanity(force=True)
2560+
should_exit = True
25562561
elif check_flag('--show-ports'):
25572562
system_libs.show_ports()
25582563
should_exit = True

site/source/docs/building_from_source/verify_emscripten_environment.rst

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,24 @@ 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

2424
For example, the following output reports an installation where Java is missing:
2525

2626
.. code-block:: none
27-
:emphasize-lines: 6
27+
:emphasize-lines: 3
2828
29-
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
29+
emcc (Emscripten GCC-like replacement + linker emulating GNU ld) 1.21.0
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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,15 @@ 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

331+
``--check``
332+
Runs Emscripten's internal sanity checks and reports any issues with the
333+
current configuration.
334+
330335
.. _emcc-cache:
331336

332337
``--cache``

tests/test_other.py

Lines changed: 9 additions & 1 deletion
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'
@@ -227,7 +235,7 @@ def test_emcc_basics(self, compiler, suffix):
227235
# --version
228236
output = self.run_process([compiler, '--version'], stdout=PIPE, stderr=PIPE)
229237
output = output.stdout.replace('\r', '')
230-
self.assertContained('emcc (Emscripten gcc/clang-like replacement)', output)
238+
self.assertContained('emcc (Emscripten gcc/clang-like replacement', output)
231239
self.assertContained('''Copyright (C) 2014 the Emscripten authors (see AUTHORS.txt)
232240
This is free and open source software under the MIT license.
233241
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

0 commit comments

Comments
 (0)