Skip to content

Commit 0c52621

Browse files
authored
NODE_CODE_CACHING followups (#11077)
Note that this is broken on newer node, and mention where it works. see nodejs/node#18265 Show a proper error in SINGLE_FILE mode, where this can't work. Add a missing initialization so we always work properly. Better error logging.
1 parent 1fa8848 commit 0c52621

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

emcc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,6 +1958,8 @@ def check_human_readable_list(items):
19581958
exit_with_error('NODE_CODE_CACHING requires sync compilation (WASM_ASYNC_COMPILATION=0)')
19591959
if not shared.Settings.target_environment_may_be('node'):
19601960
exit_with_error('NODE_CODE_CACHING only works in node, but target environments do not include it')
1961+
if shared.Settings.SINGLE_FILE:
1962+
exit_with_error('NODE_CODE_CACHING saves a file on the side and is not compatible with SINGLE_FILE')
19611963

19621964
# safe heap in asm.js uses the js optimizer (in wasm-only mode we can use binaryen)
19631965
if shared.Settings.SAFE_HEAP and not shared.Building.is_wasm_only():

src/preamble.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,7 @@ function createWasm() {
10691069
// to load ok, but we do actually recompile the binary every time).
10701070
var cachedCodeFile = '{{{ WASM_BINARY_FILE }}}.' + v8.cachedDataVersionTag() + '.cached';
10711071
cachedCodeFile = locateFile(cachedCodeFile);
1072+
if (!nodeFS) nodeFS = require('fs');
10721073
var hasCached = nodeFS.existsSync(cachedCodeFile);
10731074
if (hasCached) {
10741075
#if RUNTIME_LOGGING
@@ -1077,7 +1078,7 @@ function createWasm() {
10771078
try {
10781079
module = v8.deserialize(nodeFS.readFileSync(cachedCodeFile));
10791080
} catch (e) {
1080-
err('NODE_CODE_CACHING: failed to deserialize, bad cache file?');
1081+
err('NODE_CODE_CACHING: failed to deserialize, bad cache file? (' + cachedCodeFile + ')');
10811082
// Save the new compiled code when we have it.
10821083
hasCached = false;
10831084
}

src/settings.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -836,10 +836,9 @@ var NODERAWFS = 0;
836836
// The V8 version used in node is included in the cache name so that we don't
837837
// try to load cached code from another version, which fails silently (it seems
838838
// to load ok, but we do actually recompile).
839-
// * This requires a somewhat recent node, but unclear what version, see
840-
// https://github.com/nodejs/node/issues/18265#issuecomment-471237531
841-
// * This option requires WASM_ASYNC_COMPILATION=0 (we load and save code
842-
// in the sync compilation path for simplicity).
839+
// * The only version known to work for sure is node 12.9.1, as this has
840+
// regressed, see
841+
// https://github.com/nodejs/node/issues/18265#issuecomment-622971547
843842
// * The default location of the .cached files is alongside the wasm binary,
844843
// as mentioned earlier. If that is in a read-only directory, you may need
845844
// to place them elsewhere. You can use the locateFile() hook to do so.

0 commit comments

Comments
 (0)