Skip to content

Commit

Permalink
pb-rust: schemafy only Bundles
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Leightcap <[email protected]>
  • Loading branch information
jleightcap committed Aug 2, 2023
1 parent b207da1 commit e8f2d78
Show file tree
Hide file tree
Showing 36 changed files with 38 additions and 22 deletions.
23 changes: 13 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,6 @@ ruby: docker-image
--entrypoint bash ${PROTOC_IMAGE} \
-c "cd ./gen/pb-ruby && protoc -I/opt/include -I../../protos/ --ruby_out=lib ../../protos/*.proto"

rust: docker-image
@echo "Generating rust protobuf files"
docker run \
--platform linux/amd64 \
-v ${PWD}:/defs \
-e "RUST_BACKTRACE=1" \
--entrypoint bash ${PROTOC_IMAGE} \
-c "cd gen/pb-rust/codegen && cargo run && rm -rf target/"

jsonschema: docker-image-jsonschema
@echo "Generating JSON schema files"
docker run \
Expand All @@ -68,6 +59,18 @@ jsonschema: docker-image-jsonschema
${JSONSCHEMA_IMAGE} \
-c "cd defs/gen/jsonschema && ./jsonschema.sh -I ../../protos -I /googleapis/ --jsonschema_out=schemas ../../protos/*.proto"

gen/pb-rust/schemas: jsonschema
cp -r gen/jsonschema/schemas $@

rust: docker-image gen/pb-rust/schemas
@echo "Generating rust protobuf files"
docker run \
--platform linux/amd64 \
-v ${PWD}:/defs \
-e "RUST_BACKTRACE=1" \
--entrypoint bash ${PROTOC_IMAGE} \
-c "cd gen/pb-rust && cargo build"

# docker already does its own caching so we can attempt a build every time
.PHONY: docker-image
docker-image:
Expand All @@ -93,7 +96,7 @@ clean:
gen/pb-typescript/src/__generated__ \
gen/pb-python/sigstore_protobuf_specs/dev \
gen/pb-python/sigstore_protobuf_specs/io \
gen/pb-rust/codegen/target \
gen/pb-rust/schemas \
gen/pb-rust/target
docker rmi -f ${PROTOC_IMAGE}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
37 changes: 25 additions & 12 deletions gen/pb-rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
use schemafy_core;
use serde;
use serde_json;

use serde::{Deserialize, Serialize};

pub mod sigstore {
pub mod verification {
pub mod v1 {
use super::super::super::*;
schemafy::schemafy!("schema/Artifact.schema.json");
}
}
}
/// NOTE(jleightcap): a method to include all JSON schemas is not immediately obvious to me:
///
/// - `schemafy!` is a direct 1:1 compilation to Rust structures of each definition in "defintions",
/// - each schema is 'standalone': including definitions of all it's dependencies,
/// as a result, the Rust generated structures have name collisions if included in the same module scope.
///
/// prefixing works,
///
/// ```rust
/// mod CertificateIdentity {
/// schemafy::schemafy!("schemas/CertificateIdentity.shema.json")
/// }
/// mod CertificateIdentities {
/// schemafy::schemafy!("schemas/CertificateIdentities.schema.json")
/// }
/// ```
/// but is clunky to use and manual to generate.
///
/// a more general approach is to 'flatten' each JSON Schema,
/// unioning all of the "defintions" fields.
///
/// Since standardized bundles is the singular motiviation for these Rust bindings,
/// for now we're punting this issue.

schemafy::schemafy!("schemas/Bundle.schema.json");

0 comments on commit e8f2d78

Please sign in to comment.