Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move building of proto generated files to their own crates.
Browse files Browse the repository at this point in the history
ernoc committed Jan 4, 2024
1 parent 884dda5 commit 3281161
Showing 36 changed files with 234 additions and 137 deletions.
27 changes: 24 additions & 3 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -100,6 +100,8 @@ oak_grpc_utils = { path = "./oak_grpc_utils" }
oak_launcher_utils = { path = "./oak_launcher_utils" }
oak_linux_boot_params = { path = "./linux_boot_params" }
oak_logger = { path = "./oak_functions/logger" }
oak_attestation_proto = { path = "./proto/attestation" }
oak_functions_proto = { path = "./proto/oak_functions" }
oak_remote_attestation = { path = "./oak_remote_attestation" }
oak_restricted_kernel_dice = { path = "./oak_restricted_kernel_dice" }
oak_restricted_kernel_sdk = { path = "./oak_restricted_kernel_sdk" }
10 changes: 9 additions & 1 deletion enclave_apps/Cargo.lock

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

1 change: 0 additions & 1 deletion fuzz/Cargo.lock

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

4 changes: 1 addition & 3 deletions oak_attestation_verification/Cargo.toml
Original file line number Diff line number Diff line change
@@ -13,13 +13,11 @@ coset = { version = "*", default-features = false }
ecdsa = { version = "*", features = ["pkcs8", "pem"] }
hex = "*"
oak_dice = { workspace = true }
oak_attestation_proto = { workspace = true }
prost = { workspace = true }
p256 = { version = "*", features = ["ecdsa-core", "ecdsa", "pem"] }
serde = { version = "*", features = ["derive"] }
serde_jcs = "*"
serde_json = "*"
sha2 = { version = "*", default-features = false }
time = { version = "0.3.28", features = ["serde", "parsing", "formatting"] }

[build-dependencies]
prost-build = { workspace = true }
2 changes: 1 addition & 1 deletion oak_attestation_verification/src/claims.rs
Original file line number Diff line number Diff line change
@@ -21,9 +21,9 @@
extern crate alloc;

use crate::proto::oak::HexDigest;
use alloc::{collections::BTreeMap, string::String, vec::Vec};
use anyhow::Context;
use oak_attestation_proto::oak::HexDigest;
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;

2 changes: 1 addition & 1 deletion oak_attestation_verification/src/endorsement.rs
Original file line number Diff line number Diff line change
@@ -21,12 +21,12 @@ use crate::{
get_digest, parse_endorsement_statement, validate_endorsement, verify_validity_duration,
EndorsementStatement,
},
proto::oak::HexDigest,
rekor::{get_rekor_log_entry_body, verify_rekor_log_entry},
util::{convert_pem_to_raw, equal_keys, is_hex_digest_match, MatchResult},
};
use anyhow::Context;
use base64::{prelude::BASE64_STANDARD, Engine as _};
use oak_attestation_proto::oak::HexDigest;

