Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "build protobufs"
name: "Bazel build of protobufs"

on:
push:
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/google-rpc-status-synced.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Ensure google/rpc/status.proto is synced with upstream.

on:
pull_request:

jobs:
check-google-rpc-status-synced:
runs-on: [ubuntu-latest]
steps:
- uses: actions/checkout@v5
- run: ./proto/update_google_rpc_status.sh
- run: |
DIFF=$(git diff proto/google/rpc/status.proto)
if [ -n "$DIFF" ]; then
echo "$DIFF"
echo ""
echo "ERROR: proto/google/rpc/status.proto is not synced with upstream."
echo "Please run ./proto/update_google_rpc_status.sh to fix it."
exit 1
fi
echo "SUCCESS: proto/google/rpc/status.proto is synced with upstream."
14 changes: 14 additions & 0 deletions .github/workflows/rust-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: "Rust build"

on:
push:
branches: [ main ]
pull_request:

jobs:
build:
runs-on: [ubuntu-latest]
steps:
- uses: actions/checkout@v5
- run: cd rust && cargo build
- run: cd rust && cargo test
11 changes: 0 additions & 11 deletions CI/check_codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pushd "$THIS_DIR/.." >/dev/null

rm -rf go/*
rm -rf py/p4
rm -rf rust/src
./codegen/update.sh

diff="$(git status --porcelain go go.mod go.sum)"
Expand All @@ -27,14 +26,4 @@ if [ ! -z "$diff" ]; then
exit 1
fi

diff="$(git status --porcelain rust)"

if [ ! -z "$diff" ]; then
echo "The generated Rust files are not up-to-date"
echo "DIFF:"
echo "$diff"
echo "You can regenerate them with './codegen/update.sh' and commit the changes"
exit 1
fi

popd >/dev/null
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,7 @@ pip3 install p4runtime==1.3.0

### Rust

To include the P4Runtime Rust crate to your project, add this repository url to
your `Cargo.toml` file:

```toml
[dependencies]
p4runtime = { git = "https://github.com/p4lang/p4runtime.git" }
```
See the [rust/README.md](rust/README.md).

## Guidelines for using Protocol Buffers (protobuf) in backwards-compatible ways

Expand Down
8 changes: 1 addition & 7 deletions codegen/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LABEL description="Dockerfile used for CI testing of p4lang/p4runtime"
ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
apt-get install -y --no-install-recommends software-properties-common git curl build-essential
apt-get install -y --no-install-recommends software-properties-common git curl

ARG GO_VERSION=1.20.5

Expand All @@ -26,11 +26,5 @@ ENV PATH="${PATH}:/usr/local/go/bin:/root/go/bin"
RUN go install google.golang.org/protobuf/cmd/[email protected]
RUN go install google.golang.org/grpc/cmd/[email protected]

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.81.0 --profile minimal; \
. $HOME/.cargo/env; \
cargo install --locked [email protected] [email protected] [email protected]

ENV PATH="${PATH}:/root/.cargo/bin"

COPY . /p4runtime/
WORKDIR /p4runtime/
27 changes: 2 additions & 25 deletions codegen/compile_protos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,18 @@ set -e
THIS_DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
PROTO_DIR="$THIS_DIR/../proto"

tmpdir="$(mktemp -d)"
pushd "$tmpdir" > /dev/null
git clone --depth 1 https://github.com/googleapis/googleapis.git
popd > /dev/null
GOOGLE_PROTO_DIR="$tmpdir/googleapis"

PROTOS="\
$PROTO_DIR/p4/v1/p4data.proto \
$PROTO_DIR/p4/v1/p4runtime.proto \
$PROTO_DIR/p4/config/v1/p4info.proto \
$PROTO_DIR/p4/config/v1/p4types.proto \
$GOOGLE_PROTO_DIR/google/rpc/status.proto \
$GOOGLE_PROTO_DIR/google/rpc/code.proto"
$PROTO_DIR/p4/config/v1/p4types.proto"

PROTOFLAGS="-I$GOOGLE_PROTO_DIR -I$PROTO_DIR"
PROTOFLAGS="-I$PROTO_DIR"

mkdir -p "$BUILD_DIR/cpp_out"
mkdir -p "$BUILD_DIR/grpc_out"
mkdir -p "$BUILD_DIR/py_out"
mkdir -p "$BUILD_DIR/go_out"
mkdir -p "$BUILD_DIR/rust_out"

set -o xtrace
$PROTOC $PROTOS --cpp_out "$BUILD_DIR/cpp_out" $PROTOFLAGS
Expand All @@ -66,18 +57,4 @@ $PROTOC $PROTOS --python_out "$BUILD_DIR/py_out" $PROTOFLAGS --grpc_out "$BUILD_

$PROTOC $PROTOS --go_out="$BUILD_DIR/go_out" --go-grpc_out="$BUILD_DIR/go_out" $PROTOFLAGS

$PROTOC $PROTOS $PROTOFLAGS \
--prost_out="$BUILD_DIR/rust_out/src" \
--prost_opt=compile_well_known_types \
--prost_opt=extern_path=.google.protobuf=::pbjson_types \
--tonic_out="$BUILD_DIR/rust_out/src" \
--tonic_opt=compile_well_known_types \
--tonic_opt=extern_path=.google.protobuf=::pbjson_types \
--prost-crate_out="$BUILD_DIR/rust_out" \
--prost-crate_opt="gen_crate=rust/Cargo.toml"

set +o xtrace

rm -rf "$tmpdir"

echo "SUCCESS"
3 changes: 0 additions & 3 deletions codegen/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ cp -r "$tmpdir"/go_out/github.com/p4lang/p4runtime/go/* go/
cp -r "$tmpdir"/py_out/p4 py/
find py/p4 -type d -exec touch {}/__init__.py \;

# Rust
cp -r "$tmpdir"/rust_out/* rust/

# Cleanup files owned by root user
docker run --rm \
-v "$tmpdir:/tmp/gen" \
Expand Down
49 changes: 49 additions & 0 deletions proto/google/rpc/status.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package google.rpc;

import "google/protobuf/any.proto";

option cc_enable_arenas = true;
option go_package = "google.golang.org/genproto/googleapis/rpc/status;status";
option java_multiple_files = true;
option java_outer_classname = "StatusProto";
option java_package = "com.google.rpc";
option objc_class_prefix = "RPC";

// The `Status` type defines a logical error model that is suitable for
// different programming environments, including REST APIs and RPC APIs. It is
// used by [gRPC](https://github.com/grpc). Each `Status` message contains
// three pieces of data: error code, error message, and error details.
//
// You can find out more about this error model and how to work with it in the
// [API Design Guide](https://cloud.google.com/apis/design/errors).
message Status {
// The status code, which should be an enum value of
// [google.rpc.Code][google.rpc.Code].
int32 code = 1;

// A developer-facing error message, which should be in English. Any
// user-facing error message should be localized and sent in the
// [google.rpc.Status.details][google.rpc.Status.details] field, or localized
// by the client.
string message = 2;

// A list of messages that carry the error details. There is a common set of
// message types for APIs to use.
repeated google.protobuf.Any details = 3;
}
14 changes: 14 additions & 0 deletions proto/update_google_rpc_status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
#
# Updates proto/google/rpc/status.proto with the latest version from the
# official upstream repository.
#
# The file is very stable and hasn't changed in many years, but we enforce
# freshness of this copy using a GitHub Actions workflow just in case.

set -e

STATUS_PROTO_URL="https://raw.githubusercontent.com/googleapis/googleapis/refs/heads/master/google/rpc/status.proto"
THIS_DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"

wget "$STATUS_PROTO_URL" -O "$THIS_DIR/google/rpc/status.proto"
Loading