Skip to content

WIP: Bazel all the things#1591

Draft
dzbarsky wants to merge 1 commit into
aya-rs:mainfrom
dzbarsky:main
Draft

WIP: Bazel all the things#1591
dzbarsky wants to merge 1 commit into
aya-rs:mainfrom
dzbarsky:main

Conversation

@dzbarsky

@dzbarsky dzbarsky commented May 30, 2026

Copy link
Copy Markdown

This PR converts the repo to building with Bazel. It does not yet add CI jobs. This is WIP for collaborating with @tamird .

Added/updated tests?

Tests added, to be enabled in CI

Checklist

  • Rust code has been formatted with cargo +nightly fmt.
  • All clippy lints have been fixed.
    You can find failing lints with cargo xtask clippy.
  • Unit tests are passing locally with cargo test.
  • The Integration tests are passing locally.
  • I have blessed any API changes with cargo xtask public-api --bless.

(Optional) What GIF best describes this PR or how it makes you feel?

image

This change is Reviewable

@netlify

netlify Bot commented May 30, 2026

Copy link
Copy Markdown

Deploy Preview for aya-rs-docs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 1356d15
🔍 Latest deploy log https://app.netlify.com/projects/aya-rs-docs/deploys/6a1b467a23e88e000844e14e
😎 Deploy Preview https://deploy-preview-1591--aya-rs-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.


aya_rust_crate(
name = "aya-ebpf-macros",
proc_macro = True,

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right now there's a bit of a "sniff for ebpf in the name" logic in the macro. should we just do a ebpf = True macro param instead?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that seems better yeah

],
)
+
+source_stdlib(

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: upstream to rules_rs in some form

Comment thread bazel/vm.bzl
out = ctx.outputs.initrd
manifest = ctx.actions.declare_file(ctx.label.name + ".cpio.list")

lines = [

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: upstream initramfs builder to linux.bzl

Comment thread bazel/vm.bzl
# --- end runfiles.bash initialization v3 ---
set -euo pipefail

runfile() {{

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: can we just use rootpath instead of runfiles for tests?

Comment thread test-distro/src/init.rs
use anyhow::Context as _;

#[cfg(target_os = "linux")]
fn set_loopback_up() -> anyhow::Result<()> {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i believe the previous kernel/distro setup we were using gave us the loopback "for free", now we do it manually

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it does not - we shouldn't depend on loopback being up, can you elaborate on what happens if this file is reverted?

Comment thread test-distro/src/init.rs
target_mode: Some(RXRXRX),
},
Mount {
source: "debugfs",

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure why these changes are needed, perhaps another difference with the previous debian setup

Comment thread bazel/defs.bzl
)

def _c_bpf_compile(ctx, cc_toolchain, feature_configuration, name, defines = []):
_, compilation_outputs = cc_common.compile(

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was pretty happy with how this bit turned out :)

@vadorovsky vadorovsky left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to have some explanation why do we want this and who would use it.

Comment thread .gitignore
@@ -1,5 +1,6 @@
Cargo.lock

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I overall agree with this (Aya is a set of library crates), but I think that deserves a separate commit with an explanation.

@dzbarsky

dzbarsky commented May 30, 2026

Copy link
Copy Markdown
Author

Would be nice to have some explanation why do we want this and who would use it.

Will let @tamird take this one since he asked for help with this work :) But at a high level - typically projects use Bazel when they want very reproducible, very fast builds that can parallelize their actions across remote executors. For example I can run the e2e tests in around 4 minutes, which involves building all crates and linux kernel from source, spawning the VMs, and running the tests. Looks like it takes closer to 20 minutes in Github actions :)

@vadorovsky

vadorovsky commented Jun 1, 2026

Copy link
Copy Markdown
Member

Would be nice to have some explanation why do we want this and who would use it.

Will let @tamird take this one since he asked for help with this work :) But at a high level - typically projects use Bazel when they want very reproducible, very fast builds that can parallelize their actions across remote executors. For example I can run the e2e tests in around 4 minutes, which involves building all crates and linux kernel from source, spawning the VMs, and running the tests. Looks like it takes closer to 20 minutes in Github actions :)

Got it, sounds cool. Could you please list some of these reasons in the pull request and commit message?

I know nothing about Bazel, but I noticed that there is https://github.com/hermeticbuild/hermetic-llvm that caught my interest. We are doing some heavy cross-compilation stuff in https://github.com/aya-rs/bpf-linker (we build LLVM for different architectures and with musl), do you think it could benefit from the hermetic LLVM builds?

@dzbarsky

dzbarsky commented Jun 1, 2026

Copy link
Copy Markdown
Author

Would be nice to have some explanation why do we want this and who would use it.

Will let @tamird take this one since he asked for help with this work :) But at a high level - typically projects use Bazel when they want very reproducible, very fast builds that can parallelize their actions across remote executors. For example I can run the e2e tests in around 4 minutes, which involves building all crates and linux kernel from source, spawning the VMs, and running the tests. Looks like it takes closer to 20 minutes in Github actions :)

Got it, sounds cool. Could you please list some of these reasons in the pull request and commit message?

Sure, will do before landing. Both the message and PR are still very WIP!

I know nothing about Bazel, but I noticed that there is https://github.com/hermeticbuild/hermetic-llvm that caught my interest. We are doing some heavy cross-compilation stuff in https://github.com/aya-rs/bpf-linker (we build LLVM for different architectures and with musl), do you think it could benefit from the hermetic LLVM builds?

Yes! I'm actually one of the maintainers of hermetic-llvm project :) I only looked at bpf-linker briefly but am fairly confident if we just need to build some rust code and link against LLVM with some patches, hermetic-llvm likely should work out of the box and give ability to compile for all targets (including missing ones like windows!).

@tamird tamird requested a review from vadorovsky June 1, 2026 15:39

@tamird tamird left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice work here. What do I need to do to get this running in CI so we can look at the results?

@tamird reviewed 6 files and made 10 comments.
Reviewable status: 6 of 39 files reviewed, 15 unresolved discussions (waiting on dzbarsky and vadorovsky).


BUILD.bazel at r1 (raw file):
What does this empty file do?


Cargo.lock line 1 at r1 (raw file):

# This file is automatically @generated by Cargo.

this file needs a mention in the commit message and a CI staleness check


.bazelrc line 1 at r1 (raw file):

common --enable_platform_specific_config

this file needs some comments :)


test/kernel/README.md line 1 at r1 (raw file):

# Bazel Kernel Inputs

very nice. note that the current setup is undergoing some change in #1588 so it would be better to rewrite this without referencing the existing machinery.


test/kernel/aya_aarch64.config line 1 at r1 (raw file):

# Minimal allnoconfig-based aarch64 kernel for Aya integration VMs.

for both of these files it would be great to encode which configs are direct dependencies and which are transitive (or otherwise have a reproducible way to regenerate these)


MODULE.bazel.lock line 1 at r1 (raw file):

{

needs CI staleness check


MODULE.bazel line 1 at r1 (raw file):

module(

we need some maintenance instructions for this file + inline commentary for things that aren't obvious like the overrides


aya_rust_crate(
name = "aya-ebpf-macros",
proc_macro = True,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that seems better yeah

Comment thread test-distro/src/init.rs
use anyhow::Context as _;

#[cfg(target_os = "linux")]
fn set_loopback_up() -> anyhow::Result<()> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it does not - we shouldn't depend on loopback being up, can you elaborate on what happens if this file is reverted?

@swananan swananan mentioned this pull request Jun 2, 2026
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants