Skip to content

Closure compiler fails with ENVIRONMENT="web,worker" and USE_PTHREADS=1 #10502

Closed

Description

@Faless

Tested with latest upstream emsdk version (1.39.8):

Try to compile the pthread test in test/core/pthread.cpp with options:

  • EMCC_DEBUG=1 emcc -g1 -s USE_PTHREADS=1 --closure 1 -O1 create.cpp
    success.

  • EMCC_DEBUG=1 emcc -g1 -s USE_PTHREADS=1 --closure 1 -s ENVIRONMENT="web,worker" -O1 create.cpp
    failure:

shared:ERROR: /tmp/emscripten_temp/a.out.wasm.o.js:71: WARNING - [JSC_REFERENCE_BEFORE_DECLARE] Variable referenced before declaration: buffer
  buffer = Module['buffer'];
  ^^^^^^

/tmp/emscripten_temp/a.out.wasm.o.js:72: WARNING - [JSC_REFERENCE_BEFORE_DECLARE] Variable referenced before declaration: DYNAMIC_BASE
  DYNAMIC_BASE = Module['DYNAMIC_BASE'];
  ^^^^^^^^^^^^

/tmp/emscripten_temp/a.out.wasm.o.js:73: WARNING - [JSC_REFERENCE_BEFORE_DECLARE] Variable referenced before declaration: DYNAMICTOP_PTR
  DYNAMICTOP_PTR = Module['DYNAMICTOP_PTR'];
  ^^^^^^^^^^^^^^

/tmp/emscripten_temp/a.out.wasm.o.js:88: ERROR - [JSC_UNDEFINED_VARIABLE] variable __filename is undeclared
  _scriptDir = __filename;
               ^^^^^^^^^^

/tmp/emscripten_temp/a.out.wasm.o.js:133: ERROR - [JSC_UNDEFINED_VARIABLE] variable nodeFS is undeclared
    if (!nodeFS) nodeFS = require('fs');
         ^^^^^^

/tmp/emscripten_temp/a.out.wasm.o.js:133: ERROR - [JSC_UNDEFINED_VARIABLE] variable require is undeclared
    if (!nodeFS) nodeFS = require('fs');
                          ^^^^^^^

/tmp/emscripten_temp/a.out.wasm.o.js:134: ERROR - [JSC_UNDEFINED_VARIABLE] variable nodePath is undeclared
    if (!nodePath) nodePath = require('path');
         ^^^^^^^^

4 error(s), 3 warning(s)

shared:ERROR: closure compiler failed (rc: 4.)

I tried digging the source a bit without much luck, so for now I'm just reporting it, maybe it's an easy fix for someone who knows the internals better.

Activity

  1. added a commit that references this issue on Feb 21, 2020
    0470930
  2. kripken commented on Feb 21, 2020

    @kripken
    Member

    Thanks @Faless ! We were missing some ifdefs. Fix in #10521

  3. shahine44 commented on Mar 4, 2025

    @shahine44

    var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB &&
    !ENVIRONMENT_IS_WORKER &&
    !ENVIRONMENT_IS_NODE;

        if (ENVIRONMENT_IS_NODE) {
          var fs = require("fs");
          var path = require("path");
    
          Module["read"] = function shell_read(filename, binary) {
            var ret;
            try {
              ret = fs.readFileSync(filename, binary ? null : "utf8");
              if (!binary && ret.startsWith("\uFEFF")) {
                ret = ret.substr(1);
              }
            } catch (e) {
              throw new Error("Failed to read file: " + filename);
            }
            return ret;
          };
    
          Module["readBinary"] = function readBinary(filename) {
            return Module["read"](filename, true);
          };
    
          Module["load"] = function load(f) {
            eval(Module["read"](f));
          };
        }
    
        Module["ready"] = readyPromise;
        readyPromiseResolve(Module);
        return Module;
      };
    })();
    
    module.exports = Module;
    

    }
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions