Skip to content

Added safari support for rust_wasm_bindgen_test #3328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ tasks:
name: Extensions wasm-bindgen
working_directory: extensions/wasm_bindgen
shell_commands:
- "bash ./test/bazelci_linux_setup.sh"
- "bash ./test/bazelci_unix_setup.sh"
build_flags: *aspects_flags
test_flags: *aspects_flags
build_targets:
Expand All @@ -1104,13 +1104,16 @@ tasks:
extensions_wasm_bindgen_macos:
platform: macos_arm64
name: Extensions wasm-bindgen
working_directory: extensions
working_directory: extensions/wasm_bindgen
shell_commands:
- "bash ./test/bazelci_unix_setup.sh"
build_flags: *aspects_flags
test_flags: *aspects_flags
build_targets:
- "//..."
test_targets:
- "//..."
# TODO: https://github.com/bazelbuild/rules_rust/issues/3039
# test_targets:
# - "//..."
extensions_wasm_bindgen_windows:
platform: windows
name: Extensions wasm-bindgen
Expand Down
17 changes: 10 additions & 7 deletions .bcr/extensions/wasm_bindgen/presubmit.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
bcr_test_module:
module_path: ""
matrix:
platform: ["macos_arm64", "windows"]
platform: ["ubuntu2004", "windows"]
bazel: ["7.x", "8.x"]
tasks:
run_tests:
name: "Run test module"
platform: ${{ platform }}
bazel: ${{ bazel }}
shell_commands:
- "bash ./test/bazelci_unix_setup.sh"
test_targets:
- "//..."
bcr_test_module_linux:
bcr_test_module_macos:
module_path: ""
matrix:
platform: ["ubuntu2004"]
platform: ["macos_arm64"]
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:
- "//..."
shell_commands:
- "bash ./test/bazelci_unix_setup.sh"
# TODO: https://github.com/bazelbuild/rules_rust/issues/3039
# test_targets:
# - "//..."
11 changes: 4 additions & 7 deletions extensions/wasm_bindgen/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
# TODO: https://github.com/bazelbuild/rules_rust/issues/3319
common --deleted_packages=rules_js,rules_js/test

# An alias for the test browser setting.
common --flag_alias=test_browser=//settings:test_browser

###############################################################################

# https://bazel.build/reference/command-line-reference#flag--enable_platform_specific_config
Expand All @@ -29,14 +32,8 @@ 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
build:linux --test_browser=firefox

