Skip to content

Commit

Permalink
Andrewmwells/protobufs (#1277)
Browse files Browse the repository at this point in the history
Signed-off-by: Brandon Rozek <[email protected]>
Signed-off-by: Andrew Wells <[email protected]>
Co-authored-by: Brandon Rozek <[email protected]>
  • Loading branch information
andrewmwells-amazon and Brandon-Rozek authored Oct 23, 2024
1 parent 4be5f5f commit 6b16db5
Show file tree
Hide file tree
Showing 27 changed files with 2,973 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:

steps:
- uses: actions/checkout@v4
- run: sudo apt-get install protobuf-compiler
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
- run: ./panic_safety.sh
- run: cargo doc --all-features --no-deps
Expand All @@ -43,6 +44,7 @@ jobs:

steps:
- uses: actions/checkout@v4
- run: sudo apt-get install protobuf-compiler
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
# Clippy is configured by `.cargo/config.toml` to deny on lints like
# `unwrap_used`. They aren't detected by `panic_safety.sh` which only
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
# `cargo semver-checks` doesn't understand `rlib` crates.
- run: >-
sed -i -E 's/^(crate-type = \["rlib", "cdylib"\]|crate-type = \["rlib"\])$/crate-type = ["lib"]/' {head,base}/cedar-policy/Cargo.toml
- run: sudo apt-get install protobuf-compiler
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
- run: cargo install cargo-semver-checks
- run: cargo semver-checks check-release --package cedar-policy --baseline-root ../base
Expand Down
6 changes: 6 additions & 0 deletions cedar-policy-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ serde-wasm-bindgen = { version = "0.6", optional = true }
tsify = { version = "0.4.5", optional = true }
wasm-bindgen = { version = "0.2.82", optional = true }

# protobuf dependency
prost = { version = "0.13.3", optional = true }

[features]
# by default, enable all Cedar extensions
default = ["ipaddr", "decimal"]
Expand All @@ -52,9 +55,12 @@ test-util = []
# Experimental features.
partial-eval = []
wasm = ["serde-wasm-bindgen", "tsify", "wasm-bindgen"]
protobufs = ["dep:prost", "dep:prost-build"]

[build-dependencies]
lalrpop = "0.22.0"
# protobuf dependency
prost-build = { version = "0.13.3", optional = true }

[dev-dependencies]
cool_asserts = "2.0"
Expand Down
11 changes: 11 additions & 0 deletions cedar-policy-core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

fn main() {
generate_parsers();
#[cfg(feature = "protobufs")]
generate_schemas();
}

/// Reads parser grammar files (.lalrpop) and generates Rust modules
Expand All @@ -26,3 +28,12 @@ fn generate_parsers() {
.process_dir("src/parser/")
.expect("parser synth");
}

#[cfg(feature = "protobufs")]
/// Reads protobuf schema files (.proto) and generates Rust modules
fn generate_schemas() {
// PANIC SAFETY: static file compiled at build time
#[allow(clippy::expect_used)]
prost_build::compile_protos(&["./protobuf_schema/AST.proto"], &["./protobuf_schema"])
.expect("failed to compile `.proto` schema files");
}
Loading

0 comments on commit 6b16db5

Please sign in to comment.