Skip to content

Commit

Permalink
Add new blaze target for running the protobuf and upb crates tests us…
Browse files Browse the repository at this point in the history
…ing Cargo

PiperOrigin-RevId: 673854261
  • Loading branch information
dbenson24 authored and copybara-github committed Sep 12, 2024
1 parent 92aca2d commit 6174e13
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
9 changes: 9 additions & 0 deletions rust/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,12 @@ pkg_zip(
"//:LICENSE",
],
)

sh_binary(
name = "cargo_test",
srcs = ["cargo_test.sh"],
data = [
":rust_crate",
],
deps = ["@bazel_tools//tools/bash/runfiles"],
)
37 changes: 37 additions & 0 deletions rust/cargo_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
# Runs tests that are defined in the protobuf crate using Cargo.
# This is not a hermetic task because Cargo will fetch the needed
# dependencies from crates.io

# --- begin runfiles.bash initialization ---
# Copy-pasted from Bazel's Bash runfiles library (tools/bash/runfiles/runfiles.bash).
set -euo pipefail
if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
if [[ -f "$0.runfiles_manifest" ]]; then
export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest"
elif [[ -f "$0.runfiles/MANIFEST" ]]; then
export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST"
elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
export RUNFILES_DIR="$0.runfiles"
fi
fi
if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash"
elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \
"$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)"
else
echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash"
exit 1
fi
# --- end runfiles.bash initialization ---

TMP_DIR=$(mktemp -d)
trap 'rm -rf -- "$TMP_DIR"' EXIT
CRATE=$(rlocation com_google_protobuf/rust/rust_crate.zip)

unzip -d $TMP_DIR $CRATE
cd $TMP_DIR

# Run all tests except doctests
cargo test --lib --bins --tests

0 comments on commit 6174e13

Please sign in to comment.