Skip to content

Commit 9d8c596

Browse files
authored
Improve async compilation error message + docs (#6873)
* When async compilation fails, we try sync compilation as a fallback, but the error message just mentioned sync. Update it to mention both, as likely the user would want to fix async compilation, and not care about the tricks needed for sync compilation. * Update the tutorial text: now that we emit wasm by default, emitting an html file requires loading of a wasm in an xhr, and so a webserver is needed for browsers that don't support file:// loading, which it seems is all browsers but firefox these days.
1 parent 01897f8 commit 9d8c596

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

site/source/docs/getting_started/Tutorial.rst

+6-4
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ Emscripten can also generate HTML for testing embedded JavaScript. To generate H
7474

7575
./emcc tests/hello_world.c -o hello.html
7676

77-
Open the web page in a web browser. As you can see, the framework defines a text area for displaying the output of the ``printf()`` calls in the native code.
77+
You can now open ``hello.html`` in a web browser.
78+
79+
.. note:: Unfortunately several browsers (including *Chrome*, *Safari*, and *Internet Explorer*) do not support ``file://`` :term:`XHR` requests, and can't load extra files needed by the HTML (like a ``.wasm`` file, or packaged file data as mentioned lower down). For these browsers you'll need to serve the files using a webserver. The easiest way to do this is to use the python **SimpleHTTPServer** (in the current directory do ``python -m SimpleHTTPServer 8080`` and then open ``http://localhost:8080/hello.html``).
80+
81+
Once you have the HTML loaded in your browser, you'll see a text area for displaying the output of the ``printf()`` calls in the native code.
7882

7983
The HTML output isn't limited just to just displaying text. You can also use the SDL API to show a colored cube in a ``<canvas>`` element (on browsers that support it). For an example, build the `hello_world_sdl.cpp <https://github.com/kripken/emscripten/blob/master/tests/hello_world_sdl.cpp>`_ test code and then refresh the browser: ::
8084

@@ -119,9 +123,7 @@ The following command is used to specify a data file to :ref:`preload <emcc-prel
119123
./emcc tests/hello_world_file.cpp -o hello.html --preload-file tests/hello_world_file.txt
120124
121125

122-
Run the above command, then open **hello.html** in the *Firefox web browser* to see the data from **hello_world_file.txt** being displayed.
123-
124-
.. note:: Unfortunately *Chrome* and *Internet Explorer* do not support ``file://`` :term:`XHR` requests, and can't directly load the local file in which preloaded data is stored. For these browsers you'll need to serve the files using a webserver. The easiest way to do this is to use the python **SimpleHTTPServer** (in the current directory do ``python -m SimpleHTTPServer 8080`` and then open ``http://localhost:8080/hello.html``).
126+
Run the above command, then open **hello.html** in a web browser to see the data from **hello_world_file.txt** being displayed.
125127

126128
For more information about working with the file system see the :ref:`file-system-overview`, :ref:`Filesystem-API` and :ref:`Synchronous-virtual-XHR-backed-file-system-usage`.
127129

src/preamble.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -2117,7 +2117,11 @@ function integrateWasmJS() {
21172117
if (Module['readBinary']) {
21182118
return Module['readBinary'](wasmBinaryFile);
21192119
} else {
2120-
throw "on the web, we need the wasm binary to be preloaded and set on Module['wasmBinary']. emcc.py will do that for you when generating HTML (but not JS)";
2120+
#if BINARYEN_ASYNC_COMPILATION
2121+
throw "both async and sync fetching of the wasm failed";
2122+
#else
2123+
throw "sync fetching of the wasm failed: you can preload it to Module['wasmBinary'] manually, or emcc.py will do that for you when generating HTML (but not JS)";
2124+
#endif
21212125
}
21222126
}
21232127
catch (err) {

0 commit comments

Comments
 (0)