Skip to content

Commit

Permalink
Use write_source_files for oak_proto_rust copying
Browse files Browse the repository at this point in the history
Change-Id: Iae9925e366f1494f8380ec9ab1bbfc0e31fea593
  • Loading branch information
jblebrun committed Jul 1, 2024
1 parent adeed63 commit 6852bb3
Show file tree
Hide file tree
Showing 15 changed files with 14 additions and 93 deletions.
3 changes: 0 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,6 @@ clang-tidy:
bare_metal_crates_query := "bazel query 'attr(\"tags\", \"ci-build-for-x86_64-unknown-none\", //...)' | tr '\\n' ' '"

bazel-ci:
# Make sure the generated prost files have been copied to the correct place.
bazel run oak_proto_rust:verify_generated

# Test Oak as a dependency in the test workspace
# Some dependencies aren't properly exposed yet, so just testing a subset of targets
cd bazel/test_workspace && CARGO_BAZEL_REPIN=1 bazel build --config=unsafe-fast-presubmit @oak2//micro_rpc @oak2//oak_grpc_utils @oak2//oak_proto_rust
Expand Down
24 changes: 8 additions & 16 deletions oak_proto_rust/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.
#

load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files")
load("@rules_rust//cargo:defs.bzl", "cargo_build_script")
load("@rules_rust//rust:defs.bzl", "rust_library")

Expand Down Expand Up @@ -87,20 +88,11 @@ cargo_build_script(
],
)

sh_binary(
name = "copy_generated",
srcs = [":copy_generated.sh"],
data = [
":build",
":oak_proto_rust",
],
)

sh_binary(
name = "verify_generated",
srcs = [":verify_generated.sh"],
data = [
":build",
":oak_proto_rust",
],
# Prost build tools aren't available internally, so we copy the generated files
# into the source tree for easy import. See README.md for more details.
write_source_files(
name = "copy_generated_files",
files = {
"generated": "//oak_proto_rust:build",
},
)
13 changes: 6 additions & 7 deletions oak_proto_rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ This library is imported into some environments where Prost and/or build scripts
are not available. To support building our Rust targets in these environmnets,
we also include pre-generated Prost Rust code in the `generated` directory.

A presubmit job will run the `oak_proto_rust:verify_generated` target to verify
that all generated code also exists in the `generated` directory.
The bazel `write_source_files` helps us with this. It creates a rule for copying
the generated files, as well as a rule that verifies that they exist in the
right place.

If proto changes are made, you should run:
`bazel run oak_proto_rust:copy_generated_files`

`bazel run oak_proto_rust:copy_generated`

to copy any added/modified files. Not that the script will not cover any
_removed_ files, so take care to clean up any uneeded files if protos are
removed at some point.
If you forget, your presubmit will fail, with a message telling you to run that
command.
23 changes: 0 additions & 23 deletions oak_proto_rust/copy_generated.sh

This file was deleted.

Empty file modified oak_proto_rust/generated/oak.attestation.v1.rs
100755 → 100644
Empty file.
Empty file modified oak_proto_rust/generated/oak.containers.rs
100755 → 100644
Empty file.
Empty file modified oak_proto_rust/generated/oak.crypto.v1.rs
100755 → 100644
Empty file.
Empty file modified oak_proto_rust/generated/oak.functions.abi.rs
100755 → 100644
Empty file.
Empty file modified oak_proto_rust/generated/oak.functions.lookup_data.rs
100755 → 100644
Empty file.
Empty file modified oak_proto_rust/generated/oak.functions.rs
100755 → 100644
Empty file.
Empty file modified oak_proto_rust/generated/oak.functions.testing.rs
100755 → 100644
Empty file.
Empty file modified oak_proto_rust/generated/oak.functions.wasm.v1.rs
100755 → 100644
Empty file.
Empty file modified oak_proto_rust/generated/oak.rs
100755 → 100644
Empty file.
Empty file modified oak_proto_rust/generated/oak.session.v1.rs
100755 → 100644
Empty file.
44 changes: 0 additions & 44 deletions oak_proto_rust/verify_generated.sh

This file was deleted.

0 comments on commit 6852bb3

Please sign in to comment.