@@ -3,6 +3,21 @@ package(default_visibility = ['//visibility:public'])
33exports_files(['emscripten_config'])
44"""
55
6+ BUILD_FILE_USE_BUILTIN_CACHE = """
7+ alias(
8+ name = "emscripten_cache",
9+ actual = "{}//:builtin_cache",
10+ )
11+ """
12+
13+ BUILD_FILE_USE_SECONDARY_CACHE = """
14+ filegroup(
15+ name = "emscripten_cache",
16+ srcs = glob(["cache/**"]),
17+ visibility = ["//visibility:public"],
18+ )
19+ """
20+
621EMBUILDER_CONFIG_TEMPLATE = """
722CACHE = '{cache}'
823BINARYEN_ROOT = '{binaryen_root}'
@@ -29,6 +44,26 @@ def get_root_and_script_ext(repository_ctx):
2944 else :
3045 fail ("Unsupported operating system" )
3146
47+ def get_bin_deps_repo_name (repository_ctx ):
48+ if repository_ctx .os .name .startswith ("linux" ):
49+ if "amd64" in repository_ctx .os .arch or "x86_64" in repository_ctx .os .arch :
50+ return "@emscripten_bin_linux"
51+ elif "aarch64" in repository_ctx .os .arch :
52+ return "@emscripten_bin_linux_arm64"
53+ else :
54+ fail ("Unsupported architecture for Linux" )
55+ elif repository_ctx .os .name .startswith ("mac" ):
56+ if "amd64" in repository_ctx .os .arch or "x86_64" in repository_ctx .os .arch :
57+ return "@emscripten_bin_mac"
58+ elif "aarch64" in repository_ctx .os .arch :
59+ return "@emscripten_bin_mac_arm64"
60+ else :
61+ fail ("Unsupported architecture for MacOS" )
62+ elif repository_ctx .os .name .startswith ("windows" ):
63+ return "@emscripten_bin_win"
64+ else :
65+ fail ("Unsupported operating system" )
66+
3267def _emscripten_cache_repository_impl (repository_ctx ):
3368 # Read the default emscripten configuration file
3469 default_config = repository_ctx .read (
@@ -38,6 +73,8 @@ def _emscripten_cache_repository_impl(repository_ctx):
3873 )
3974
4075 repo_metadata = None
76+ build_file_content = BUILD_FILE_CONTENT_TEMPLATE
77+ use_builtin_cache = True
4178
4279 if repository_ctx .attr .prebuilt_cache_url :
4380 repository_ctx .download_and_extract (
@@ -48,8 +85,7 @@ def _emscripten_cache_repository_impl(repository_ctx):
4885 )
4986
5087 # Use the prebuilt cache
51- prebuilt_cache_path = repository_ctx .path ("cache" )
52- default_config += "CACHE = '{}'\n " .format (prebuilt_cache_path )
88+ use_builtin_cache = False
5389
5490 repo_metadata = repository_ctx .repo_metadata (reproducible = True )
5591
@@ -90,12 +126,17 @@ def _emscripten_cache_repository_impl(repository_ctx):
90126 if result .return_code != 0 :
91127 fail ("Embuilder exited with a non-zero return code" )
92128
93- # Override Emscripten's cache with the secondary cache
94- default_config += "CACHE = '{}'\n " .format (cache )
129+ use_builtin_cache = False
130+
131+ if use_builtin_cache :
132+ build_file_content += BUILD_FILE_USE_BUILTIN_CACHE .format (get_bin_deps_repo_name (repository_ctx ))
133+ else :
134+ default_config += 'CACHE = os.path.join(os.path.dirname(os.environ["EM_CONFIG_PATH"]), "cache")\n '
135+ build_file_content += BUILD_FILE_USE_SECONDARY_CACHE
95136
96137 # Create the configuration file for the toolchain and export
97138 repository_ctx .file ("emscripten_config" , default_config )
98- repository_ctx .file ("BUILD.bazel" , BUILD_FILE_CONTENT_TEMPLATE )
139+ repository_ctx .file ("BUILD.bazel" , build_file_content )
99140
100141 return repo_metadata
101142
0 commit comments