From d6b5d3b43696ef648a9bfaa362c4b601ad7fe21b Mon Sep 17 00:00:00 2001 From: Steffen Smolka Date: Mon, 27 Oct 2025 22:10:18 -0700 Subject: [PATCH 1/3] Add support for building project with Bazel. --- .cargo/config.toml | 4 +- .github/workflows/bazel.yml | 28 ++++++ .gitignore | 2 + BUILD.bazel | 0 Cargo.lock | 148 ++++++++++------------------- Cargo.toml | 7 +- MODULE.bazel | 26 +++++ book/code/BUILD.bazel | 39 ++++++++ codegen/rust/BUILD.bazel | 15 +++ lang/p4-macro-test/BUILD.bazel | 15 +++ lang/p4-macro/BUILD.bazel | 15 +++ lang/p4rs/BUILD.bazel | 13 +++ lang/prog/sidecar-lite/BUILD.bazel | 17 ++++ p4/BUILD.bazel | 17 ++++ test/BUILD.bazel | 39 ++++++++ test/src/dload.rs | 8 +- x4c/BUILD.bazel | 27 ++++++ x4c_error_codes/BUILD.bazel | 7 ++ 18 files changed, 320 insertions(+), 107 deletions(-) create mode 100644 .github/workflows/bazel.yml create mode 100644 BUILD.bazel create mode 100644 MODULE.bazel create mode 100644 book/code/BUILD.bazel create mode 100644 codegen/rust/BUILD.bazel create mode 100644 lang/p4-macro-test/BUILD.bazel create mode 100644 lang/p4-macro/BUILD.bazel create mode 100644 lang/p4rs/BUILD.bazel create mode 100644 lang/prog/sidecar-lite/BUILD.bazel create mode 100644 p4/BUILD.bazel create mode 100644 test/BUILD.bazel create mode 100644 x4c/BUILD.bazel create mode 100644 x4c_error_codes/BUILD.bazel diff --git a/.cargo/config.toml b/.cargo/config.toml index d587a51f..e4141f91 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,6 +1,6 @@ [net] git-fetch-with-cli = true -# https://github.com/rust-lang/cargo/issues/3946#issuecomment-973132993 [env] -CARGO_WORKSPACE_DIR = { value = "", relative = true } +# Used in tests/src/dload.rs to dynamically load sidecar_lite. +LIBSIDECAR_LITE_DIR = { value = "target/debug", relative = true } diff --git a/.github/workflows/bazel.yml b/.github/workflows/bazel.yml new file mode 100644 index 00000000..757826cd --- /dev/null +++ b/.github/workflows/bazel.yml @@ -0,0 +1,28 @@ +name: Bazel CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + bazel-build-and-test: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + + steps: + - uses: actions/checkout@v4 + - uses: bazel-contrib/setup-bazel@0.15.0 + with: + bazelisk-cache: true + disk-cache: ${{ github.workflow }}-${{ matrix.os }} + repository-cache: true + + - name: Build with Bazel + run: bazel build --test_output=errors //... + + - name: Test with Bazel + run: bazel test --test_output=errors //... diff --git a/.gitignore b/.gitignore index e05bdad3..4ef1e204 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ *.sw* out.rs tags +bazel* +MODULE.bazel.lock diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 00000000..e69de29b diff --git a/Cargo.lock b/Cargo.lock index ed5e1cb3..a45c351a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -198,27 +198,25 @@ dependencies = [ [[package]] name = "dof" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "558e5396321b677a59d2c43b3cc3bc44683109c63ac49275f3bbbf41c0ecd002" +version = "0.4.0" +source = "git+https://github.com/smolkaj/usdt.git#3c6b9729d8f87b48ebfa577ce481cacb82aba2e4" dependencies = [ "goblin", "pretty-hex", "serde", "serde_json", - "thiserror 1.0.69", - "zerocopy 0.7.35", + "thiserror", + "zerocopy", ] [[package]] name = "dtrace-parser" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71734e3eb68cd4df338d04dffdcc024f89eb0b238150cc95b826fbfad756452b" +version = "0.3.0" +source = "git+https://github.com/smolkaj/usdt.git#3c6b9729d8f87b48ebfa577ce481cacb82aba2e4" dependencies = [ "pest", "pest_derive", - "thiserror 1.0.69", + "thiserror", ] [[package]] @@ -273,9 +271,9 @@ checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" [[package]] name = "goblin" -version = "0.8.2" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b363a30c165f666402fe6a3024d3bec7ebc898f96a4a23bd1c99f8dbf3f4f47" +checksum = "51876e3748c4a347fe65b906f2b1ae46a1e55a497b22c94c1f4f2c469ff7673a" dependencies = [ "log", "plain", @@ -344,13 +342,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] -name = "memmap" -version = "0.7.0" +name = "memmap2" +version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" +checksum = "744133e4a0e0a658e1374cf3bf8e415c4052a15a111acd372764c55b4177d490" dependencies = [ "libc", - "winapi", ] [[package]] @@ -497,20 +494,19 @@ dependencies = [ [[package]] name = "pest" -version = "2.8.0" +version = "2.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "198db74531d58c70a361c42201efde7e2591e976d518caf7662a47dc5720e7b6" +checksum = "989e7521a040efde50c3ab6bbadafbe15ab6dc042686926be59ac35d74607df4" dependencies = [ "memchr", - "thiserror 2.0.12", "ucd-trie", ] [[package]] name = "pest_derive" -version = "2.8.0" +version = "2.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d725d9cfd79e87dccc9341a2ef39d1b6f6353d68c4b33c177febbe1a402c97c5" +checksum = "187da9a3030dbafabbbfb20cb323b976dc7b7ce91fcd84f2f74d6e31d378e2de" dependencies = [ "pest", "pest_generator", @@ -518,9 +514,9 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.8.0" +version = "2.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db7d01726be8ab66ab32f9df467ae8b1148906685bbe75c82d1e65d7f5b3f841" +checksum = "49b401d98f5757ebe97a26085998d6c0eecec4995cad6ab7fc30ffdf4b052843" dependencies = [ "pest", "pest_meta", @@ -531,11 +527,10 @@ dependencies = [ [[package]] name = "pest_meta" -version = "2.8.0" +version = "2.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9f832470494906d1fca5329f8ab5791cc60beb230c74815dff541cbd2b5ca0" +checksum = "72f27a2cfee9f9039c4d86faa5af122a0ac3851441a34865b8a043b46be0065a" dependencies = [ - "once_cell", "pest", "sha2", ] @@ -643,7 +638,7 @@ version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" dependencies = [ - "zerocopy 0.8.24", + "zerocopy", ] [[package]] @@ -771,18 +766,18 @@ checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" [[package]] name = "scroll" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ab8598aa408498679922eff7fa985c25d58a90771bd6be794434c5277eab1a6" +checksum = "c1257cd4248b4132760d6524d6dda4e053bc648c9070b960929bf50cfb1e7add" dependencies = [ "scroll_derive", ] [[package]] name = "scroll_derive" -version = "0.12.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f81c2fde025af7e69b1d1420531c8a8811ca898919db177141a85313b1cb932" +checksum = "ed76efe62313ab6610570951494bdaa81568026e0318eaa55f167de70eeea67d" dependencies = [ "proc-macro2", "quote", @@ -921,38 +916,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" -dependencies = [ - "thiserror-impl 1.0.69", -] - -[[package]] -name = "thiserror" -version = "2.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" -dependencies = [ - "thiserror-impl 2.0.12", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.69" +version = "2.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" dependencies = [ - "proc-macro2", - "quote", - "syn", + "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "2.0.12" +version = "2.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" +checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" dependencies = [ "proc-macro2", "quote", @@ -961,12 +936,12 @@ dependencies = [ [[package]] name = "thread-id" -version = "4.2.2" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfe8f25bbdd100db7e1d34acf7fd2dc59c4bf8f7483f505eaa7d4f12f76cc0ea" +checksum = "99043e46c5a15af379c06add30d9c93a6c0e8849de00d244c4a2c417da128d80" dependencies = [ "libc", - "winapi", + "windows-sys", ] [[package]] @@ -989,14 +964,12 @@ checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" [[package]] name = "usdt" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bf5c47fb471a0bff3d7b17a250817bba8c6cc99b0492abaefe5b3bb99045f02" +version = "0.6.0" +source = "git+https://github.com/smolkaj/usdt.git#3c6b9729d8f87b48ebfa577ce481cacb82aba2e4" dependencies = [ "dof", - "dtrace-parser", "goblin", - "memmap", + "memmap2", "serde", "usdt-attr-macro", "usdt-impl", @@ -1005,9 +978,8 @@ dependencies = [ [[package]] name = "usdt-attr-macro" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "025161fff40db24774e7757f75df74ecc47e93d7e11e0f6cdfc31b40eacfe136" +version = "0.6.0" +source = "git+https://github.com/smolkaj/usdt.git#3c6b9729d8f87b48ebfa577ce481cacb82aba2e4" dependencies = [ "dtrace-parser", "proc-macro2", @@ -1019,9 +991,8 @@ dependencies = [ [[package]] name = "usdt-impl" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f925814e5942ebb87af2d9fcf4c3f8665e37903f741eb11f0fa2396c6ef5f7b1" +version = "0.6.0" +source = "git+https://github.com/smolkaj/usdt.git#3c6b9729d8f87b48ebfa577ce481cacb82aba2e4" dependencies = [ "byteorder", "dof", @@ -1032,16 +1003,14 @@ dependencies = [ "serde", "serde_json", "syn", - "thiserror 1.0.69", + "thiserror", "thread-id", - "version_check", ] [[package]] name = "usdt-macro" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ddd86f8f3abac0b7c87f59fe82446fc96a3854a413f176dd2797ed686b7af4c" +version = "0.6.0" +source = "git+https://github.com/smolkaj/usdt.git#3c6b9729d8f87b48ebfa577ce481cacb82aba2e4" dependencies = [ "dtrace-parser", "proc-macro2", @@ -1231,39 +1200,18 @@ source = "git+https://github.com/oxidecomputer/xfr#8a89ee73d039abf91fdddcdd66de6 [[package]] name = "zerocopy" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" -dependencies = [ - "byteorder", - "zerocopy-derive 0.7.35", -] - -[[package]] -name = "zerocopy" -version = "0.8.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2586fea28e186957ef732a5f8b3be2da217d65c5969d4b1e17f973ebbe876879" -dependencies = [ - "zerocopy-derive 0.8.24", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.35" +version = "0.8.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +checksum = "0894878a5fa3edfd6da3f88c4805f4c8558e2b996227a3d864f47fe11e38282c" dependencies = [ - "proc-macro2", - "quote", - "syn", + "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.24" +version = "0.8.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a996a8f63c5c4448cd959ac1bab0aaa3306ccfd060472f85943ee0750f0169be" +checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index a90d3944..1c8eb322 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,5 +37,10 @@ serde = "1.0" serde_tokenstream = "0.2" syn = "2.0" tempfile = "3.3" -usdt = "0.5.0" +usdt = "0.6.0" xfr = { git = "https://github.com/oxidecomputer/xfr" } + +# TODO: Remove this patch once https://github.com/oxidecomputer/usdt/pull/486 is merged. +[patch.crates-io] +usdt = { git = "https://github.com/smolkaj/usdt.git" } +usdt-impl = { git = "https://github.com/smolkaj/usdt.git" } diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 00000000..23336384 --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,26 @@ +module( + name = "x4c", + # Set to version number for releases, only. + version = "HEAD", +) + +bazel_dep(name = "rules_rust", version = "0.67.0") + +# Pick Rust toolchain version. +rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") +rust.toolchain( + # TODO: bump up to 2024 once https://github.com/oxidecomputer/p4/pull/195 + # is merged. + edition = "2021", + versions = ["1.90.0"], +) +use_repo(rust, "rust_toolchains") + +# Make all crates declared in Cargo.toml available as @crates//:... to Bazel. +crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate") +crate.from_cargo( + name = "crates", + cargo_lockfile = "//:Cargo.lock", + manifests = ["//:Cargo.toml"], +) +use_repo(crate, "crates") diff --git a/book/code/BUILD.bazel b/book/code/BUILD.bazel new file mode 100644 index 00000000..c503fbd7 --- /dev/null +++ b/book/code/BUILD.bazel @@ -0,0 +1,39 @@ +load("@rules_rust//rust:defs.bzl", "rust_binary") + +rust_binary( + name = "hello-world", + srcs = ["src/bin/hello-world.rs"], + deps = [ + "//test:tests", + "//lang/p4rs", + "@crates//:num", + "@crates//:bitvec", + "@crates//:pnet", + "@crates//:colored", + "@crates//:usdt", + "@crates//:rand", + "@crates//:anyhow", + "@crates//:xfr", + ], + proc_macro_deps = ["//lang/p4-macro"], + compile_data = glob(["src/**/*.p4"]), +) + +rust_binary( + name = "vlan-switch", + srcs = ["src/bin/vlan-switch.rs"], + deps = [ + "//test:tests", + "//lang/p4rs", + "@crates//:num", + "@crates//:bitvec", + "@crates//:pnet", + "@crates//:colored", + "@crates//:usdt", + "@crates//:rand", + "@crates//:anyhow", + "@crates//:xfr", + ], + proc_macro_deps = ["//lang/p4-macro"], + compile_data = glob(["src/**/*.p4"]), +) diff --git a/codegen/rust/BUILD.bazel b/codegen/rust/BUILD.bazel new file mode 100644 index 00000000..d1ff9b3f --- /dev/null +++ b/codegen/rust/BUILD.bazel @@ -0,0 +1,15 @@ +load("@rules_rust//rust:defs.bzl", "rust_library") + +rust_library( + name = "p4-rust", + srcs = glob(["src/**/*.rs"]), + deps = [ + "//p4", + "@crates//:quote", + "@crates//:proc-macro2", + "@crates//:syn", + "@crates//:prettyplease", + "@crates//:tempfile", + ], + visibility = ["//visibility:public"], +) diff --git a/lang/p4-macro-test/BUILD.bazel b/lang/p4-macro-test/BUILD.bazel new file mode 100644 index 00000000..91436ebe --- /dev/null +++ b/lang/p4-macro-test/BUILD.bazel @@ -0,0 +1,15 @@ +load("@rules_rust//rust:defs.bzl", "rust_binary") + +rust_binary( + name = "p4-macro-test", + srcs = glob(["src/**/*.rs"]), + deps = [ + "//lang/p4rs", + "@crates//:bitvec", + "@crates//:colored", + "@crates//:usdt", + + ], + proc_macro_deps = ["//lang/p4-macro"], + compile_data = glob(["src/**/*.p4"]), +) diff --git a/lang/p4-macro/BUILD.bazel b/lang/p4-macro/BUILD.bazel new file mode 100644 index 00000000..7a296e5f --- /dev/null +++ b/lang/p4-macro/BUILD.bazel @@ -0,0 +1,15 @@ +load("@rules_rust//rust:defs.bzl", "rust_proc_macro") + +rust_proc_macro( + name = "p4-macro", + srcs = glob(["src/**/*.rs"]), + deps = [ + "//p4", + "//codegen/rust:p4-rust", + "@crates//:proc-macro2", + "@crates//:syn", + "@crates//:serde_tokenstream", + "@crates//:serde", + ], + visibility = ["//visibility:public"], +) diff --git a/lang/p4rs/BUILD.bazel b/lang/p4rs/BUILD.bazel new file mode 100644 index 00000000..73e9ee1b --- /dev/null +++ b/lang/p4rs/BUILD.bazel @@ -0,0 +1,13 @@ +load("@rules_rust//rust:defs.bzl", "rust_library") + +rust_library( + name = "p4rs", + srcs = glob(["src/**/*.rs"]), + deps = [ + "@crates//:num", + "@crates//:bitvec", + "@crates//:usdt", + "@crates//:serde", + ], + visibility = ["//visibility:public"], +) diff --git a/lang/prog/sidecar-lite/BUILD.bazel b/lang/prog/sidecar-lite/BUILD.bazel new file mode 100644 index 00000000..1a39e65e --- /dev/null +++ b/lang/prog/sidecar-lite/BUILD.bazel @@ -0,0 +1,17 @@ +load("@rules_rust//rust:defs.bzl", "rust_shared_library") + +rust_shared_library( + name = "sidecar-lite", + srcs = glob(["src/**/*.rs"]), + deps = [ + "//lang/p4rs", + "//codegen/rust:p4-rust", + "@crates//:num", + "@crates//:bitvec", + "@crates//:colored", + "@crates//:usdt", + ], + proc_macro_deps = ["//lang/p4-macro"], + visibility = ["//visibility:public"], + compile_data = ["//test:p4"], +) diff --git a/p4/BUILD.bazel b/p4/BUILD.bazel new file mode 100644 index 00000000..f2789e88 --- /dev/null +++ b/p4/BUILD.bazel @@ -0,0 +1,17 @@ +load("@rules_rust//rust:defs.bzl", "rust_library") + +rust_library( + name = "p4", + srcs = glob(["src/**/*.rs"]), + deps = [ + "@crates//:colored", + "@crates//:regex", + ], + visibility = ["//visibility:public"], +) + +filegroup( + name = "examples", + srcs = glob(["examples/**/*.p4"]), + visibility = ["//visibility:public"], +) diff --git a/test/BUILD.bazel b/test/BUILD.bazel new file mode 100644 index 00000000..0bb3e852 --- /dev/null +++ b/test/BUILD.bazel @@ -0,0 +1,39 @@ +load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") + +rust_library( + name = "tests", + srcs = glob(["src/**/*.rs"]), + deps = [ + "//lang/p4rs", + "@crates//:num", + "@crates//:bitvec", + "@crates//:pnet", + "@crates//:colored", + "@crates//:usdt", + "@crates//:rand", + "@crates//:anyhow", + "@crates//:xfr", + "@crates//:libloading", + ], + proc_macro_deps = ["//lang/p4-macro"], + compile_data = [ + ":p4", + "//p4:examples", + ], + visibility = ["//visibility:public"], +) + +filegroup( + name = "p4", + srcs = glob(["src/**/*.p4"]), + visibility = ["//visibility:public"], +) + +rust_test( + name = "test", + crate = ":tests", + # Needed so the library can be loaded dynamically at runtime, see dload.rs. + data = ["//lang/prog/sidecar-lite:sidecar-lite"], + # Used in dload.rs to dynamically load sidecar_lite. + env = {"LIBSIDECAR_LITE_DIR": "lang/prog/sidecar-lite"}, +) diff --git a/test/src/dload.rs b/test/src/dload.rs index ff938a78..ba786f4b 100644 --- a/test/src/dload.rs +++ b/test/src/dload.rs @@ -25,12 +25,12 @@ use p4rs::packet_in; #[test] fn dynamic_load() -> Result<(), anyhow::Error> { - // see .cargo/config.toml - let ws = std::env::var("CARGO_WORKSPACE_DIR").unwrap(); + // Defined in .cargo/config.toml (Cargo) / test/BUILD.bazel (Bazel). + let ws = std::env::var("LIBSIDECAR_LITE_DIR").unwrap(); #[cfg(target_os = "macos")] - let path = format!("{}/target/debug/libsidecar_lite.dylib", ws); + let path = format!("{}/libsidecar_lite.dylib", ws); #[cfg(not(target_os = "macos"))] - let path = format!("{}/target/debug/libsidecar_lite.so", ws); + let path = format!("{}/libsidecar_lite.so", ws); let lib = match unsafe { libloading::Library::new(path) } { Ok(l) => l, diff --git a/x4c/BUILD.bazel b/x4c/BUILD.bazel new file mode 100644 index 00000000..2fefe4fd --- /dev/null +++ b/x4c/BUILD.bazel @@ -0,0 +1,27 @@ +load("@rules_rust//rust:defs.bzl", "rust_library", "rust_binary") + +rust_library( + name = "lib", + srcs = ["src/lib.rs"], + crate_name = "x4c", + deps = [ + "//p4", + "@crates//:colored", + "@crates//:clap", + "@crates//:anyhow", + "@crates//:regex", + ], + visibility = ["//visibility:public"], +) + +rust_binary( + name = "x4c", + srcs = ["src/bin/x4c.rs"], + deps = [ + ":lib", + "//p4", + "//codegen/rust:p4-rust", + "@crates//:anyhow", + "@crates//:clap", + ], +) diff --git a/x4c_error_codes/BUILD.bazel b/x4c_error_codes/BUILD.bazel new file mode 100644 index 00000000..ffbe91df --- /dev/null +++ b/x4c_error_codes/BUILD.bazel @@ -0,0 +1,7 @@ +load("@rules_rust//rust:defs.bzl", "rust_library") + +rust_library( + name = "x4c_error_codes", + srcs = glob(["src/**/*.rs"]), + visibility = ["//visibility:public"], +) From 9a2985d384332dee2d5adf9d325c83168cf98297 Mon Sep 17 00:00:00 2001 From: Steffen Smolka Date: Mon, 3 Nov 2025 18:21:27 -0800 Subject: [PATCH 2/3] Remove/update TODOs. --- Cargo.lock | 12 ++++++------ Cargo.toml | 7 +++---- MODULE.bazel | 2 -- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a45c351a..298d2de4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -199,7 +199,7 @@ dependencies = [ [[package]] name = "dof" version = "0.4.0" -source = "git+https://github.com/smolkaj/usdt.git#3c6b9729d8f87b48ebfa577ce481cacb82aba2e4" +source = "git+https://github.com/oxidecomputer/usdt#4329591597b3ceaab78d606cf601781c6a99e6de" dependencies = [ "goblin", "pretty-hex", @@ -212,7 +212,7 @@ dependencies = [ [[package]] name = "dtrace-parser" version = "0.3.0" -source = "git+https://github.com/smolkaj/usdt.git#3c6b9729d8f87b48ebfa577ce481cacb82aba2e4" +source = "git+https://github.com/oxidecomputer/usdt#4329591597b3ceaab78d606cf601781c6a99e6de" dependencies = [ "pest", "pest_derive", @@ -965,7 +965,7 @@ checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" [[package]] name = "usdt" version = "0.6.0" -source = "git+https://github.com/smolkaj/usdt.git#3c6b9729d8f87b48ebfa577ce481cacb82aba2e4" +source = "git+https://github.com/oxidecomputer/usdt#4329591597b3ceaab78d606cf601781c6a99e6de" dependencies = [ "dof", "goblin", @@ -979,7 +979,7 @@ dependencies = [ [[package]] name = "usdt-attr-macro" version = "0.6.0" -source = "git+https://github.com/smolkaj/usdt.git#3c6b9729d8f87b48ebfa577ce481cacb82aba2e4" +source = "git+https://github.com/oxidecomputer/usdt#4329591597b3ceaab78d606cf601781c6a99e6de" dependencies = [ "dtrace-parser", "proc-macro2", @@ -992,7 +992,7 @@ dependencies = [ [[package]] name = "usdt-impl" version = "0.6.0" -source = "git+https://github.com/smolkaj/usdt.git#3c6b9729d8f87b48ebfa577ce481cacb82aba2e4" +source = "git+https://github.com/oxidecomputer/usdt#4329591597b3ceaab78d606cf601781c6a99e6de" dependencies = [ "byteorder", "dof", @@ -1010,7 +1010,7 @@ dependencies = [ [[package]] name = "usdt-macro" version = "0.6.0" -source = "git+https://github.com/smolkaj/usdt.git#3c6b9729d8f87b48ebfa577ce481cacb82aba2e4" +source = "git+https://github.com/oxidecomputer/usdt#4329591597b3ceaab78d606cf601781c6a99e6de" dependencies = [ "dtrace-parser", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index 1c8eb322..820507b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,10 +37,9 @@ serde = "1.0" serde_tokenstream = "0.2" syn = "2.0" tempfile = "3.3" -usdt = "0.6.0" +usdt = "0.6" xfr = { git = "https://github.com/oxidecomputer/xfr" } -# TODO: Remove this patch once https://github.com/oxidecomputer/usdt/pull/486 is merged. +# TODO: Remove once https://github.com/oxidecomputer/usdt/pull/486 is released. [patch.crates-io] -usdt = { git = "https://github.com/smolkaj/usdt.git" } -usdt-impl = { git = "https://github.com/smolkaj/usdt.git" } +usdt = { git = "https://github.com/oxidecomputer/usdt" } diff --git a/MODULE.bazel b/MODULE.bazel index 23336384..9bbd7092 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -9,8 +9,6 @@ bazel_dep(name = "rules_rust", version = "0.67.0") # Pick Rust toolchain version. rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") rust.toolchain( - # TODO: bump up to 2024 once https://github.com/oxidecomputer/p4/pull/195 - # is merged. edition = "2021", versions = ["1.90.0"], ) From 6b6bef70720296e7b5e0e400a9cf14f24af0a8b9 Mon Sep 17 00:00:00 2001 From: Steffen Smolka Date: Mon, 3 Nov 2025 18:30:46 -0800 Subject: [PATCH 3/3] Fix Github Action --- .github/workflows/bazel.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/bazel.yml b/.github/workflows/bazel.yml index 757826cd..42dcdb13 100644 --- a/.github/workflows/bazel.yml +++ b/.github/workflows/bazel.yml @@ -14,15 +14,17 @@ jobs: os: [ubuntu-latest, macos-latest] steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 - uses: bazel-contrib/setup-bazel@0.15.0 with: bazelisk-cache: true disk-cache: ${{ github.workflow }}-${{ matrix.os }} repository-cache: true - + - if: matrix.os == 'ubuntu-latest' + run: | + sudo apt-get install -y lld + sudo update-alternatives --install /usr/bin/ld ld /usr/bin/ld.lld 100 - name: Build with Bazel run: bazel build --test_output=errors //... - - name: Test with Bazel run: bazel test --test_output=errors //...