@@ -3,6 +3,44 @@ package(default_visibility = ['//visibility:public'])
3
3
exports_files(['emscripten_config'])
4
4
"""
5
5
6
+ def get_binaryen_root (repository_ctx ):
7
+ """
8
+ Retrieve the path to the Emscripten binary directory
9
+
10
+ This function determines the correct Emscripten binary directory path by
11
+ examining the operating system (OS) and architecture (arch) of the
12
+ environment. It supports Linux, macOS, and Windows operating systems with
13
+ specific architectures.
14
+
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.
22
+
23
+ """
24
+ if repository_ctx .os .name .startswith ('linux' ):
25
+ if 'amd64' in repository_ctx .os .arch or 'x86_64' in repository_ctx .os .arch :
26
+ return repository_ctx .path (Label ("@emscripten_bin_linux//:all" )).dirname
27
+ elif 'aarch64' in repository_ctx .os .arch :
28
+ return repository_ctx .path (Label ("@emscripten_bin_linux_arm64//:all" )).dirname
29
+ else :
30
+ repository_ctx .fail ('Unsupported architecture for Linux' )
31
+ elif repository_ctx .os .name .startswith ('mac' ):
32
+ if 'amd64' in repository_ctx .os .arch or 'x86_64' in repository_ctx .os .arch :
33
+ return repository_ctx .path (Label ("@emscripten_bin_mac//:all" )).dirname
34
+ elif 'aarch64' in repository_ctx .os .arch :
35
+ return repository_ctx .path (Label ("@emscripten_bin_mac_arm64//:all" )).dirname
36
+ else :
37
+ repository_ctx .fail ('Unsupported architecture for MacOS' )
38
+ elif repository_ctx .os .name .startswith ('windows' ):
39
+ return repository_ctx .path (Label ("@emscripten_bin_win//:all" )).dirname
40
+ else :
41
+ repository_ctx .fail ('Unsupported operating system' )
42
+ return ''
43
+
6
44
def _emscripten_cache_impl (repository_ctx ):
7
45
# Read the default emscripten configuration file
8
46
default_config = repository_ctx .read (
@@ -11,11 +49,9 @@ def _emscripten_cache_impl(repository_ctx):
11
49
)
12
50
)
13
51
14
- # TODO I need a cross platform way to get embuilder and bin/node
15
52
if repository_ctx .attr .libraries or repository_ctx .attr .flags :
16
- # Get paths to tools (toolchain is not yet setup, so we cannot use emscripten_config)
17
- embuilder_path = repository_ctx .path (Label ("@emscripten_bin_linux//:emscripten/embuilder.py" ))
18
- binaryen_root = embuilder_path .dirname .dirname
53
+ binaryen_root = get_binaryen_root (repository_ctx )
54
+ embuilder_path = binaryen_root .get_child ('emscripten/embuilder' )
19
55
llvm_root = binaryen_root .get_child ("bin" )
20
56
nodejs = repository_ctx .path (Label ("@nodejs//:node_files" )).dirname .get_child ('bin/node' )
21
57
# Create configuration file
@@ -38,6 +74,7 @@ def _emscripten_cache_impl(repository_ctx):
38
74
repository_ctx .execute (embuilder_args , quiet = False )
39
75
# Override Emscripten's cache with the secondary cache
40
76
default_config += "CACHE = '{}'\n " .format (repository_ctx .path ('cache' ))
77
+
41
78
# Create the configuration file for the toolchain and export
42
79
repository_ctx .file ('emscripten_config' , default_config )
43
80
repository_ctx .file ('BUILD.bazel' , BUILD_FILE_CONTENT_TEMPLATE )
0 commit comments