Skip to content

Commit 692c0c7

Browse files
authored
Minor doc updates (#6528)
* add a FAQ entry about uglify parsing errors * update changelog * update docs on optimizing code when building projects
1 parent 9a90a23 commit 692c0c7

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

ChangeLog.markdown

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Not all changes are documented here. In particular, new features, user-oriented
99

1010
Current Trunk
1111
-------------
12+
- Remove special-case support for src/struct_info.compiled.json: Make it a normal cached thing like system libraries, not something checked into the source tree.
1213
- Breaking change: Emit WebAssembly by default. Only the default is changed - we of course still support asm.js, and will for a very long time. But changing the default makes sense as the recommended output for most use cases should be WebAssembly, given it has shipped in all major browsers and platforms and is more efficient than asm.js. Build with `-s WASM=0` to disable wasm and use asm.js if you want that (or use `-s LEGACY_VM_SUPPORT=1`, which emits output that can run in older browsers, which includes a bunch of polyfills as well as disables wasm). (#6419)
1314

1415
v1.38.0: 05/09/2018

site/source/docs/compiling/Building-Projects.rst

+12-11
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ The last step is to compile the linked bitcode into JavaScript. We do this by ca
5656
Building projects with optimizations
5757
====================================
5858

59-
Emscripten performs :ref:`compiler optimization <Optimizing-Code>` at two levels: each source file is optimized by LLVM as it is compiled into an object file, and then JavaScript-specific optimizations are applied when converting object files into JavaScript.
59+
Emscripten performs :ref:`compiler optimization <Optimizing-Code>` at two levels: each source file is optimized by LLVM as it is compiled into an object file, and then JavaScript/WebAssembly-specific optimizations are applied when converting object files into the final JavaScript/WebAssembly.
6060

61-
In order to properly optimize code, it is important to use the **same** :ref:`optimization flags <emcc-compiler-optimization-options>` and other :ref:`compiler options <emcc-s-option-value>` when compiling source to object code, and object code to JavaScript (or HTML).
61+
In order to properly optimize code, it is usually best to use the **same** :ref:`optimization flags <emcc-compiler-optimization-options>` and other :ref:`compiler options <emcc-s-option-value>` when compiling source to object code, and object code to JavaScript (or HTML).
6262

6363
Consider the examples below:
6464

6565
.. code-block:: bash
6666
67-
# Sub-optimal - JavaScript optimizations are omitted
67+
# Sub-optimal - JavaScript/WebAssembly optimizations are omitted
6868
./emcc -O2 a.cpp -o a.bc
6969
./emcc -O2 b.cpp -o b.bc
7070
./emcc a.bc b.bc -o project.js
@@ -74,26 +74,27 @@ Consider the examples below:
7474
./emcc b.cpp -o b.bc
7575
./emcc -O2 a.bc b.bc -o project.js
7676
77-
# Broken! Different JavaScript and LLVM optimisations used.
78-
./emcc -O1 a.cpp -o a.bc
79-
./emcc -O2 b.cpp -o b.bc
80-
./emcc -O3 a.bc b.bc -o project.js
81-
82-
# Correct. The SAME LLVM and JavaScript options are provided at both levels.
77+
# Usually the right thing: The SAME LLVM and JavaScript options are provided at both levels.
8378
./emcc -O2 a.cpp -o a.bc
8479
./emcc -O2 b.cpp -o b.bc
8580
./emcc -O2 a.bc b.bc -o project.js
8681
82+
However, sometimes you may want slightly different optimizations on certain files:
83+
84+
.. code-block:: bash
8785
88-
The same rule applies when :ref:`building Emscripten using a build system <building-projects-build-system>` — both LLVM and JavaScript must be optimized using the same settings.
86+
# Optimize the first file for size, and the rest using `-O2`.
87+
./emcc -Oz a.cpp -o a.bc
88+
./emcc -O2 b.cpp -o b.bc
89+
./emcc -O2 a.bc b.bc -o project.js
8990
9091
.. note:: Unfortunately each build-system defines its own mechanisms for setting compiler and optimization methods. **You will need to work out the correct approach to set the LLVM optimization flags for your system**.
9192

9293
- Some build systems have a flag like ``./configure --enable-optimize``.
9394
- You can control whether LLVM optimizations are run using ``--llvm-opts N`` where N is an integer in the range 0-3. Sending ``-O2 --llvm-opts 0`` to *emcc* during all compilation stages will disable LLVM optimizations but utilize JavaScript optimizations. This can be useful when debugging a build failure.
9495

9596

96-
JavaScript optimizations are specified in the final step, when you compile the linked LLVM bitcode to JavaScript. For example, to compile with :ref:`-O1 <emcc-O1>`:
97+
JavaScript/WebAssembly optimizations are specified in the final step (sometimes called "link", as that step typically also links together a bunch of files that are all compiled together into one JavaScript/WebAssembly output). For example, to compile with :ref:`-O1 <emcc-O1>`:
9798

9899
.. code-block:: bash
99100

site/source/docs/getting_started/FAQ.rst

+12
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,18 @@ A possible cause is that building *libcxx* or *libcxxabi* failed. Go to **system
420420
Another possible cause of this error is the lack of ``make``, which is necessary to build these libraries. If you are on Windows, you need *cmake*.
421421

422422

423+
Why do I get an error mentioning Uglify and ``throw new JS_Parse_Error``?
424+
=========================================================================
425+
426+
In ``-O2`` and above, emscripten will optimize the JS using Uglify1. If you added any JS (using ``--pre-js``/``--post-js``/``EM_ASM``/``EM_JS``) and it contains JS that Uglify1 can't parse - like recent ES6 features - then it will throw such a parsing error.
427+
428+
In the long term we hope to upgrade our internal JS parser. Meanwhile, you can move such code to another script tag on the page, that is, not pass it through the emscripten optimizer.
429+
430+
See also
431+
432+
* https://github.com/kripken/emscripten/issues/6000
433+
* https://github.com/kripken/emscripten/issues/5700
434+
423435
Why does running LLVM bitcode generated by emcc through **lli** break with errors about ``impure_ptr``?
424436
=======================================================================================================
425437

0 commit comments

Comments
 (0)