Repository navigation
Build with Bazel (bzlmod) alongside Cargo - #12
Conversation
Adds a bzlmod build covering the whole repo: the Rust workspace via rules_rs, and the Flutter plugin and its example via the rules_flutter fork. The Cargo workflow is unchanged and still the path that ships the Android .so through the Gradle shim. Rust targets are razemify-core (three feature variants: bare for wasm, rembg for the CLI, flutter_ffi for the plugin), razemify-cli, razemify-wasm, xtask, and the plugin's host shared/static libs. ONNX Runtime is fetched as a pinned http_archive per platform and handed to the CLI at runtime through ORT_DYLIB_PATH. razemify-core enables ort's load-dynamic, which turns on ort-sys/disable-linking, so nothing links against it at build time and its build script is skipped. The pinned version tracks what the resolved ort-sys declares in its dist.tsv -- 1.28.0 for ort 2.0.0-rc.13 -- and must be re-derived whenever ort moves. third_party/wasm_bindgen pins the wasm-bindgen CLI at the same version as the wasm-bindgen crate and registers its toolchain ahead of the one bundled with rules_rs. The bindgen schema versions must match exactly, and the bundled CLI (0.2.105) trails the crate (0.2.126). BuildBuddy provides the remote cache and build event stream on every build; remote execution is opt-in via --config=remote. The RBE platform pins BuildBuddy's stock Ubuntu 20.04 image because the default executor image's glibc predates 2.28, which binaries from the hermetic llvm and Rust toolchains require. Credentials stay out of the repo: .bazelrc try-imports a gitignored user.bazelrc (see user.bazelrc.example). Dependencies move to current versions -- Bazel 9.2.0, Rust 1.97.1, Flutter 3.44.7, cargo update across the workspace, and pub upgrades -- which required a few source fixes: two dead Dart imports and a library name that flutter_lints 6.0 now flags, and a clippy lint that CI's -D warnings rejects under Rust 1.97. The example's pubspec.lock is dropped and its widget test rewritten. The lock pinned transitive versions that conflicted with the plugin's own resolution, and pub_deps.json is the pinned record for the Bazel build; the test was still the generated plugin template asserting text the app never renders, so it failed independently of this change.
Runs bazel build and test on top of the existing Cargo jobs, which is what covers the Flutter analyze/format gates and the example widget test. MODULE.bazel reaches the rules_flutter fork through local_path_override at a path outside $GITHUB_WORKSPACE, where actions/checkout cannot write, so the fork is cloned there directly. RULES_FLUTTER_REF pins the fork branch carrying the path-dependency and engine-version fixes; point it at main once that merges, and delete the arrangement entirely if MODULE.bazel moves to git_override. Without a BUILDBUDDY_API_KEY secret -- pull requests from forks never get one -- the job writes a user.bazelrc that switches the remote cache and BES off, rather than leaving them to fail against BuildBuddy anonymously.
The WASM Build Check job fails in wasm-opt: [wasm-validator error in function 7936] unexpected false: Bulk memory operations require bulk memory [--enable-bulk-memory] Fatal: error validating input rustc enables bulk-memory, nontrapping-fptoint, multivalue, reference-types and sign-ext by default for wasm32-unknown-unknown, while the wasm-opt that wasm-pack downloads validates with every feature off and rejects the input. This is toolchain drift rather than fallout from the dependency bump: the enabled features come from rustc alone, and the failure reproduces identically against main's untouched Cargo.lock. The job pins no Rust version -- it uses dtolnay/rust-toolchain@stable -- so it broke whenever stable crossed the release enabling these, and main last ran in February. Allow exactly the features rustc emits instead of setting wasm-opt = false, which would keep the build green only by giving up the size optimization this crate wants. Verified with wasm-pack 0.15.0 and Rust 1.97.1: the build completes and wasm-opt takes the module down to 2.5 MB.
The Bazel job used BuildBuddy only as a cache; --config=remote was never exercised there, so remote execution was verified locally and nowhere else. --noremote_accept_cached is the substance of the check. Without it a warm cache serves nearly every action -- a plain --config=remote run here reported 2 remote actions against 2364 cache hits -- and passing proves nothing about whether remote execution works. Refusing cached results forces the actions to actually run on BuildBuddy. The step then asserts on the "N remote" figure in Bazel's process breakdown rather than on the exit code, because a build served entirely from cache also exits 0. The pattern deliberately does not match "remote cache hit", so a cache-only run fails the check instead of passing it. Rust targets only: rules_flutter tags its host-bound actions no-remote-exec, so the Flutter targets stay local by design. The step skips when no API key is present, since pull requests from forks get no secrets.
local_path_override required the fork to sit at ../../rules_flutter/main on every machine that builds this repo, and it silently picked up whatever was in that working tree -- uncommitted edits included -- so no two checkouts were guaranteed to build the same thing. git_override pins the fork by commit, which makes the build reproducible and removes the path requirement entirely. The fixes this repo needs (the Flutter 3.44 engine-version patch and path-dependency staging) are now on the fork's main, so the pinned commit carries them. This also deletes the CI step that cloned the fork to a path outside $GITHUB_WORKSPACE, which only existed to satisfy local_path_override. Verified from a cold bazel clean --expunge: all four tests pass, and the fetched copy matches the pinned commit rather than the local checkout -- the local working tree has uncommitted changes to flutter/defs.bzl that are absent from what Bazel fetched. To develop the ruleset itself, swap local_path_override back in.
CI ran two toolchains side by side: a Bazel job plus five cargo jobs that
installed rustup and wasm-pack. Everything the cargo jobs checked now has a
Bazel equivalent, so ci.yml goes away:
cargo fmt --all --check -> //:rustfmt
cargo clippy -D warnings -> //:clippy
cargo test --workspace -> //razemify-core:razemify_core{,_rembg}_test
cargo build --workspace -> bazel build //...
wasm-pack build -> //razemify-wasm:razemify_wasm
rules_rs wraps the rules_rust build rules but does not re-export its
rustfmt/clippy aspects, so MODULE.bazel pulls the same pinned rules_rust
repo in directly. .bazelrc sets clippy_flag=-Dwarnings, without which
//:clippy reports lints and still succeeds -- verified by reintroducing the
unnecessary_sort_by lint and confirming the gate fails, then reverting.
razemify_core_rembg_test is new: the existing test target covered only the
feature-less build, while cargo test --workspace exercises the rembg one
too, since razemify-cli turns that feature on.
The repository cache is cached across runs because it holds the fetched
archives -- Flutter SDK, Rust toolchains, ONNX Runtime, every crate -- that
the BuildBuddy action cache cannot cover: repository rules run outside the
action graph, so their downloads repeat on every cold runner. Keyed on
MODULE.bazel.lock, which pins exactly what gets fetched.
Note this drops CI coverage of the cargo and wasm-pack paths themselves,
which still ship: Gradle builds the Android .so through cargo, and xtask
still bundles releases with wasm-pack.
It was the most expensive step in the job at 142s, because --noremote_accept_cached deliberately refuses the remote cache that makes every other step fast. Remote execution is opt-in via --config=remote and is not what CI builds with, so paying that on every run bought little. --config=remote is untouched in .bazelrc and still works on demand.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f3e6ba49b1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c1870dcc15
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5b43b09f67
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Adds a bzlmod build covering the whole repo — the Rust workspace via rules_rs, and the Flutter plugin and example via the rules_flutter fork. The Cargo workflow is untouched and still the path that ships the Android
.sothrough the Gradle shim.The two ruleset fixes this needs landed in pawelchcki/rules_flutter#1;
MODULE.bazelpins the fork by commit viagit_override, so no sibling checkout is required.What is built
Rust:
razemify-corein three feature variants (bare for wasm,rembgfor the CLI,flutter_ffifor the plugin),razemify-cli,razemify-wasm,xtask, and the plugin's host shared/static libs. Flutter: the plugin withflutter_analyze_test+dart_format_test, and the example with its widget test. No APK — Gradle still owns that, along with the Android.so.Things worth reviewing
ONNX Runtime is not vendored or linked.
razemify-coreenables ort'sload-dynamic, which turns onort-sys/disable-linking, so nothing links against it at build time and its build script is skipped entirely. The library is fetched as a pinned per-platformhttp_archiveand handed to the CLI at runtime viaORT_DYLIB_PATH. The pinned version tracks what the resolvedort-sysdeclares in itsbuild/download/dist.tsv— 1.28.0 for ort 2.0.0-rc.13 — so it must be re-derived whenever ort moves, not assumed.third_party/wasm_bindgenexists because bindgen schema versions must match exactly. rules_rs bundles a 0.2.105 CLI while the workspace links wasm-bindgen 0.2.126, which fails with a schema-version mismatch. This pins a matching CLI and registers its toolchain ahead of the bundled one. Keep itsCargo.tomlin lockstep with the workspace's wasm-bindgen version.The RBE platform pins BuildBuddy's stock Ubuntu 20.04 image. The default executor image's glibc predates 2.28, which binaries from the hermetic llvm and Rust toolchains require, so
--config=remotedied withGLIBC_2.28 not foundon every remote Rust action. This is a stock published image, not a custom one.The example's
pubspec.lockis deleted. It pinned transitive versions that conflicted with the plugin's own resolution (async 2.11.0 vs 2.13.1), which the pub extension rejects as a hard error.pub_deps.jsonis the pinned record for the Bazel build, andflutter pub getregenerates the lock for the Gradle path.Source fixes the dependency bumps forced. Two dead Dart imports and a library name that flutter_lints 6.0 flags; a
clippy::unnecessary_sort_bythat CI's-D warningsrejects under Rust 1.97 (pre-existing — confirmed by stashing). The example's widget test was still the generated plugin template asserting'Running on:'text the app never renders, so it failed independently of this change and is rewritten as a real smoke test.Verification
From a cold
bazel clean --expunge, so every hash, download, and toolchain was re-fetched:bazel build //...— 3572 actions, cleanbazel test //...with--nocache_test_resultsso all 4 tests genuinely execute rather than reporting(cached)--noremote_accept_cachedto force real work rather than cache replay: 1736 of 2512 actions executed on BuildBuddy. Under--config=remotethe Flutter targets correctly stay local, per the ruleset'sno-remote-exectaggingORT_DYLIB_PATHend to end{ initSync, __wbg_init as default }— the exactwasm-pack --target webshapecargo check/fmt/clippy -D warningsall clean, and the tree builds against a clean clone of the fork branch, which is the configuration CI usesFollow-ups
.so-c optis not Cargo'sopt-level=z + lto; add rustc flags if wasm size parity matters (5.1 MB opt vs 17 MB fastbuild today)BUILDBUDDY_API_KEYsecret to use the remote cache; without it the job builds with remote disabled rather than failing