Skip to content

Commit d6b5d3b

Browse files
committed
Add support for building project with Bazel.
1 parent eda6902 commit d6b5d3b

File tree

18 files changed

+320
-107
lines changed

18 files changed

+320
-107
lines changed

.cargo/config.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[net]
22
git-fetch-with-cli = true
33

4-
# https://github.com/rust-lang/cargo/issues/3946#issuecomment-973132993
54
[env]
6-
CARGO_WORKSPACE_DIR = { value = "", relative = true }
5+
# Used in tests/src/dload.rs to dynamically load sidecar_lite.
6+
LIBSIDECAR_LITE_DIR = { value = "target/debug", relative = true }

.github/workflows/bazel.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Bazel CI
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
bazel-build-and-test:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
os: [ubuntu-latest, macos-latest]
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: bazel-contrib/setup-bazel@0.15.0
19+
with:
20+
bazelisk-cache: true
21+
disk-cache: ${{ github.workflow }}-${{ matrix.os }}
22+
repository-cache: true
23+
24+
- name: Build with Bazel
25+
run: bazel build --test_output=errors //...
26+
27+
- name: Test with Bazel
28+
run: bazel test --test_output=errors //...

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
*.sw*
33
out.rs
44
tags
5+
bazel*
6+
MODULE.bazel.lock

BUILD.bazel

Whitespace-only changes.

Cargo.lock

Lines changed: 48 additions & 100 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,10 @@ serde = "1.0"
3737
serde_tokenstream = "0.2"
3838
syn = "2.0"
3939
tempfile = "3.3"
40-
usdt = "0.5.0"
40+
usdt = "0.6.0"
4141
xfr = { git = "https://github.com/oxidecomputer/xfr" }
42+
43+
# TODO: Remove this patch once https://github.com/oxidecomputer/usdt/pull/486 is merged.
44+
[patch.crates-io]
45+
usdt = { git = "https://github.com/smolkaj/usdt.git" }
46+
usdt-impl = { git = "https://github.com/smolkaj/usdt.git" }

MODULE.bazel

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module(
2+
name = "x4c",
3+
# Set to version number for releases, only.
4+
version = "HEAD",
5+
)
6+
7+
bazel_dep(name = "rules_rust", version = "0.67.0")
8+
9+
# Pick Rust toolchain version.
10+
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
11+
rust.toolchain(
12+
# TODO: bump up to 2024 once https://github.com/oxidecomputer/p4/pull/195
13+
# is merged.
14+
edition = "2021",
15+
versions = ["1.90.0"],
16+
)
17+
use_repo(rust, "rust_toolchains")
18+
19+
# Make all crates declared in Cargo.toml available as @crates//:... to Bazel.
20+
crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
21+
crate.from_cargo(
22+
name = "crates",
23+
cargo_lockfile = "//:Cargo.lock",
24+
manifests = ["//:Cargo.toml"],
25+
)
26+
use_repo(crate, "crates")

0 commit comments

Comments
 (0)