# Enable use of the nightly toolchains.
build:nightly --@rules_rust//rust/toolchain/channel=nightly
Expand Down
4 changes: 4 additions & 0 deletions extensions/wasm_bindgen/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ rust_wasm_bindgen_toolchain(
browser = select({
"//settings:test_browser_chrome": "@chrome",
"//settings:test_browser_firefox": "@firefox",
"//settings:test_browser_safari": None,
}),
browser_type = select({
"//settings:test_browser_chrome": "chrome",
"//settings:test_browser_firefox": "firefox",
"//settings:test_browser_safari": "safari",
}),
visibility = ["//visibility:public"],
wasm_bindgen_cli = "//3rdparty:wasm_bindgen_cli",
Expand All @@ -39,10 +41,12 @@ rust_wasm_bindgen_toolchain(
webdriver = select({
"//settings:test_browser_chrome": "@chromedriver",
"//settings:test_browser_firefox": "@geckodriver",
"//settings:test_browser_safari": "@safaridriver",
}),
webdriver_args = select({
"//settings:test_browser_chrome": ["--verbose"],
"//settings:test_browser_firefox": [],
"//settings:test_browser_safari": [],
}),
webdriver_json = "webdriver.json",
)
Expand Down
1 change: 1 addition & 0 deletions extensions/wasm_bindgen/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ use_repo(
"rrwbd__wasmparser-0.214.0",
"rrwbd__wasmprinter-0.214.0",
"rules_rust_wasm_bindgen_cli",
"safaridriver",
)

register_toolchains(
Expand Down
1 change: 1 addition & 0 deletions extensions/wasm_bindgen/private/wasm_bindgen.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ For additional information, see the [Bazel toolchains documentation][toolchains]
values = [
"firefox",
"chrome",
"safari",
],
),
"wasm_bindgen_cli": attr.label(
Expand Down
67 changes: 63 additions & 4 deletions extensions/wasm_bindgen/private/wasm_bindgen_test_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,27 @@ use runfiles::{rlocation, Runfiles};

fn write_webdriver_for_browser(
original: &Path,
section: &str,
section: Option<&str>,
args: &Vec<String>,
browser: &Option<PathBuf>,
output: &Path,
) {
// If no section is provided, simply copy the file and early return.
let section = match section {
Some(s) => s,
None => {
fs::copy(original, output).unwrap_or_else(|e| {
panic!(
"Failed to copy webdriver config: {} -> {}\n{:?}",
original.display(),
output.display(),
e
);
});
return;
}
};

let content = fs::read_to_string(original).unwrap_or_else(|e| {
panic!(
"Failed to read webdriver.json at: {}\n{:?}",
Expand Down Expand Up @@ -135,7 +151,7 @@ fn main() {

write_webdriver_for_browser(
&webdriver_json,
"goog:chromeOptions",
Some("goog:chromeOptions"),
&vec![format!("user-data-dir={}", user_data_dir.display())],
&browser,
&updated_webdriver_json,
Expand All @@ -151,7 +167,7 @@ fn main() {

write_webdriver_for_browser(
&webdriver_json,
"moz:firefoxOptions",
Some("moz:firefoxOptions"),
&Vec::new(),
&browser,
&updated_webdriver_json,
Expand All @@ -161,13 +177,56 @@ fn main() {
// and creating an additional one would result in errors.
env.insert("MOZ_DISABLE_CONTENT_SANDBOX".to_string(), "1".to_string());

env.insert("GECKODRIVER_ARGS".to_string(), webdriver_args);
let mut args = Vec::new();

// Define a clean profile root that can be checked at the end of tests.
let profile_root = undeclared_test_outputs.join("profile_root");
fs::create_dir_all(&profile_root).unwrap_or_else(|e| {
panic!(
"Failed to create directory: {}\n{:?}",
profile_root.display(),
e
)
});

// geckodriver directly accepts the profile root arg so it's tracked here
// as there's no way to write this info in a usable way to the `webdriver.json`.
args.push(format!("--profile-root={}", profile_root.display()));

// geckodriver explicitly accepts a browser flag so we pass that in addition
// to setting it in the webdriver.json config.
if let Some(browser) = browser {
args.push(format!("--binary={}", browser.display()));
}

// Ensure logs are always complete.
args.push("--log-no-truncate".to_string());

// Some arguments must be passed to geckodriver directly to ensure it's
// launched in an expected manner
env.insert(
"GECKODRIVER_ARGS".to_string(),
args.join(" ").trim().to_string(),
);
}
"safari" => {
write_webdriver_for_browser(
&webdriver_json,
None,
&Vec::new(),
&browser,
&updated_webdriver_json,
);

env.insert("SAFARIDRIVER_ARGS".to_string(), webdriver_args);
}
_ => {
panic!("Unexpected browser type: {}", browser_type)
}
}

env.insert("RUST_LOG".to_string(), "debug".to_string());

// Run the test
let mut command = Command::new(test_runner);
command.envs(env).arg(test_bin).args(env::args().skip(1));
Expand Down
5 changes: 0 additions & 5 deletions extensions/wasm_bindgen/private/webdrivers/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

exports_files([
"firefox",
"chrome",
])

bzl_library(
name = "bzl_lib",
srcs = glob(["*.bzl"]),
Expand Down
Empty file.
Loading