Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vendor prost locally #1199

Merged
merged 2 commits into from
Jun 26, 2020
Merged
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
47 changes: 47 additions & 0 deletions scripts/vendor_prost.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash

readonly SCRIPTS_DIR="$(dirname "$0")"
# shellcheck source=scripts/common
source "${SCRIPTS_DIR}/common"

# Updates our local copy of https://github.com/danburkert/prost and applies a small patch to add
# support for the message_type field option.

# Master branch as of 2020-06-05
readonly PROST_COMMIT="80256277997975948d257faf3f35c2890bf12787"
readonly PROST_ZIP_SHA256="02c086f2d1b7aad110745ac701f001618cd8343f882fc9ce034aa007c4c53773"

readonly PROST_ZIP_URL="https://github.com/danburkert/prost/archive/${PROST_COMMIT}.zip"
readonly PROST_ZIP_PREFIX="prost-${PROST_COMMIT}"

# Make sure we run in the third_party directory.
cd "${SCRIPTS_DIR}/../third_party" || exit
daviddrysdale marked this conversation as resolved.
Show resolved Hide resolved

# Download the prost zip only if it does not yet exist in the filesystem.
if [[ ! -f "${PROST_ZIP_PREFIX}.zip" ]]; then
curl --location "${PROST_ZIP_URL}" > "${PROST_ZIP_PREFIX}.zip"
fi

# Make sure the SHA256 checks out
echo "${PROST_ZIP_SHA256} ${PROST_ZIP_PREFIX}.zip" | sha256sum --check -

# Clean up from previous runs
rm -rf "${PROST_ZIP_PREFIX}" prost/

# Unzip and move into the vendored directory (stripping the prefix).
unzip "${PROST_ZIP_PREFIX}.zip"
mv "${PROST_ZIP_PREFIX}" prost

# We do not need the bundled protobuf because we already require users to have it installed.
rm -r prost/prost-build/third-party

(
# Apply any local patches.
cd prost/ || exit
for patchfile in ../prost-*.patch; do
patch --strip=1 < "$patchfile"
done

# Check the local version runs, which also regenerates Cargo.lock.
PROTOC=protoc cargo test
)
1 change: 1 addition & 0 deletions third_party/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
prost-*.zip
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
From df8d3e37563d373ac38cc90f75f97416ba766b61 Mon Sep 17 00:00:00 2001
From: Daan de Graaf <daagra@google.com>
Date: Fri, 27 Mar 2020 14:34:20 +0000
Subject: [PATCH] Patch prost to generate typesafe Sender and Receiver.

---
prost-build/src/code_generator.rs | 13 +++++++++++++
prost-types/src/protobuf.rs | 3 +++
2 files changed, 16 insertions(+)

diff --git a/prost-build/src/code_generator.rs b/prost-build/src/code_generator.rs
index 7323eb6..f500791 100644
--- a/prost-build/src/code_generator.rs
+++ b/prost-build/src/code_generator.rs
@@ -715,7 +715,20 @@ impl<'a> CodeGenerator<'a> {
self.buf.push_str("}\n");
}

+ fn resolve_message_type(&self, field: &FieldDescriptorProto) -> Option<String> {
+ let message_type = self.resolve_ident(&field.options.as_ref()?.message_type.as_ref()?);
+ let direction = match field.type_name() {
+ ".oak.handle.Sender" => Some("Sender"),
+ ".oak.handle.Receiver" => Some("Receiver"),
+ _ => None,
+ }?;
+ Some(format!("::oak::io::{}<{}>", direction, message_type))
+ }
+
fn resolve_type(&self, field: &FieldDescriptorProto) -> String {
+ if let Some(ty) = self.resolve_message_type(field) {
+ return ty;
+ }
match field.r#type() {
Type::Float => String::from("f32"),
Type::Double => String::from("f64"),
diff --git a/prost-types/src/protobuf.rs b/prost-types/src/protobuf.rs
index 6649f76..0e2edbf 100644
--- a/prost-types/src/protobuf.rs
+++ b/prost-types/src/protobuf.rs
@@ -567,6 +567,9 @@ pub struct FieldOptions {
/// The parser stores options it doesn't recognize here. See above.
#[prost(message, repeated, tag="999")]
pub uninterpreted_option: ::prost::alloc::vec::Vec<UninterpretedOption>,
+ /// Oak `message_type` annotation.
+ #[prost(string, optional, tag="79658")]
+ pub message_type: ::core::option::Option<::prost::alloc::string::String>,
}
/// Nested message and enum types in `FieldOptions`.
pub mod field_options {
--
2.20.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: continuous integration
on: pull_request

jobs:

rustfmt:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
- name: install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
default: true
profile: minimal
components: rustfmt
- name: rustfmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
default: true
profile: minimal
components: clippy
- name: install ninja
uses: seanmiddleditch/gha-setup-ninja@v1
- name: clippy
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --workspace --all-features --all-targets

test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
toolchain:
- stable
- 1.39.0
os:
- ubuntu-latest
- macos-latest
- windows-latest
steps:
- name: checkout
uses: actions/checkout@v2
- name: install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.toolchain }}
default: true
profile: minimal
- name: install ninja
uses: seanmiddleditch/gha-setup-ninja@v1
- name: test
uses: actions-rs/cargo@v1
with:
command: test
args: --workspace --all-targets
- name: test no-default-features
uses: actions-rs/cargo@v1
with:
command: test
args: --no-default-features

no-std:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
- name: install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
default: true
profile: minimal
- name: install cargo-no-std-check
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-no-std-check
- name: prost cargo-no-std-check
uses: actions-rs/cargo@v1
with:
command: no-std-check
args: --manifest-path Cargo.toml --no-default-features
- name: prost-types cargo-no-std-check
uses: actions-rs/cargo@v1
with:
command: no-std-check
args: --manifest-path prost-types/Cargo.toml --no-default-features
# prost-build depends on prost with --no-default-features, but when
# prost-build is built through the workspace, prost typically has default
# features enabled due to vagaries in Cargo workspace feature resolution.
# This additional check ensures that prost-build does not rely on any of
# prost's default features to compile.
- name: prost-build check
uses: actions-rs/cargo@v1
with:
command: check
args: --manifest-path prost-build/Cargo.toml
1 change: 1 addition & 0 deletions third_party/prost/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
Loading