diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index c55eb2a935..a7979e3200 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -1067,14 +1067,13 @@ tasks: name: Extensions wasm-bindgen working_directory: extensions/wasm_bindgen shell_commands: - - "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" + - "bash ./test/bazelci_linux_setup.sh" build_flags: *aspects_flags test_flags: *aspects_flags build_targets: - "//..." - # TODO: Chromedriver cannot launch chrome on linux - # test_targets: - # - "//..." + test_targets: + - "//..." extensions_wasm_bindgen_linux_rbe: platform: rbe_ubuntu2004 name: Extensions wasm-bindgen @@ -1086,13 +1085,9 @@ tasks: test_flags: *aspects_flags build_targets: - "//..." - # TODO: Chromedriver cannot launch chrome on linux + # TODO: https://github.com/bazelbuild/rules_rust/issues/3039 # test_targets: - # - "--" # - "//..." - # # TODO: https://github.com/bazelbuild/rules_rust/issues/3039 - # - "-//rules_js/test:hello_world_wasm_lib_test" - # - "-//rules_js/test:hello_world_wasm_direct_test" extensions_wasm_bindgen_macos: platform: macos_arm64 name: Extensions wasm-bindgen diff --git a/.bcr/extensions/wasm_bindgen/presubmit.yml b/.bcr/extensions/wasm_bindgen/presubmit.yml index 6618ebb522..4982202547 100644 --- a/.bcr/extensions/wasm_bindgen/presubmit.yml +++ b/.bcr/extensions/wasm_bindgen/presubmit.yml @@ -1,7 +1,7 @@ bcr_test_module: module_path: "" matrix: - platform: ["macos_arm64", "ubuntu2004", "windows"] + platform: ["macos_arm64", "windows"] bazel: ["7.x", "8.x"] tasks: run_tests: @@ -10,3 +10,17 @@ bcr_test_module: bazel: ${{ bazel }} test_targets: - "//..." +bcr_test_module_linux: + module_path: "" + matrix: + platform: ["ubuntu2004"] + bazel: ["7.x", "8.x"] + tasks: + run_tests: + shell_commands: + - "bash ./test/bazelci_linux_setup.sh" + name: "Run test module" + platform: ${{ platform }} + bazel: ${{ bazel }} + test_targets: + - "//..." diff --git a/extensions/wasm_bindgen/.bazelrc b/extensions/wasm_bindgen/.bazelrc index 1e36d13020..726f1f5d97 100644 --- a/extensions/wasm_bindgen/.bazelrc +++ b/extensions/wasm_bindgen/.bazelrc @@ -29,6 +29,15 @@ common --experimental_cc_shared_library ## Unique configuration groups ############################################################################### +# Explicitly use firefox for browser tests. +build:firefox --//settings:test_browser=firefox + +# Explicitly use chrome for browser tests +build:chrome --//settings:test_browser=chrome + +# Default linux to run firefox +build:linux --config=firefox + # Enable use of the nightly toolchains. build:nightly --@rules_rust//rust/toolchain/channel=nightly diff --git a/extensions/wasm_bindgen/BUILD.bazel b/extensions/wasm_bindgen/BUILD.bazel index b2296528ee..33254182fb 100644 --- a/extensions/wasm_bindgen/BUILD.bazel +++ b/extensions/wasm_bindgen/BUILD.bazel @@ -1,5 +1,4 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") -load("@bazel_skylib//rules:common_settings.bzl", "string_flag") load(":defs.bzl", "rust_wasm_bindgen_toolchain") exports_files([ @@ -13,32 +12,6 @@ toolchain_type( visibility = ["//visibility:public"], ) -string_flag( - name = "test_browser", - build_setting_default = "chrome", - values = [ - "chrome", - "firefox", - ], - visibility = ["//visibility:public"], -) - -config_setting( - name = "test_browser_chrome", - flag_values = { - ":test_browser": "chrome", - }, - visibility = ["//visibility:public"], -) - -config_setting( - name = "test_browser_firefox", - flag_values = { - ":test_browser": "firefox", - }, - visibility = ["//visibility:public"], -) - bzl_library( name = "bzl_lib", srcs = glob(["**/*.bzl"]), @@ -52,24 +25,24 @@ bzl_library( rust_wasm_bindgen_toolchain( name = "default_wasm_bindgen_toolchain_impl", browser = select({ - ":test_browser_chrome": "@chrome", - ":test_browser_firefox": "@firefox", + "//settings:test_browser_chrome": "@chrome", + "//settings:test_browser_firefox": "@firefox", }), browser_type = select({ - ":test_browser_chrome": "chrome", - ":test_browser_firefox": "firefox", + "//settings:test_browser_chrome": "chrome", + "//settings:test_browser_firefox": "firefox", }), visibility = ["//visibility:public"], wasm_bindgen_cli = "//3rdparty:wasm_bindgen_cli", wasm_bindgen_test = "//3rdparty:wasm_bindgen_test", wasm_bindgen_test_runner = "//3rdparty:wasm_bindgen_test_runner", webdriver = select({ - ":test_browser_chrome": "@chromedriver", - ":test_browser_firefox": "@geckodriver", + "//settings:test_browser_chrome": "@chromedriver", + "//settings:test_browser_firefox": "@geckodriver", }), webdriver_args = select({ - ":test_browser_chrome": ["--verbose"], - ":test_browser_firefox": [], + "//settings:test_browser_chrome": ["--verbose"], + "//settings:test_browser_firefox": [], }), webdriver_json = "webdriver.json", ) diff --git a/extensions/wasm_bindgen/MODULE.bazel b/extensions/wasm_bindgen/MODULE.bazel index ed5592a842..72c5d7e362 100644 --- a/extensions/wasm_bindgen/MODULE.bazel +++ b/extensions/wasm_bindgen/MODULE.bazel @@ -34,6 +34,9 @@ use_repo( "chromedriver_win32", "chromedriver_win64", "firefox", + "firefox_linux_aarch64", + "firefox_linux_x86_64", + "firefox_local", "geckodriver", "geckodriver_linux64", "geckodriver_linux_aarch64", diff --git a/extensions/wasm_bindgen/private/webdrivers/BUILD.chrome.bazel b/extensions/wasm_bindgen/private/webdrivers/BUILD.chrome.bazel index eb1c4f0531..c39a666136 100644 --- a/extensions/wasm_bindgen/private/webdrivers/BUILD.chrome.bazel +++ b/extensions/wasm_bindgen/private/webdrivers/BUILD.chrome.bazel @@ -9,10 +9,7 @@ alias( alias( name = "chrome_linux", - actual = select({ - "@platforms//cpu:aarch64": "@chrome_linux_aarch64", - "//conditions:default": "@chrome_linux64", - }), + actual = "@chrome_linux64", target_compatible_with = ["@platforms//os:linux"], ) @@ -28,7 +25,7 @@ alias( alias( name = "chrome", actual = select({ - "@platforms//os:linux": "@chrome_linux64", + "@platforms//os:linux": ":chrome_linux", "@platforms//os:macos": ":chrome_macos", "@platforms//os:windows": ":chrome_windows", }), diff --git a/extensions/wasm_bindgen/private/webdrivers/BUILD.chrome_headless_shell.bazel b/extensions/wasm_bindgen/private/webdrivers/BUILD.chrome_headless_shell.bazel index 0fedc6afae..934c9bc107 100644 --- a/extensions/wasm_bindgen/private/webdrivers/BUILD.chrome_headless_shell.bazel +++ b/extensions/wasm_bindgen/private/webdrivers/BUILD.chrome_headless_shell.bazel @@ -9,10 +9,7 @@ alias( alias( name = "chrome_headless_shell_linux", - actual = select({ - "@platforms//cpu:aarch64": "@chrome_headless_shell_linux_aarch64", - "//conditions:default": "@chrome_headless_shell_linux64", - }), + actual = "@chrome_headless_shell_linux64", target_compatible_with = ["@platforms//os:linux"], ) @@ -28,7 +25,7 @@ alias( alias( name = "chrome_headless_shell", actual = select({ - "@platforms//os:linux": "@chrome_headless_shell_linux64", + "@platforms//os:linux": ":chrome_headless_shell_linux", "@platforms//os:macos": ":chrome_headless_shell_macos", "@platforms//os:windows": ":chrome_headless_shell_windows", }), diff --git a/extensions/wasm_bindgen/private/webdrivers/BUILD.chromedriver.bazel b/extensions/wasm_bindgen/private/webdrivers/BUILD.chromedriver.bazel index 9da63a1cdd..a55e8d4312 100644 --- a/extensions/wasm_bindgen/private/webdrivers/BUILD.chromedriver.bazel +++ b/extensions/wasm_bindgen/private/webdrivers/BUILD.chromedriver.bazel @@ -9,10 +9,7 @@ alias( alias( name = "chromedriver_linux", - actual = select({ - "@platforms//cpu:aarch64": "@chromedriver_linux_aarch64", - "//conditions:default": "@chromedriver_linux64", - }), + actual = "@chromedriver_linux64", target_compatible_with = ["@platforms//os:linux"], ) @@ -28,7 +25,7 @@ alias( alias( name = "chromedriver", actual = select({ - "@platforms//os:linux": "@chromedriver_linux64", + "@platforms//os:linux": ":chromedriver_linux", "@platforms//os:macos": ":chromedriver_macos", "@platforms//os:windows": ":chromedriver_windows", }), diff --git a/extensions/wasm_bindgen/private/webdrivers/BUILD.firefox.bazel b/extensions/wasm_bindgen/private/webdrivers/BUILD.firefox.bazel new file mode 100644 index 0000000000..31e647816a --- /dev/null +++ b/extensions/wasm_bindgen/private/webdrivers/BUILD.firefox.bazel @@ -0,0 +1,30 @@ +alias( + name = "firefox_macos", + actual = "@firefox_local//:firefox", + target_compatible_with = ["@platforms//os:macos"], +) + +alias( + name = "firefox_linux", + actual = select({ + "@platforms//cpu:aarch64": "@firefox_linux_aarch64", + "//conditions:default": "@firefox_linux_x86_64", + }), + target_compatible_with = ["@platforms//os:linux"], +) + +alias( + name = "firefox_windows", + actual = "@firefox_local//:firefox", + target_compatible_with = ["@platforms//os:windows"], +) + +alias( + name = "firefox", + actual = select({ + "@platforms//os:linux": ":firefox_linux", + "@platforms//os:macos": ":firefox_macos", + "@platforms//os:windows": ":firefox_windows", + }), + visibility = ["//visibility:public"], +) diff --git a/extensions/wasm_bindgen/private/webdrivers/webdriver_repositories.bzl b/extensions/wasm_bindgen/private/webdrivers/webdriver_repositories.bzl index bc4eef4908..4469cbf90d 100644 --- a/extensions/wasm_bindgen/private/webdrivers/webdriver_repositories.bzl +++ b/extensions/wasm_bindgen/private/webdrivers/webdriver_repositories.bzl @@ -139,7 +139,7 @@ alias( ) """ -def _local_firefox_repository_impl(repository_ctx): +def _firefox_local_repository_impl(repository_ctx): repository_ctx.file("WORKSPACE.bazel", """workspace(name = "{}")""".format( repository_ctx.name, )) @@ -168,7 +168,7 @@ def _local_firefox_repository_impl(repository_ctx): repository_ctx.file("BUILD.bazel", _FIREFOX_BUILD_CONTENT_WINDOWS if is_windows else _FIREFOX_BUILD_CONTENT_UNIX) -local_firefox_repository = repository_rule( +firefox_local_repository = repository_rule( doc = """\ A repository rule for wrapping the path to a host installed firefox binary @@ -177,7 +177,7 @@ Note that firefox binaries can be found here: https://ftp.mozilla.org/pub/firefo However, for platforms like MacOS and Windows, the storage formats are not something that can be extracted in a repository rule. """, - implementation = _local_firefox_repository_impl, + implementation = _firefox_local_repository_impl, environ = ["FIREFOX_BINARY"], ) @@ -226,10 +226,41 @@ def firefox_deps(): build_file = Label("//private/webdrivers:BUILD.geckodriver.bazel"), ) + firefox_version = "136.0" + + for platform, integrity in { + "linux-aarch64": "sha256-vveh8MLGr9pl8cHtvj4T/dk1wzaxYkMMfTUTkidAgAo=", + "linux-x86_64": "sha256-UiL1HKrPzK8PDPeVEX8K03Qi/p1BPvGPLBceFiK5RVo=", + }.items(): + archive = "tar.xz" + tool = "firefox" + name = "firefox_{}".format(platform.replace("-", "_")) + direct_deps.append(struct(repo = name)) + maybe( + webdriver_repository, + name = name, + original_name = name, + urls = ["https://ftp.mozilla.org/pub/firefox/releases/{version}/{platform}/en-US/firefox-{version}.{archive}".format( + version = firefox_version, + platform = platform, + archive = archive, + )], + strip_prefix = "firefox", + integrity = integrity, + tool = tool, + ) + + direct_deps.append(struct(repo = "firefox_local")) + maybe( + firefox_local_repository, + name = "firefox_local", + ) + direct_deps.append(struct(repo = "firefox")) maybe( - local_firefox_repository, + build_file_repository, name = "firefox", + build_file = Label("//private/webdrivers:BUILD.firefox.bazel"), ) return direct_deps diff --git a/extensions/wasm_bindgen/settings/BUILD.bazel b/extensions/wasm_bindgen/settings/BUILD.bazel new file mode 100644 index 0000000000..9b49da9b44 --- /dev/null +++ b/extensions/wasm_bindgen/settings/BUILD.bazel @@ -0,0 +1,27 @@ +load("@bazel_skylib//rules:common_settings.bzl", "string_flag") + +string_flag( + name = "test_browser", + build_setting_default = "chrome", + values = [ + "chrome", + "firefox", + ], + visibility = ["//visibility:public"], +) + +config_setting( + name = "test_browser_chrome", + flag_values = { + ":test_browser": "chrome", + }, + visibility = ["//visibility:public"], +) + +config_setting( + name = "test_browser_firefox", + flag_values = { + ":test_browser": "firefox", + }, + visibility = ["//visibility:public"], +) diff --git a/extensions/wasm_bindgen/test/bazelci_linux_setup.sh b/extensions/wasm_bindgen/test/bazelci_linux_setup.sh new file mode 100755 index 0000000000..6beba816e3 --- /dev/null +++ b/extensions/wasm_bindgen/test/bazelci_linux_setup.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# A script for installing the necessary dependencies on Buildkite workers to run +# `rust_wasm_bindgen_test` targets. + +set -euo pipefail + +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 \ + libgtk-3-0 \ + libx11-xcb1