diff --git a/justfile b/justfile index 2b9b9b7ac86..11abfe152b0 100644 --- a/justfile +++ b/justfile @@ -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 diff --git a/oak_proto_rust/BUILD b/oak_proto_rust/BUILD index 3628f36eff6..945b0a7cfdb 100644 --- a/oak_proto_rust/BUILD +++ b/oak_proto_rust/BUILD @@ -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") @@ -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", + }, ) diff --git a/oak_proto_rust/README.md b/oak_proto_rust/README.md index 207375b9556..d9a51bb6338 100644 --- a/oak_proto_rust/README.md +++ b/oak_proto_rust/README.md @@ -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. diff --git a/oak_proto_rust/copy_generated.sh b/oak_proto_rust/copy_generated.sh deleted file mode 100755 index aa89fe3f5df..00000000000 --- a/oak_proto_rust/copy_generated.sh +++ /dev/null @@ -1,23 +0,0 @@ -set -o xtrace - -echo "Copy generated files" - -BUILD_SCRIPT_GENERATED_FILES=../../build.out_dir -IMPORTABLE_GENERATED_FILE_DEST=../../../../../../oak_proto_rust/generated - -if [ ! -d $BUILD_SCRIPT_GENERATED_FILES ] -then - set +o xtrace - echo "The expected bazel workspace directory wasn't found." - echo "Make sure you run this script via bazel:" - echo "bazel run oak_proto_rust:copy_generated" - exit 1 -fi - -ls -la $BUILD_SCRIPT_GENERATED_FILES - -cp "$BUILD_SCRIPT_GENERATED_FILES"/*.rs $IMPORTABLE_GENERATED_FILE_DEST - -ls $IMPORTABLE_GENERATED_FILE_DEST - -chmod --recursive u+w "$IMPORTABLE_GENERATED_FILE_DEST" diff --git a/oak_proto_rust/generated/oak.attestation.v1.rs b/oak_proto_rust/generated/oak.attestation.v1.rs old mode 100755 new mode 100644 diff --git a/oak_proto_rust/generated/oak.containers.rs b/oak_proto_rust/generated/oak.containers.rs old mode 100755 new mode 100644 diff --git a/oak_proto_rust/generated/oak.crypto.v1.rs b/oak_proto_rust/generated/oak.crypto.v1.rs old mode 100755 new mode 100644 diff --git a/oak_proto_rust/generated/oak.functions.abi.rs b/oak_proto_rust/generated/oak.functions.abi.rs old mode 100755 new mode 100644 diff --git a/oak_proto_rust/generated/oak.functions.lookup_data.rs b/oak_proto_rust/generated/oak.functions.lookup_data.rs old mode 100755 new mode 100644 diff --git a/oak_proto_rust/generated/oak.functions.rs b/oak_proto_rust/generated/oak.functions.rs old mode 100755 new mode 100644 diff --git a/oak_proto_rust/generated/oak.functions.testing.rs b/oak_proto_rust/generated/oak.functions.testing.rs old mode 100755 new mode 100644 diff --git a/oak_proto_rust/generated/oak.functions.wasm.v1.rs b/oak_proto_rust/generated/oak.functions.wasm.v1.rs old mode 100755 new mode 100644 diff --git a/oak_proto_rust/generated/oak.rs b/oak_proto_rust/generated/oak.rs old mode 100755 new mode 100644 diff --git a/oak_proto_rust/generated/oak.session.v1.rs b/oak_proto_rust/generated/oak.session.v1.rs old mode 100755 new mode 100644 diff --git a/oak_proto_rust/verify_generated.sh b/oak_proto_rust/verify_generated.sh deleted file mode 100755 index fca3ae8e5f6..00000000000 --- a/oak_proto_rust/verify_generated.sh +++ /dev/null @@ -1,44 +0,0 @@ -set -o xtrace - -echo "Verify generated files" - -echo "FILES:" -ls -la -echo "" - -BUILD_SCRIPT_GENERATED_FILES=../../build.out_dir -IMPORTABLE_GENERATED_FILE_DEST=../../../../../../oak_proto_rust/generated - -echo "BSD:" -ls $BUILD_SCRIPT_GENERATED_FILES - -if [ ! -d $BUILD_SCRIPT_GENERATED_FILES ] -then - set +o xtrace - echo "The expected bazel workspace directory wasn't found." - echo "Make sure you run this script via bazel:" - echo "bazel run oak_proto_rust:verify_generated" - exit 1 -fi - - -for generated in "$BUILD_SCRIPT_GENERATED_FILES"/* -do - filename=$(basename -- "$generated") - GENERATED_FILE_HASH=$(sha512sum < "$generated") - EXISTING_FILE_HASH=$(sha512sum < "$IMPORTABLE_GENERATED_FILE_DEST/$filename") - - if [ "$GENERATED_FILE_HASH" != "$EXISTING_FILE_HASH" ] - then - set +o xtrace - echo "" - echo "The generated files haven't been moved to an importable location." - echo "Please run:" - echo "" - echo "bazel run oak_proto_rust:copy_generated" - echo "" - exit 1 - fi -done - -echo "Generated files are up-to-date"