From ea458fb94aaa0b593a594806ea1491d73a80f882 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 16 Dec 2022 08:54:26 -0800 Subject: [PATCH 1/2] Get node binary via @nodejs//:node I had a colleague using an arm64 mac whose builds were failing because `platform.machine()` was returning amd64 for some reason (my guess is the python toolchain was running under Rosetta). Then emscripten_config looked for the node binary in a nonexistent directory -- nodejs_darwin_amd64 rather than nodejs_darwin_arm64. This switches to a public rules_nodejs API for obtaining the binary, so should always work. --- bazel/emscripten_toolchain/BUILD.bazel | 1 + bazel/emscripten_toolchain/emscripten_config | 10 ++-------- bazel/emscripten_toolchain/toolchain.bzl | 5 +++++ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bazel/emscripten_toolchain/BUILD.bazel b/bazel/emscripten_toolchain/BUILD.bazel index 4486220b56..e23a28b3b2 100644 --- a/bazel/emscripten_toolchain/BUILD.bazel +++ b/bazel/emscripten_toolchain/BUILD.bazel @@ -62,6 +62,7 @@ emscripten_cc_toolchain_config_rule( "@bazel_tools//src/conditions:host_windows": "bat", "//conditions:default": "sh", }), + node_binary = "@nodejs//:node", ) cc_toolchain( diff --git a/bazel/emscripten_toolchain/emscripten_config b/bazel/emscripten_toolchain/emscripten_config index 85a98e34b0..013714bf45 100644 --- a/bazel/emscripten_toolchain/emscripten_config +++ b/bazel/emscripten_toolchain/emscripten_config @@ -6,18 +6,12 @@ EMSCRIPTEN_ROOT = os.environ["EMSCRIPTEN"] BINARYEN_ROOT = os.path.join(ROOT_DIR, os.environ["EM_BIN_PATH"]) LLVM_ROOT = os.path.join(BINARYEN_ROOT, "bin") FROZEN_CACHE = True - -system = platform.system() - -machine = "arm64" if platform.machine() == "arm64" else "amd64" -nodejs_binary = "bin/nodejs/node.exe" if(system =="Windows") else "bin/node" -NODE_JS = ROOT_DIR + "/external/nodejs_{}_{}/{}".format(system.lower(), machine, nodejs_binary) - +NODE_JS = os.path.join(ROOT_DIR, os.environ["NODE_JS"]) # This works around an issue with Bazel RBE where the symlinks in node_modules/.bin # are uploaded as the linked files, which means the cli.js cannot load its # dependencies from the expected locations. # See https://github.com/emscripten-core/emscripten/pull/16640 for more -if system != "Windows": +if platform.system() != "Windows": CLOSURE_COMPILER = [NODE_JS, os.path.join(EMSCRIPTEN_ROOT, "node_modules", "google-closure-compiler", "cli.js")] diff --git a/bazel/emscripten_toolchain/toolchain.bzl b/bazel/emscripten_toolchain/toolchain.bzl index 2bddd56ccf..452871abcf 100644 --- a/bazel/emscripten_toolchain/toolchain.bzl +++ b/bazel/emscripten_toolchain/toolchain.bzl @@ -1040,6 +1040,10 @@ def _impl(ctx): key = "EM_CONFIG_PATH", value = ctx.file.em_config.path, ), + env_entry( + key = "NODE_JS", + value = ctx.file.node_binary.path, + ) ], ), # Use llvm backend. Off by default, enabled via --features=llvm_backend @@ -1115,6 +1119,7 @@ emscripten_cc_toolchain_config_rule = rule( "em_config": attr.label(mandatory = True, allow_single_file = True), "emscripten_binaries": attr.label(mandatory = True, cfg = "exec"), "script_extension": attr.string(mandatory = True, values = ["sh", "bat"]), + "node_binary": attr.label(mandatory = True, allow_single_file = True, cfg = "exec"), }, provides = [CcToolchainConfigInfo], ) From ba2e7fa964cb32be9a50ce7c72ac728c9ca12db2 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 19 Dec 2022 18:29:17 -0800 Subject: [PATCH 2/2] Speculative fix for Windows CI --- .circleci/config.yml | 1 + bazel/emscripten_toolchain/BUILD.bazel | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a5d7e20155..d8f0e7a5ca 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -211,6 +211,7 @@ jobs: environment: PYTHONUNBUFFERED: "1" EMSDK_NOTTY: "1" + USE_BAZEL_VERSION: "5.4.0" steps: - checkout - run: diff --git a/bazel/emscripten_toolchain/BUILD.bazel b/bazel/emscripten_toolchain/BUILD.bazel index e23a28b3b2..d32f116308 100644 --- a/bazel/emscripten_toolchain/BUILD.bazel +++ b/bazel/emscripten_toolchain/BUILD.bazel @@ -62,7 +62,10 @@ emscripten_cc_toolchain_config_rule( "@bazel_tools//src/conditions:host_windows": "bat", "//conditions:default": "sh", }), - node_binary = "@nodejs//:node", + node_binary = select({ + "@bazel_tools//src/conditions:host_windows": "@nodejs//:node_bin", + "//conditions:default": "@nodejs//:node", + }), ) cc_toolchain(