/// Compares the digest contained in the endorsement against the given one.
pub fn verify_binary_digest(
18 changes: 0 additions & 18 deletions oak_attestation_verification/src/lib.rs
Original file line number Diff line number Diff line change
@@ -19,24 +19,6 @@

extern crate alloc;

// Inlined from tonic::include_proto in order to cut dependency on tonic.
macro_rules! include_proto {
($package: tt) => {
include!(concat!(env!("OUT_DIR"), concat!("/", $package, ".rs")));
};
}

pub mod proto {
pub mod oak {
include_proto!("oak");
pub mod attestation {
pub mod v1 {
include_proto!("oak.attestation.v1");
}
}
}
}

pub mod claims;
pub mod endorsement;
pub mod rekor;
2 changes: 1 addition & 1 deletion oak_attestation_verification/src/util.rs
Original file line number Diff line number Diff line change
@@ -14,12 +14,12 @@
// limitations under the License.
//

use crate::proto::oak::{HexDigest, RawDigest};
use alloc::{string::String, vec::Vec};
use anyhow::Context;
use base64::{prelude::BASE64_STANDARD, Engine as _};
use core::{cmp::Ordering, str::FromStr};
use ecdsa::{signature::Verifier, Signature};
use oak_attestation_proto::oak::{HexDigest, RawDigest};
use p256::ecdsa::VerifyingKey;
use sha2::{Digest, Sha256, Sha384, Sha512};

58 changes: 29 additions & 29 deletions oak_attestation_verification/src/verifier.rs
Original file line number Diff line number Diff line change
@@ -20,20 +20,6 @@ use crate::{
alloc::string::ToString,
claims::{get_digest, parse_endorsement_statement},
endorsement::verify_binary_endorsement,
proto::oak::{
attestation::v1::{
attestation_results::Status, binary_reference_value, endorsements, reference_values,
ApplicationKeys, ApplicationLayerEndorsements, ApplicationLayerReferenceValues,
AttestationResults, BinaryReferenceValue, CbEndorsements, CbReferenceValues,
ContainerLayerEndorsements, ContainerLayerReferenceValues, Endorsements, Evidence,
KernelLayerEndorsements, KernelLayerReferenceValues, LayerEvidence,
OakContainersEndorsements, OakContainersReferenceValues,
OakRestrictedKernelEndorsements, OakRestrictedKernelReferenceValues, ReferenceValues,
RootLayerEndorsements, RootLayerEvidence, RootLayerReferenceValues,
SystemLayerEndorsements, SystemLayerReferenceValues, TransparentReleaseEndorsement,
},
RawDigest,
},
util::{
hex_to_raw_digest, is_hex_digest_match, is_raw_digest_match, raw_to_hex_digest, MatchResult,
},
@@ -42,6 +28,20 @@ use crate::{
use alloc::vec::Vec;
use coset::{cbor::Value, cwt::ClaimsSet, CborSerializable, CoseKey, RegisteredLabelWithPrivate};
use ecdsa::{signature::Verifier, Signature};
use oak_attestation_proto::oak::{
attestation::v1::{
attestation_results::Status, binary_reference_value, endorsements, reference_values,
ApplicationKeys, ApplicationLayerEndorsements, ApplicationLayerReferenceValues,
AttestationResults, BinaryReferenceValue, CbEndorsements, CbReferenceValues,
ContainerLayerEndorsements, ContainerLayerReferenceValues, Endorsements, Evidence,
KernelLayerEndorsements, KernelLayerReferenceValues, LayerEvidence,
OakContainersEndorsements, OakContainersReferenceValues, OakRestrictedKernelEndorsements,
OakRestrictedKernelReferenceValues, ReferenceValues, RootLayerEndorsements,
RootLayerEvidence, RootLayerReferenceValues, SystemLayerEndorsements,
SystemLayerReferenceValues, TransparentReleaseEndorsement,
},
RawDigest,
};
use oak_dice::cert::{
cose_key_to_hpke_public_key, cose_key_to_verifying_key, get_public_key_from_claims_set,
ACPI_MEASUREMENT_ID, CONTAINER_IMAGE_ID, ENCLAVE_APPLICATION_LAYER_ID, INITRD_MEASUREMENT_ID,
@@ -58,21 +58,21 @@ pub struct DiceChainResult {
signing_public_key: Vec<u8>,
}

impl From<&anyhow::Result<DiceChainResult>> for AttestationResults {
fn from(value: &anyhow::Result<DiceChainResult>) -> Self {
match value {
Ok(dice_chain_result) => AttestationResults {
status: Status::Success.into(),
encryption_public_key: dice_chain_result.encryption_public_key.clone(),
signing_public_key: dice_chain_result.signing_public_key.clone(),
..Default::default()
},
Err(err) => AttestationResults {
status: Status::GenericFailure.into(),
reason: err.to_string(),
..Default::default()
},
}
pub fn to_attestation_results(
verify_result: &anyhow::Result<DiceChainResult>,
) -> AttestationResults {
match verify_result {
Ok(dice_chain_result) => AttestationResults {
status: Status::Success.into(),
encryption_public_key: dice_chain_result.encryption_public_key.clone(),
signing_public_key: dice_chain_result.signing_public_key.clone(),
..Default::default()
},
Err(err) => AttestationResults {
status: Status::GenericFailure.into(),
reason: err.to_string(),
..Default::default()
},
}
}

3 changes: 2 additions & 1 deletion oak_attestation_verification/tests/endorsement_tests.rs
Original file line number Diff line number Diff line change
@@ -25,11 +25,12 @@ use oak_attestation_verification::{
verify_binary_digest, verify_binary_endorsement, verify_endorsement_statement,
verify_endorser_public_key,
},
proto::oak::HexDigest,
rekor::{verify_rekor_log_entry, verify_rekor_signature},
util::{convert_pem_to_raw, MatchResult},
};

use oak_attestation_proto::oak::HexDigest;

const BINARY_DIGEST: &str = "39051983bbb600bbfb91bd22ee4c976420f8f0c6a895fd083dcb0d153ddd5fd6";
const ENDORSEMENT_PATH: &str = "testdata/endorsement.json";

46 changes: 29 additions & 17 deletions oak_attestation_verification/tests/verifier_tests.rs
Original file line number Diff line number Diff line change
@@ -18,17 +18,17 @@ use prost::Message;
use std::fs;

use oak_attestation_verification::{
proto::oak::attestation::v1::{
attestation_results::Status, AmdSevReferenceValues, AttestationResults,
BinaryReferenceValue, ContainerLayerEndorsements, ContainerLayerReferenceValues,
EndorsementReferenceValue, Endorsements, Evidence, KernelLayerEndorsements,
KernelLayerReferenceValues, OakContainersEndorsements, OakContainersReferenceValues,
ReferenceValues, RootLayerEndorsements, RootLayerReferenceValues, SkipVerification,
StringReferenceValue, SystemLayerEndorsements, SystemLayerReferenceValues,
TransparentReleaseEndorsement,
},
util::convert_pem_to_raw,
verifier::verify,
verifier::{to_attestation_results, verify},
};

use oak_attestation_proto::oak::attestation::v1::{
attestation_results::Status, AmdSevReferenceValues, BinaryReferenceValue,
ContainerLayerEndorsements, ContainerLayerReferenceValues, EndorsementReferenceValue,
Endorsements, Evidence, KernelLayerEndorsements, KernelLayerReferenceValues,
OakContainersEndorsements, OakContainersReferenceValues, ReferenceValues,
RootLayerEndorsements, RootLayerReferenceValues, SkipVerification, StringReferenceValue,
SystemLayerEndorsements, SystemLayerReferenceValues, TransparentReleaseEndorsement,
};

const ENDORSEMENT_PATH: &str = "testdata/endorsement.json";
@@ -87,7 +87,9 @@ fn create_endorsements() -> Endorsements {
container_layer: Some(container_layer),
};
Endorsements {
r#type: Some(oak_attestation_verification::proto::oak::attestation::v1::endorsements::Type::OakContainers(ends)),
r#type: Some(
oak_attestation_proto::oak::attestation::v1::endorsements::Type::OakContainers(ends),
),
}
}

@@ -108,10 +110,18 @@ fn create_reference_values() -> ReferenceValues {
rekor_public_key,
};
let skip = BinaryReferenceValue {
r#type: Some(oak_attestation_verification::proto::oak::attestation::v1::binary_reference_value::Type::Skip(SkipVerification {})),
r#type: Some(
oak_attestation_proto::oak::attestation::v1::binary_reference_value::Type::Skip(
SkipVerification {},
),
),
};
let brv = BinaryReferenceValue {
r#type: Some(oak_attestation_verification::proto::oak::attestation::v1::binary_reference_value::Type::Endorsement(erv)),
r#type: Some(
oak_attestation_proto::oak::attestation::v1::binary_reference_value::Type::Endorsement(
erv,
),
),
};
let srv = StringReferenceValue {
values: ["whatever".to_owned()].to_vec(),
@@ -150,7 +160,9 @@ fn create_reference_values() -> ReferenceValues {
container_layer: Some(container_layer),
};
ReferenceValues {
r#type: Some(oak_attestation_verification::proto::oak::attestation::v1::reference_values::Type::OakContainers(vs)),
r#type: Some(
oak_attestation_proto::oak::attestation::v1::reference_values::Type::OakContainers(vs),
),
}
}

