You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: ChangeLog.markdown
+1
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,7 @@ Not all changes are documented here. In particular, new features, user-oriented
9
9
10
10
Current Trunk
11
11
-------------
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.
12
13
- 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)
Copy file name to clipboardExpand all lines: site/source/docs/compiling/Building-Projects.rst
+12-11
Original file line number
Diff line number
Diff line change
@@ -56,15 +56,15 @@ The last step is to compile the linked bitcode into JavaScript. We do this by ca
56
56
Building projects with optimizations
57
57
====================================
58
58
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.
60
60
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).
62
62
63
63
Consider the examples below:
64
64
65
65
.. code-block:: bash
66
66
67
-
# Sub-optimal - JavaScript optimizations are omitted
67
+
# Sub-optimal - JavaScript/WebAssembly optimizations are omitted
68
68
./emcc -O2 a.cpp -o a.bc
69
69
./emcc -O2 b.cpp -o b.bc
70
70
./emcc a.bc b.bc -o project.js
@@ -74,26 +74,27 @@ Consider the examples below:
74
74
./emcc b.cpp -o b.bc
75
75
./emcc -O2 a.bc b.bc -o project.js
76
76
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.
83
78
./emcc -O2 a.cpp -o a.bc
84
79
./emcc -O2 b.cpp -o b.bc
85
80
./emcc -O2 a.bc b.bc -o project.js
86
81
82
+
However, sometimes you may want slightly different optimizations on certain files:
83
+
84
+
.. code-block:: bash
87
85
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
89
90
90
91
.. 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**.
91
92
92
93
- Some build systems have a flag like ``./configure --enable-optimize``.
93
94
- 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.
94
95
95
96
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>`:
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.
0 commit comments