Skip to content

Commit 4d023c1

Browse files
authored
Add firefox linux binaries for rust_wasm_bindgen_test (#3320)
The firefox binaries are only available for linux since there is no easy way to extract a `.dmg` for macos and the `.exe` that firefox distributes for the relevant platforms. Additionally, the `@rules_rust_wasm_bindgen//:test_browser` setting moved to `@rules_rust_wasm_bindgen//settings:test_browser`
1 parent 4301846 commit 4d023c1

File tree

12 files changed

+158
-64
lines changed

12 files changed

+158
-64
lines changed

.bazelci/presubmit.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,14 +1067,13 @@ tasks:
10671067
name: Extensions wasm-bindgen
10681068
working_directory: extensions/wasm_bindgen
10691069
shell_commands:
1070-
- "sudo apt -y update && sudo apt -y install libxcb1 libatk1.0-0 libatk-bridge2.0-0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1 libpango-1.0-0 libxkbcommon-x11-0 libcairo2"
1070+
- "bash ./test/bazelci_linux_setup.sh"
10711071
build_flags: *aspects_flags
10721072
test_flags: *aspects_flags
10731073
build_targets:
10741074
- "//..."
1075-
# TODO: Chromedriver cannot launch chrome on linux
1076-
# test_targets:
1077-
# - "//..."
1075+
test_targets:
1076+
- "//..."
10781077
extensions_wasm_bindgen_linux_rbe:
10791078
platform: rbe_ubuntu2004
10801079
name: Extensions wasm-bindgen
@@ -1086,13 +1085,9 @@ tasks:
10861085
test_flags: *aspects_flags
10871086
build_targets:
10881087
- "//..."
1089-
# TODO: Chromedriver cannot launch chrome on linux
1088+
# TODO: https://github.com/bazelbuild/rules_rust/issues/3039
10901089
# test_targets:
1091-
# - "--"
10921090
# - "//..."
1093-
# # TODO: https://github.com/bazelbuild/rules_rust/issues/3039
1094-
# - "-//rules_js/test:hello_world_wasm_lib_test"
1095-
# - "-//rules_js/test:hello_world_wasm_direct_test"
10961091
extensions_wasm_bindgen_macos:
10971092
platform: macos_arm64
10981093
name: Extensions wasm-bindgen
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
bcr_test_module:
22
module_path: ""
33
matrix:
4-
platform: ["macos_arm64", "ubuntu2004", "windows"]
4+
platform: ["macos_arm64", "windows"]
55
bazel: ["7.x", "8.x"]
66
tasks:
77
run_tests:
@@ -10,3 +10,17 @@ bcr_test_module:
1010
bazel: ${{ bazel }}
1111
test_targets:
1212
- "//..."
13+
bcr_test_module_linux:
14+
module_path: ""
15+
matrix:
16+
platform: ["ubuntu2004"]
17+
bazel: ["7.x", "8.x"]
18+
tasks:
19+
run_tests:
20+
shell_commands:
21+
- "bash ./test/bazelci_linux_setup.sh"
22+
name: "Run test module"
23+
platform: ${{ platform }}
24+
bazel: ${{ bazel }}
25+
test_targets:
26+
- "//..."

extensions/wasm_bindgen/.bazelrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ common --experimental_cc_shared_library
2929
## Unique configuration groups
3030
###############################################################################
3131

32+
# Explicitly use firefox for browser tests.
33+
build:firefox --//settings:test_browser=firefox
34+
35+
# Explicitly use chrome for browser tests
36+
build:chrome --//settings:test_browser=chrome
37+
38+
# Default linux to run firefox
39+
build:linux --config=firefox
40+
3241
# Enable use of the nightly toolchains.
3342
build:nightly --@rules_rust//rust/toolchain/channel=nightly
3443

extensions/wasm_bindgen/BUILD.bazel

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
2-
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
32
load(":defs.bzl", "rust_wasm_bindgen_toolchain")
43

54
exports_files([
@@ -13,32 +12,6 @@ toolchain_type(
1312
visibility = ["//visibility:public"],
1413
)
1514

16-
string_flag(
17-
name = "test_browser",
18-
build_setting_default = "chrome",
19-
values = [
20-
"chrome",
21-
"firefox",
22-
],
23-
visibility = ["//visibility:public"],
24-
)
25-
26-
config_setting(
27-
name = "test_browser_chrome",
28-
flag_values = {
29-
":test_browser": "chrome",
30-
},
31-
visibility = ["//visibility:public"],
32-
)
33-
34-
config_setting(
35-
name = "test_browser_firefox",
36-
flag_values = {
37-
":test_browser": "firefox",
38-
},
39-
visibility = ["//visibility:public"],
40-
)
41-
4215
bzl_library(
4316
name = "bzl_lib",
4417
srcs = glob(["**/*.bzl"]),
@@ -52,24 +25,24 @@ bzl_library(
5225
rust_wasm_bindgen_toolchain(
5326
name = "default_wasm_bindgen_toolchain_impl",
5427
browser = select({
55-
":test_browser_chrome": "@chrome",
56-
":test_browser_firefox": "@firefox",
28+
"//settings:test_browser_chrome": "@chrome",
29+
"//settings:test_browser_firefox": "@firefox",
5730
}),
5831
browser_type = select({
59-
":test_browser_chrome": "chrome",
60-
":test_browser_firefox": "firefox",
32+
"//settings:test_browser_chrome": "chrome",
33+
"//settings:test_browser_firefox": "firefox",
6134
}),
6235
visibility = ["//visibility:public"],
6336
wasm_bindgen_cli = "//3rdparty:wasm_bindgen_cli",
6437
wasm_bindgen_test = "//3rdparty:wasm_bindgen_test",
6538
wasm_bindgen_test_runner = "//3rdparty:wasm_bindgen_test_runner",
6639
webdriver = select({
67-
":test_browser_chrome": "@chromedriver",
68-
":test_browser_firefox": "@geckodriver",
40+
"//settings:test_browser_chrome": "@chromedriver",
41+
"//settings:test_browser_firefox": "@geckodriver",
6942
}),
7043
webdriver_args = select({
71-
":test_browser_chrome": ["--verbose"],
72-
":test_browser_firefox": [],
44+
"//settings:test_browser_chrome": ["--verbose"],
45+
"//settings:test_browser_firefox": [],
7346
}),
7447
webdriver_json = "webdriver.json",
7548
)

extensions/wasm_bindgen/MODULE.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ use_repo(
3434
"chromedriver_win32",
3535
"chromedriver_win64",
3636
"firefox",
37+
"firefox_linux_aarch64",
38+
"firefox_linux_x86_64",
39+
"firefox_local",
3740
"geckodriver",
3841
"geckodriver_linux64",
3942
"geckodriver_linux_aarch64",

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ alias(
99

1010
alias(
1111
name = "chrome_linux",
12-
actual = select({
13-
"@platforms//cpu:aarch64": "@chrome_linux_aarch64",
14-
"//conditions:default": "@chrome_linux64",
15-
}),
12+
actual = "@chrome_linux64",
1613
target_compatible_with = ["@platforms//os:linux"],
1714
)
1815

@@ -28,7 +25,7 @@ alias(
2825
alias(
2926
name = "chrome",
3027
actual = select({
31-
"@platforms//os:linux": "@chrome_linux64",
28+
"@platforms//os:linux": ":chrome_linux",
3229
"@platforms//os:macos": ":chrome_macos",
3330
"@platforms//os:windows": ":chrome_windows",
3431
}),

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ alias(
99

1010
alias(
1111
name = "chrome_headless_shell_linux",
12-
actual = select({
13-
"@platforms//cpu:aarch64": "@chrome_headless_shell_linux_aarch64",
14-
"//conditions:default": "@chrome_headless_shell_linux64",
15-
}),
12+
actual = "@chrome_headless_shell_linux64",
1613
target_compatible_with = ["@platforms//os:linux"],
1714
)
1815

@@ -28,7 +25,7 @@ alias(
2825
alias(
2926
name = "chrome_headless_shell",
3027
actual = select({
31-
"@platforms//os:linux": "@chrome_headless_shell_linux64",
28+
"@platforms//os:linux": ":chrome_headless_shell_linux",
3229
"@platforms//os:macos": ":chrome_headless_shell_macos",
3330
"@platforms//os:windows": ":chrome_headless_shell_windows",
3431
}),

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ alias(
99

1010
alias(
1111
name = "chromedriver_linux",
12-
actual = select({
13-
"@platforms//cpu:aarch64": "@chromedriver_linux_aarch64",
14-
"//conditions:default": "@chromedriver_linux64",
15-
}),
12+
actual = "@chromedriver_linux64",
1613
target_compatible_with = ["@platforms//os:linux"],
1714
)
1815

@@ -28,7 +25,7 @@ alias(
2825
alias(
2926
name = "chromedriver",
3027
actual = select({
31-
"@platforms//os:linux": "@chromedriver_linux64",
28+
"@platforms//os:linux": ":chromedriver_linux",
3229
"@platforms//os:macos": ":chromedriver_macos",
3330
"@platforms//os:windows": ":chromedriver_windows",
3431
}),
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
alias(
2+
name = "firefox_macos",
3+
actual = "@firefox_local//:firefox",
4+
target_compatible_with = ["@platforms//os:macos"],
5+
)
6+
7+
alias(
8+
name = "firefox_linux",
9+
actual = select({
10+
"@platforms//cpu:aarch64": "@firefox_linux_aarch64",
11+
"//conditions:default": "@firefox_linux_x86_64",
12+
}),
13+
target_compatible_with = ["@platforms//os:linux"],
14+
)
15+
16+
alias(
17+
name = "firefox_windows",
18+
actual = "@firefox_local//:firefox",
19+
target_compatible_with = ["@platforms//os:windows"],
20+
)
21+
22+
alias(
23+
name = "firefox",
24+
actual = select({
25+
"@platforms//os:linux": ":firefox_linux",
26+
"@platforms//os:macos": ":firefox_macos",
27+
"@platforms//os:windows": ":firefox_windows",
28+
}),
29+
visibility = ["//visibility:public"],
30+
)

extensions/wasm_bindgen/private/webdrivers/webdriver_repositories.bzl

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ alias(
139139
)
140140
"""
141141

142-
def _local_firefox_repository_impl(repository_ctx):
142+
def _firefox_local_repository_impl(repository_ctx):
143143
repository_ctx.file("WORKSPACE.bazel", """workspace(name = "{}")""".format(
144144
repository_ctx.name,
145145
))
@@ -168,7 +168,7 @@ def _local_firefox_repository_impl(repository_ctx):
168168

169169
repository_ctx.file("BUILD.bazel", _FIREFOX_BUILD_CONTENT_WINDOWS if is_windows else _FIREFOX_BUILD_CONTENT_UNIX)
170170

171-
local_firefox_repository = repository_rule(
171+
firefox_local_repository = repository_rule(
172172
doc = """\
173173
A repository rule for wrapping the path to a host installed firefox binary
174174
@@ -177,7 +177,7 @@ Note that firefox binaries can be found here: https://ftp.mozilla.org/pub/firefo
177177
However, for platforms like MacOS and Windows, the storage formats are not something that can be extracted
178178
in a repository rule.
179179
""",
180-
implementation = _local_firefox_repository_impl,
180+
implementation = _firefox_local_repository_impl,
181181
environ = ["FIREFOX_BINARY"],
182182
)
183183

@@ -226,10 +226,41 @@ def firefox_deps():
226226
build_file = Label("//private/webdrivers:BUILD.geckodriver.bazel"),
227227
)
228228

229+
firefox_version = "136.0"
230+
231+
for platform, integrity in {
232+
"linux-aarch64": "sha256-vveh8MLGr9pl8cHtvj4T/dk1wzaxYkMMfTUTkidAgAo=",
233+
"linux-x86_64": "sha256-UiL1HKrPzK8PDPeVEX8K03Qi/p1BPvGPLBceFiK5RVo=",
234+
}.items():
235+
archive = "tar.xz"
236+
tool = "firefox"
237+
name = "firefox_{}".format(platform.replace("-", "_"))
238+
direct_deps.append(struct(repo = name))
239+
maybe(
240+
webdriver_repository,
241+
name = name,
242+
original_name = name,
243+
urls = ["https://ftp.mozilla.org/pub/firefox/releases/{version}/{platform}/en-US/firefox-{version}.{archive}".format(
244+
version = firefox_version,
245+
platform = platform,
246+
archive = archive,
247+
)],
248+
strip_prefix = "firefox",
249+
integrity = integrity,
250+
tool = tool,
251+
)
252+
253+
direct_deps.append(struct(repo = "firefox_local"))
254+
maybe(
255+
firefox_local_repository,
256+
name = "firefox_local",
257+
)
258+
229259
direct_deps.append(struct(repo = "firefox"))
230260
maybe(
231-
local_firefox_repository,
261+
build_file_repository,
232262
name = "firefox",
263+
build_file = Label("//private/webdrivers:BUILD.firefox.bazel"),
233264
)
234265

235266
return direct_deps

0 commit comments

Comments
 (0)