@@ -161,7 +173,7 @@ fn verify_succeeds() {
let reference_values = create_reference_values();

let r = verify(NOW_UTC_MILLIS, &evidence, &endorsements, &reference_values);
let p = AttestationResults::from(&r);
let p = to_attestation_results(&r);

eprintln!("======================================");
eprintln!("code={} reason={}", p.status as i32, p.reason);
@@ -178,7 +190,7 @@ fn verify_fails_with_manipulated_root_public_key() {
let reference_values = create_reference_values();

let r = verify(NOW_UTC_MILLIS, &evidence, &endorsements, &reference_values);
let p = AttestationResults::from(&r);
let p = to_attestation_results(&r);

eprintln!("======================================");
eprintln!("code={} reason={}", p.status as i32, p.reason);
@@ -194,7 +206,7 @@ fn verify_fails_with_empty_args() {
let reference_values = ReferenceValues::default();

let r = verify(NOW_UTC_MILLIS, &evidence, &endorsements, &reference_values);
let p = AttestationResults::from(&r);
let p = to_attestation_results(&r);

assert!(r.is_err());
assert!(p.status() == Status::GenericFailure);
4 changes: 1 addition & 3 deletions oak_functions/examples/benchmark/module/Cargo.toml
Original file line number Diff line number Diff line change
@@ -10,7 +10,5 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
oak_functions_sdk = { workspace = true }
oak_functions_proto = { workspace = true }
prost = { workspace = true }

[build-dependencies]
prost-build = { workspace = true }
29 changes: 0 additions & 29 deletions oak_functions/examples/benchmark/module/build.rs

This file was deleted.

7 changes: 3 additions & 4 deletions oak_functions/examples/benchmark/module/src/lib.rs
Original file line number Diff line number Diff line change
@@ -15,12 +15,11 @@
//

//! Oak Functions benchmark example.
pub mod proto {
include!(concat!(env!("OUT_DIR"), "/oak.functions.benchmark.rs"));
}
use oak_functions_proto::oak::oak_functions::benchmark::{
benchmark_request::Action, BenchmarkRequest, EchoAndPanicTest, LookupTest,
};
use prost::Message;
use proto::{benchmark_request::Action, BenchmarkRequest, EchoAndPanicTest, LookupTest};

#[cfg_attr(not(test), no_mangle)]
pub extern "C" fn main() {
1 change: 1 addition & 0 deletions oak_functions/lookup_data_checker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -13,4 +13,5 @@ env_logger = "*"
location_utils = { workspace = true }
log = "*"
oak_functions_abi = { workspace = true }
oak_functions_proto = { workspace = true }
prost = { workspace = true }
6 changes: 4 additions & 2 deletions oak_functions/lookup_data_checker/src/main.rs
Original file line number Diff line number Diff line change
@@ -39,8 +39,10 @@ pub fn parse_lookup_entries<B: prost::bytes::Buf>(
let mut entries = HashMap::new();
while lookup_data_buffer.has_remaining() {
let entry =
oak_functions_abi::proto::Entry::decode_length_delimited(&mut lookup_data_buffer)
.map_err(|err| anyhow::anyhow!("couldn't decode entry: {err}"))?;
oak_functions_proto::oak::oak_functions::lookup_data::Entry::decode_length_delimited(
&mut lookup_data_buffer,
)
.map_err(|err| anyhow::anyhow!("couldn't decode entry: {err}"))?;
entries.insert(entry.key, entry.value);
}
Ok(entries)
1 change: 1 addition & 0 deletions oak_functions/lookup_data_generator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ clap = { version = "*", features = ["derive"] }
location_utils = { workspace = true }
multimap = "*"
oak_functions_abi = { workspace = true }
oak_functions_proto = { workspace = true }
prost = { workspace = true }
rand = "*"
serde = { version = "*", features = ["derive"] }
2 changes: 1 addition & 1 deletion oak_functions/lookup_data_generator/src/data.rs
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ use location_utils::{
DEFAULT_CUTOFF_RADIUS_RADIANS, S2_DEFAULT_LEVEL,
};
use multimap::MultiMap;
use oak_functions_abi::proto::Entry;
use oak_functions_proto::oak::oak_functions::lookup_data::Entry;
use prost::Message;
use rand::Rng;
use serde::Serialize;
3 changes: 0 additions & 3 deletions oak_functions_abi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -10,6 +10,3 @@ anyhow = { version = "*", default-features = false }
prost = { workspace = true }
strum = { version = "*", default-features = false, features = ["derive"] }
static_assertions = "*"

[build-dependencies]
prost-build = { workspace = true }
5 changes: 0 additions & 5 deletions oak_functions_abi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -23,11 +23,6 @@ extern crate alloc;

use alloc::vec::Vec;

pub mod proto {
include!(concat!(env!("OUT_DIR"), "/oak.functions.abi.rs"));
include!(concat!(env!("OUT_DIR"), "/oak.functions.lookup_data.rs"));
}

/// See REQUEST_RESPONSE_ENCODING.MD in the crate root.
#[derive(Clone, PartialEq, Debug)]
pub struct Request {
1 change: 1 addition & 0 deletions oak_functions_containers_launcher/Cargo.toml
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ oak_containers_launcher = { workspace = true }
oak_crypto = { workspace = true }
oak_functions_abi = { workspace = true }
oak_functions_launcher = { workspace = true }
oak_functions_proto = { workspace = true }
oak_remote_attestation = { workspace = true }
prost = "*"
tokio = { version = "*", features = ["rt-multi-thread", "macros", "sync"] }
6 changes: 4 additions & 2 deletions oak_functions_containers_launcher/src/lookup.rs
Original file line number Diff line number Diff line change
@@ -136,8 +136,10 @@ fn parse_lookup_entries<B: prost::bytes::Buf>(
let mut entries = HashMap::new();
while lookup_data_buffer.has_remaining() {
let entry =
oak_functions_abi::proto::Entry::decode_length_delimited(&mut lookup_data_buffer)
.context("couldn't decode entry")?;
oak_functions_proto::oak::oak_functions::lookup_data::Entry::decode_length_delimited(
&mut lookup_data_buffer,
)
.context("couldn't decode entry")?;
entries.insert(entry.key, entry.value);
}
Ok(entries)
1 change: 1 addition & 0 deletions oak_functions_launcher/Cargo.toml
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ command-fds = { version = "*", features = ["tokio"] }
futures = "*"
log = "*"
env_logger = "*"
oak_functions_proto = { workspace = true }
prost = { workspace = true }
serde = "*"
tokio = { version = "*", features = [
6 changes: 4 additions & 2 deletions oak_functions_launcher/src/lookup.rs
Original file line number Diff line number Diff line change
@@ -142,8 +142,10 @@ fn parse_lookup_entries<B: prost::bytes::Buf>(
let mut entries = HashMap::new();
while lookup_data_buffer.has_remaining() {
let entry =
oak_functions_abi::proto::Entry::decode_length_delimited(&mut lookup_data_buffer)
.context("couldn't decode entry")?;
oak_functions_proto::oak::oak_functions::lookup_data::Entry::decode_length_delimited(
&mut lookup_data_buffer,
)
.context("couldn't decode entry")?;
entries.insert(entry.key, entry.value);
}
Ok(entries)
1 change: 1 addition & 0 deletions oak_functions_service/Cargo.toml
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ oak_core = { workspace = true }
oak_crypto = { workspace = true }
oak_functions_abi = { workspace = true }
oak_functions_sdk = { workspace = true }
oak_functions_proto = { workspace = true }
oak_remote_attestation = { workspace = true }
prost = { workspace = true }
spinning_top = "*"
4 changes: 3 additions & 1 deletion oak_functions_service/tests/integration_test.rs
Original file line number Diff line number Diff line change
@@ -19,12 +19,14 @@

extern crate alloc;

use benchmark::proto::{benchmark_request::Action, BenchmarkRequest, EchoAndPanicTest};
use core::assert_matches::assert_matches;
use oak_crypto::{
encryptor::{ClientEncryptor, EncryptionKeyProvider},
proto::oak::crypto::v1::EncryptedRequest,
};
use oak_functions_proto::oak::oak_functions::benchmark::{
benchmark_request::Action, BenchmarkRequest, EchoAndPanicTest,
};
use oak_functions_service::{
proto::oak::functions::{
ExtendNextLookupDataRequest, FinishNextLookupDataRequest, InitializeRequest, InvokeRequest,
1 change: 1 addition & 0 deletions oak_functions_test_utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ hyper = { version = "*", features = ["client", "http1", "runtime", "server"] }
nix = "*"
oak_functions_abi = { workspace = true }
oak_functions_client = { workspace = true }
oak_functions_proto = { workspace = true }
port_check = "*"
prost = { workspace = true }
tempfile = "*"
3 changes: 2 additions & 1 deletion oak_functions_test_utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -77,7 +77,8 @@ pub fn compile_rust_wasm(manifest_path: &str, release: bool) -> anyhow::Result<V
pub fn serialize_entries(entries: HashMap<Vec<u8>, Vec<u8>>) -> Vec<u8> {
let mut buf = Vec::new();
for (key, value) in entries.into_iter() {
let entry_proto = oak_functions_abi::proto::Entry { key, value };
let entry_proto =
oak_functions_proto::oak::oak_functions::lookup_data::Entry { key, value };
entry_proto
.encode_length_delimited(&mut buf)
.expect("couldn't encode entry as length delimited");
10 changes: 9 additions & 1 deletion oak_ml_transparency/runner/Cargo.lock
11 changes: 11 additions & 0 deletions proto/attestation/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "oak_attestation_proto"
version = "0.0.1"
edition = "2021"
license = "Apache-2.0"

[dependencies]
prost = { workspace = true }

[build-dependencies]
prost-build = { workspace = true }
File renamed without changes.
32 changes: 32 additions & 0 deletions proto/attestation/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// Copyright 2023 The Project Oak Authors
//
// 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.
//

// Inlined from tonic::include_proto in order to cut dependency on tonic.
macro_rules! include_proto {
($package: tt) => {
include!(concat!(env!("OUT_DIR"), concat!("/", $package, ".rs")));
};
}

pub mod oak {
include_proto!("oak");

pub mod attestation {
pub mod v1 {
include_proto!("oak.attestation.v1");
}
}
}
11 changes: 11 additions & 0 deletions proto/oak_functions/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "oak_functions_proto"
version = "0.0.1"
edition = "2021"
license = "Apache-2.0"

[dependencies]
prost = { workspace = true }

[build-dependencies]
prost-build = { workspace = true }
15 changes: 8 additions & 7 deletions oak_functions_abi/build.rs → proto/oak_functions/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2021 The Project Oak Authors
// Copyright 2023 The Project Oak Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -14,24 +14,25 @@
// limitations under the License.
//

extern crate prost_build;

fn main() {
let file_paths = [
fn main() -> Result<(), Box<dyn std::error::Error>> {
let proto_paths = [
"proto/oak_functions/abi.proto",
"proto/oak_functions/benchmark.proto",
"proto/oak_functions/lookup_data.proto",
];
prost_build::compile_protos(&file_paths, &[env!("WORKSPACE_ROOT")])
prost_build::compile_protos(&proto_paths, &[env!("WORKSPACE_ROOT")])
.expect("proto compilation failed");

// Tell cargo to rerun this build script if the proto file has changed.
// https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorerun-if-changedpath
for proto_path in file_paths.iter() {
for proto_path in proto_paths.iter() {
let file_path = std::path::Path::new(proto_path);
println!(
"cargo:rerun-if-changed={}{}",
env!("WORKSPACE_ROOT"),
file_path.display()
);
}

Ok(())
}
36 changes: 36 additions & 0 deletions proto/oak_functions/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// Copyright 2023 The Project Oak Authors
//
// 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.
//

// Inlined from tonic::include_proto in order to cut dependency on tonic.
macro_rules! include_proto {
($package: tt) => {
include!(concat!(env!("OUT_DIR"), concat!("/", $package, ".rs")));
};
}

pub mod oak {
pub mod oak_functions {
pub mod abi {
include_proto!("oak.functions.abi");
}
pub mod benchmark {
include_proto!("oak.functions.benchmark");
}
pub mod lookup_data {
include_proto!("oak.functions.lookup_data");
}
}
}

0 comments on commit 3281161

Please sign in to comment.