Skip to content

Commit 202d7fb

Browse files
authored
Added support for fetching firefox for wasm_bindgen tests on MacOS (#3597)
Thanks to bazelbuild/apple_support#421 `.dmg` files can now be used to fetch tools on platforms other than MacOS!
1 parent 2892c0b commit 202d7fb

File tree

8 files changed

+55
-57
lines changed

8 files changed

+55
-57
lines changed

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ bazel_dep(name = "platforms", version = "1.0.0")
1515
bazel_dep(name = "rules_cc", version = "0.2.4")
1616
bazel_dep(name = "rules_license", version = "1.0.0")
1717
bazel_dep(name = "rules_shell", version = "0.4.0")
18-
bazel_dep(name = "apple_support", version = "1.22.1", repo_name = "build_bazel_apple_support")
18+
bazel_dep(name = "apple_support", version = "1.23.0", repo_name = "build_bazel_apple_support")
1919

2020
internal_deps = use_extension("//rust/private:internal_extensions.bzl", "i")
2121
use_repo(

extensions/wasm_bindgen/3rdparty/patches/wasm-bindgen-cli.webdriver_json.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ index d392293..7e5a77d 100644
77
};
88
println!("Try find `webdriver.json` for configure browser's capabilities:");
99
- let capabilities: Capabilities = match File::open("webdriver.json") {
10-
+ let capabilities: Capabilities = match File::open(std::env::var("WASM_BINDGEN_WEBDRIVER_JSON").unwrap_or("webdriver.json".to_string())) {
10+
+ let capabilities: Capabilities = match File::open(std::env::var("WASM_BINDGEN_TEST_WEBDRIVER_JSON").unwrap_or("webdriver.json".to_string())) {
1111
Ok(file) => {
1212
println!("Ok");
1313
serde_json::from_reader(file)

extensions/wasm_bindgen/MODULE.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ bazel_dep(name = "bazel_skylib", version = "1.8.1")
1111
bazel_dep(name = "platforms", version = "1.0.0")
1212
bazel_dep(name = "rules_cc", version = "0.2.4")
1313
bazel_dep(name = "aspect_rules_js", version = "2.1.2")
14+
bazel_dep(name = "apple_support", version = "1.23.0")
1415

1516
rust_ext = use_extension("//:extensions.bzl", "rust_ext")
1617
use_repo(
@@ -37,6 +38,7 @@ use_repo(
3738
"firefox_linux_aarch64",
3839
"firefox_linux_x86_64",
3940
"firefox_local",
41+
"firefox_mac",
4042
"geckodriver",
4143
"geckodriver_linux64",
4244
"geckodriver_linux_aarch64",

extensions/wasm_bindgen/private/wasm_bindgen_test_wrapper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ fn main() {
135135

136136
let updated_webdriver_json = undeclared_test_outputs.join("webdriver.json");
137137
env.insert(
138-
"WASM_BINDGEN_WEBDRIVER_JSON".to_string(),
138+
"WASM_BINDGEN_TEST_WEBDRIVER_JSON".to_string(),
139139
updated_webdriver_json.to_string_lossy().to_string(),
140140
);
141141

extensions/wasm_bindgen/private/webdrivers/chrome/webdriver_chrome.bzl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ def chrome_deps():
111111
maybe(
112112
webdriver_repository,
113113
name = name,
114-
original_name = name,
115114
urls = [data["url"]],
116115
strip_prefix = "chromedriver-{}".format(platform),
117116
integrity = data.get("integrity", ""),
@@ -128,7 +127,6 @@ def chrome_deps():
128127
maybe(
129128
webdriver_repository,
130129
name = name,
131-
original_name = name,
132130
urls = [data["url"]],
133131
strip_prefix = "chrome-headless-shell-{}".format(platform),
134132
integrity = data.get("integrity", ""),
@@ -149,7 +147,6 @@ def chrome_deps():
149147
maybe(
150148
webdriver_repository,
151149
name = name,
152-
original_name = name,
153150
urls = [data["url"]],
154151
strip_prefix = "chrome-{}".format(platform),
155152
integrity = data.get("integrity", ""),

extensions/wasm_bindgen/private/webdrivers/firefox/BUILD.firefox.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
alias(
22
name = "firefox_macos",
3-
actual = "@firefox_local//:firefox",
3+
actual = select({
4+
"@platforms//cpu:aarch64": "@firefox_mac",
5+
"//conditions:default": "@firefox_local//:firefox",
6+
}),
47
target_compatible_with = ["@platforms//os:macos"],
58
)
69

extensions/wasm_bindgen/private/webdrivers/firefox/webdriver_firefox.bzl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ def firefox_deps():
123123
maybe(
124124
webdriver_repository,
125125
name = name,
126-
original_name = name,
127126
urls = ["https://github.com/mozilla/geckodriver/releases/download/v{version}/geckodriver-v{version}-{platform}.{archive}".format(
128127
version = geckodriver_version,
129128
platform = platform,
@@ -145,21 +144,32 @@ def firefox_deps():
145144
for platform, integrity in {
146145
"linux-aarch64": "sha256-vveh8MLGr9pl8cHtvj4T/dk1wzaxYkMMfTUTkidAgAo=",
147146
"linux-x86_64": "sha256-UiL1HKrPzK8PDPeVEX8K03Qi/p1BPvGPLBceFiK5RVo=",
147+
"mac": "sha256-B4VZozSRt8XvXc3mL+PIEoNarpi2On4ys79+M8sz/Mg=",
148148
}.items():
149149
archive = "tar.xz"
150+
firefox_name = "firefox"
151+
dash = "-"
152+
strip_prefix = "firefox"
150153
tool = "firefox"
154+
if "mac" in platform:
155+
archive = "dmg"
156+
firefox_name = "Firefox"
157+
dash = "%20"
158+
strip_prefix = ""
159+
tool = "Firefox.app/Contents/MacOS/firefox"
151160
name = "firefox_{}".format(platform.replace("-", "_"))
152161
direct_deps.append(struct(repo = name))
153162
maybe(
154163
webdriver_repository,
155164
name = name,
156-
original_name = name,
157-
urls = ["https://ftp.mozilla.org/pub/firefox/releases/{version}/{platform}/en-US/firefox-{version}.{archive}".format(
165+
urls = ["https://ftp.mozilla.org/pub/firefox/releases/{version}/{platform}/en-US/{name}{dash}{version}.{archive}".format(
166+
name = firefox_name,
167+
dash = dash,
158168
version = firefox_version,
159169
platform = platform,
160170
archive = archive,
161171
)],
162-
strip_prefix = "firefox",
172+
strip_prefix = strip_prefix,
163173
integrity = integrity,
164174
tool = tool,
165175
)
Lines changed: 32 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"""Utilities for webdriver repositories"""
22

3+
load("@apple_support//tools/http_dmg:http_dmg.bzl", "http_dmg")
4+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
5+
36
def _build_file_repository_impl(repository_ctx):
47
repository_ctx.file("WORKSPACE.bazel", """workspace(name = "{}")""".format(
58
repository_ctx.name,
@@ -37,52 +40,35 @@ filegroup(
3740
)
3841
"""
3942

40-
def _webdriver_repository_impl(repository_ctx):
41-
result = repository_ctx.download_and_extract(
42-
repository_ctx.attr.urls,
43-
stripPrefix = repository_ctx.attr.strip_prefix,
44-
integrity = repository_ctx.attr.integrity,
45-
)
43+
def webdriver_repository(
44+
*,
45+
name,
46+
tool,
47+
urls,
48+
integrity = "",
49+
**kwargs):
50+
"""A repository rule for downloading webdriver tools.
4651
47-
repository_ctx.file("WORKSPACE.bazel", """workspace(name = "{}")""".format(
48-
repository_ctx.attr.original_name,
49-
))
52+
Args:
53+
name (str): The name of the repository
54+
tool (str): The name of the webdriver tool being downloaded.
55+
urls (list[str]): A list of URLs to a file that will be made available to Bazel.
56+
integrity (str): Expected checksum in Subresource Integrity format of the file downloaded.
57+
**kwargs (dict): Additional keyword arguments.
58+
"""
59+
impl_rule = http_archive
60+
for url in urls:
61+
if url.endswith(".dmg"):
62+
impl_rule = http_dmg
63+
break
5064

51-
repository_ctx.file("BUILD.bazel", _WEBDRIVER_BUILD_CONTENT.format(
52-
name = repository_ctx.attr.original_name,
53-
tool = repository_ctx.attr.tool,
54-
))
55-
56-
return {
57-
"integrity": result.integrity,
58-
"name": repository_ctx.name,
59-
"original_name": repository_ctx.attr.original_name,
60-
"strip_prefix": repository_ctx.attr.strip_prefix,
61-
"tool": repository_ctx.attr.tool,
62-
"urls": repository_ctx.attr.urls,
63-
}
64-
65-
webdriver_repository = repository_rule(
66-
doc = "A repository rule for downloading webdriver tools.",
67-
implementation = _webdriver_repository_impl,
68-
attrs = {
69-
"integrity": attr.string(
70-
doc = """Expected checksum in Subresource Integrity format of the file downloaded.""",
71-
),
72-
# TODO: This can be removed in Bazel 8 and it's use moved to `repository_ctx.original_name`.
73-
"original_name": attr.string(
74-
doc = "The original name of the repository.",
65+
impl_rule(
66+
name = name,
67+
urls = urls,
68+
integrity = integrity,
69+
build_file_content = _WEBDRIVER_BUILD_CONTENT.format(
70+
name = name,
71+
tool = tool,
7572
),
76-
"strip_prefix": attr.string(
77-
doc = """A directory prefix to strip from the extracted files.""",
78-
),
79-
"tool": attr.string(
80-
doc = "The name of the webdriver tool being downloaded.",
81-
mandatory = True,
82-
),
83-
"urls": attr.string_list(
84-
doc = "A list of URLs to a file that will be made available to Bazel.",
85-
mandatory = True,
86-
),
87-
},
88-
)
73+
**kwargs
74+
)

0 commit comments

Comments
 (0)