Replies: 1 comment 1 reply
-
I don't see a strong motivation here. Rules author would then have to worry about (a) producing a wasm artifact and (b) store/distribute that wasm artifact vs just writing the current starlark rules and leveraging Github/BCR archive ecosystem. The sandboxing argument is also not that appealing to me either. What problem would "having a hermetic sandbox for rctx" solve? |
Beta Was this translation helpful? Give feedback.
-
I originally filed this as an issue at #22483, but it might be better as a discussion until some rough consensus can be reached.
The basic problem I want to address is the use of complex language-specific BUILD file generators in rulesets. Currently these tools need to execute on the host, which means a native binary for the host platform must either (1) exist as a pre-compiled download, or (2) be built as part of repository rule execution. Both approaches have significant drawbacks:
rules_rust
ruleset provides thecargo-bazel
tool compiled for Linux, macOS, and Windows on x86-64 and aarch64 -- while this does cover most users, it means that I can't easily test the Bazel builds for my Rust projects on FreeBSD or RISC-V.-gnu
vs-musl
on Linux).gazelle
binaries provided a significant improvement in CI performance but made the process of updating rules_go much more difficult.Over the past few years, support for WASM as both a compilation target and embedded interpreter has become widespread. Many languages (including Rust and Go) can be compiled to standalone WASM binaries, and the Chicory runtime implements a WASM interpreter in Java with no native code dependencies.
If it were possible to execute a WASM binary within a repository rule, then ruleset authors could provide a single pre-compiled
.wasm
file and Bazel could execute it on every platform with identical behavior and full sandboxing. The API does not need to be complex -- since Bazel can handle the file I/O using existingrepository_ctx
functions, the WASM blob only needs to provide pure functions and the API can be written in terms of plain byte buffers.I've put together a proof-of-concept to verify that this does in fact work as expected, using WASM modules written in Rust and Go (modified from existing ruleset tools). The resulting repository rules work without modification on all the host platforms I have tried, and they no longer need to execute
uname
or poke around in/lib
to detect host properties.Beta Was this translation helpful? Give feedback.
All reactions