| load("@aspect_bazel_lib//lib:output_files.bzl", "output_files") |
| load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_binary") |
| load("@crates//:defs.bzl", "aliases", "all_crate_deps") |
| load("//rust:defs.bzl", "rust_binary", "rust_library", "rust_test", "rustfmt_config") |
| |
| rustfmt_config( |
| name = "enable-rustfmt", |
| ) |
| |
| # We want the release versions of Selenium to include the prebuilt |
| # binaries, but if we're working on Selenium Manager itself, then |
| # `--manager=host` should swap in a local build. |
| # |
| # We tag the compiled versions as `manual` so that when we do a |
| # `bazel build //...` we don't do any additional work |
| |
| SELENIUM_MANAGER_PLATFORMS = [ |
| "linux-arm64", |
| "linux-x86_64", |
| "macos", |
| "windows", |
| ] |
| |
| # musl: Rust's glibc stdlib needs `-lgcc_s`, which @llvm doesn't ship. |
| # gnullvm: @llvm links a PE binary without a Windows SDK. |
| SELENIUM_MANAGER_TRIPLES = { |
| "linux-arm64": "aarch64-unknown-linux-musl", |
| "linux-x86_64": "x86_64-unknown-linux-musl", |
| "macos-arm64": "aarch64-apple-darwin", |
| "macos-x86_64": "x86_64-apple-darwin", |
| "windows": "x86_64-pc-windows-gnullvm", |
| } |
| |
| [ |
| platform_transition_binary( |
| name = "_xc-%s" % target, |
| basename = "selenium-manager.exe" if target == "windows" else "selenium-manager", |
| binary = ":selenium-manager", |
| tags = ["manual"], |
| target_platform = "@rules_rs//rs/platforms:%s" % triple, |
| ) |
| for (target, triple) in SELENIUM_MANAGER_TRIPLES.items() |
| ] |
| |
| # platform_transition_binary also forwards the rust_binary at a colliding path; keep only the wrapper. |
| # Windows hosts can't cross-compile until upstream fixes ship. |
| [ |
| output_files( |
| name = "_xc_file-%s" % target, |
| paths = ["rust/_xc-%s/selenium-manager%s" % ( |
| target, |
| ".exe" if target == "windows" else "", |
| )], |
| tags = ["manual"], |
| target = ":_xc-%s" % target, |
| target_compatible_with = select({ |
| "//common:windows": ["@platforms//:incompatible"], |
| "//conditions:default": [], |
| }), |
| visibility = ["//common/manager:__pkg__"], |
| ) |
| for target in SELENIUM_MANAGER_TRIPLES |
| ] |
| |
| genrule( |
| name = "_xc_file-macos", |
| srcs = [ |
| ":_xc_file-macos-arm64", |
| ":_xc_file-macos-x86_64", |
| ], |
| outs = ["_xc-macos/selenium-manager"], |
| cmd = "$(execpath @llvm//tools:llvm-lipo) -create -output $@ $(execpath :_xc_file-macos-arm64) $(execpath :_xc_file-macos-x86_64)", |
| tags = ["manual"], |
| tools = ["@llvm//tools:llvm-lipo"], |
| visibility = ["//common/manager:__pkg__"], |
| ) |
| |
| [ |
| alias( |
| name = "selenium-manager-%s" % platform, |
| actual = select({ |
| "//common:%s" % platform.replace("-", "_"): ":selenium-manager", |
| "//conditions:default": "@download_sm_%s//file" % platform.replace("-", "_"), |
| }), |
| tags = [ |
| "manual", |
| ], |
| visibility = [ |
| "//common/manager:__pkg__", |
| ], |
| ) |
| for platform in SELENIUM_MANAGER_PLATFORMS |
| ] |
| |
| filegroup( |
| name = "selenium-manager-dev", |
| srcs = [":selenium-manager-%s" % platform for platform in SELENIUM_MANAGER_PLATFORMS], |
| tags = [ |
| "manual", |
| ], |
| visibility = [ |
| "//common/manager:__subpackages__", |
| ], |
| ) |
| |
| alias( |
| name = "rust", |
| actual = ":selenium_manager", |
| visibility = ["//visibility:public"], |
| ) |
| |
| rust_binary( |
| # Yes, this name is very similar to the library. Note the dash |
| # instead of an underscore |
| name = "selenium-manager", |
| srcs = ["src/main.rs"], |
| aliases = aliases(), |
| compile_data = [":selenium_manager_legal"], |
| edition = "2024", |
| # clap's `#[clap(about)]` derives the CLI description from |
| # CARGO_PKG_DESCRIPTION. Cargo sets this from Cargo.toml automatically, but |
| # the Bazel build must supply it explicitly. Keep in sync with rust/Cargo.toml. |
| rustc_env = { |
| "CARGO_PKG_DESCRIPTION": "Selenium Manager is a CLI tool that automatically manages the browser/driver resources required by Selenium.", |
| }, |
| version = "0.4.50-nightly", |
| visibility = ["//visibility:public"], |
| deps = [ |
| ":selenium_manager", |
| ] + all_crate_deps(normal = True), |
| ) |
| |
| filegroup( |
| name = "selenium_manager_legal", |
| srcs = [ |
| "LICENSE", |
| "NOTICE", |
| ], |
| visibility = ["//rust:__subpackages__"], |
| ) |
| |
| rust_library( |
| # The name here is used as the crate name |
| name = "selenium_manager", |
| srcs = glob( |
| ["src/**/*.rs"], |
| exclude = ["main.rs"], |
| ), |
| aliases = aliases(), |
| compile_data = [ |
| "src/resources/rules.md", |
| "src/resources/skills.md", |
| ], |
| crate_features = select({ |
| "//common:stamp": [], |
| "//conditions:default": ["avoid_stats"], |
| }), |
| edition = "2024", |
| visibility = ["//rust:__subpackages__"], |
| deps = all_crate_deps(normal = True), |
| ) |
| |
| filegroup( |
| name = "selenium_manager_srcs", |
| srcs = [ |
| "Cargo.lock", |
| "Cargo.toml", |
| "src/resources/rules.md", |
| "src/resources/skills.md", |
| ":selenium_manager_rs_srcs", |
| ], |
| visibility = ["//visibility:public"], |
| ) |
| |
| filegroup( |
| name = "selenium_manager_rs_srcs", |
| srcs = glob(["src/**/*.rs"]), |
| ) |
| |
| rust_test( |
| name = "unit", |
| size = "small", |
| aliases = aliases(), |
| crate = ":selenium_manager", |
| edition = "2024", |
| tags = ["no-sandbox"], |
| ) |