Skip to content

Commit e6b94bc

Browse files
committed
Drop support for secondary caches on Windows
1 parent 311c587 commit e6b94bc

File tree

2 files changed

+34
-31
lines changed

2 files changed

+34
-31
lines changed

bazel/emscripten_cache.bzl

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,21 @@ package(default_visibility = ['//visibility:public'])
33
exports_files(['emscripten_config'])
44
"""
55

6-
def get_root_and_binext(repository_ctx):
7-
"""
8-
Retrieve the path to the Emscripten binary directory
6+
EMBUILDER_FILE_CONTENT_TEMPLATE = """
7+
CACHE = '{cache}'
8+
EMSCRIPTEN_ROOT = '{emscripten_root}'
9+
BINARYEN_ROOT = '{binaryen_root}'
10+
LLVM_ROOT = '{llvm_root}'
911
10-
This function determines the correct Emscripten binary directory path by
11-
examining the operating system and architecture of the environment. It
12-
supports Linux, macOS, and Windows operating systems with specific
13-
architectures.
12+
import platform
1413
15-
Args:
16-
repository_ctx: The repository context object which provides information
17-
about the OS and architecture, and methods to obtain paths and labels.
18-
19-
Returns:
20-
str: The directory path to the Emscripten binaries for the detected OS
21-
and architecture.
14+
system = platform.system()
15+
machine = "arm64" if platform.machine() in ('arm64', 'aarch64') else "amd64"
16+
nodejs_binary = "bin/nodejs/node.exe" if(system =="Windows") else "bin/node"
17+
NODE_JS = '{external_root}/nodejs_{{}}_{{}}/{{}}'.format(system.lower(), machine, nodejs_binary)
18+
"""
2219

23-
"""
20+
def get_root_and_script_ext(repository_ctx):
2421
if repository_ctx.os.name.startswith('linux'):
2522
if 'amd64' in repository_ctx.os.arch or 'x86_64' in repository_ctx.os.arch:
2623
return (repository_ctx.path(Label("@emscripten_bin_linux//:BUILD.bazel")).dirname, '')
@@ -36,7 +33,8 @@ def get_root_and_binext(repository_ctx):
3633
else:
3734
fail('Unsupported architecture for MacOS')
3835
elif repository_ctx.os.name.startswith('windows'):
39-
return (repository_ctx.path(Label("@emscripten_bin_win//:BUILD.bazel")).dirname, '.exe')
36+
fail('Using a secondary cache is not supported on Windows')
37+
#return (repository_ctx.path(Label("@emscripten_bin_win//:BUILD.bazel")).dirname, '.bat')
4038
else:
4139
fail('Unsupported operating system')
4240

@@ -49,35 +47,40 @@ def _emscripten_cache_impl(repository_ctx):
4947
)
5048

5149
if repository_ctx.attr.libraries or repository_ctx.attr.flags:
52-
root, binext = get_root_and_binext(repository_ctx)
50+
root, script_ext = get_root_and_script_ext(repository_ctx)
5351
llvm_root = root.get_child("bin")
5452
emscripten_root = root.get_child("emscripten")
55-
embuilder_path = emscripten_root.get_child("embuilder")
56-
cache_path = repository_ctx.path('cache')
57-
nodejs = repository_ctx.path(Label("@nodejs//:BUILD.bazel")).dirname.get_child("bin").get_child("node")
53+
cache = repository_ctx.path("cache")
54+
# Ugly hack to get the "external" directory (needed for Windows/Node.js)
55+
external_root = repository_ctx.path(Label("@nodejs//:BUILD.bazel")).dirname.dirname
5856
# Create configuration file
59-
embuilder_config_content = "NODE_JS = '{}{}'\n".format(nodejs, binext)
60-
embuilder_config_content += "LLVM_ROOT = '{}'\n".format(llvm_root)
61-
embuilder_config_content += "BINARYEN_ROOT = '{}'\n".format(root)
62-
embuilder_config_content += "EMSCRIPTEN_ROOT = '{}'\n".format(emscripten_root)
63-
embuilder_config_content += "CACHE = '{}'\n".format(cache_path)
57+
embuilder_config_content = EMBUILDER_FILE_CONTENT_TEMPLATE.format(
58+
cache=cache,
59+
emscripten_root=emscripten_root,
60+
binaryen_root=root,
61+
llvm_root=llvm_root,
62+
external_root=external_root,
63+
)
6464
repository_ctx.file("embuilder_config", embuilder_config_content)
6565
embuilder_config_path = repository_ctx.path("embuilder_config")
66+
embuilder_path = "{}{}".format(emscripten_root.get_child("embuilder"), script_ext)
6667
# Prepare the command line
6768
if repository_ctx.attr.libraries:
6869
libraries = repository_ctx.attr.libraries
6970
else:
70-
# if no libraries are requested, build everything
71+
# If no libraries are requested, build everything
7172
libraries = ["ALL"]
7273
flags = ["--em-config", embuilder_config_path] + repository_ctx.attr.flags
7374
embuilder_args = [embuilder_path] + flags + ["build"] + libraries
7475
# Run embuilder
7576
repository_ctx.report_progress("Building secondary cache")
76-
result = repository_ctx.execute(embuilder_args, quiet=False)
77+
result = repository_ctx.execute(embuilder_args, quiet=True)
7778
if result.return_code != 0:
79+
# Windows fails here because external/nodejs_windows_amd64/bin/nodejs/node.exe
80+
# does not exist at this point (while the equivalent on Linux and MacOS does)
7881
fail("Embuilder exited with a non-zero return code")
7982
# Override Emscripten's cache with the secondary cache
80-
default_config += "CACHE = '{}'\n".format(cache_path)
83+
default_config += "CACHE = '{}'\n".format(cache)
8184

8285
# Create the configuration file for the toolchain and export
8386
repository_ctx.file('emscripten_config', default_config)

test/test_bazel.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ if (-not $?) { Exit $LastExitCode }
2323
bazel build //:hello-embind-wasm --compilation_mode opt # release
2424
if (-not $?) { Exit $LastExitCode }
2525

26-
Set-Location ..\test_secondary_lto_cache
26+
# Set-Location ..\test_secondary_lto_cache
2727

28-
bazel build //:hello-world-wasm
29-
if (-not $?) { Exit $LastExitCode }
28+
# bazel build //:hello-world-wasm
29+
# if (-not $?) { Exit $LastExitCode }
3030

0 commit comments

Comments
 (0)