Skip to content

Commit

Permalink
feat: Add generated proto for sample BYOB UDF to repo
Browse files Browse the repository at this point in the history
Bug: b/374288740
Change-Id: I7a9160726a760b3f4ff904572facfd61e862c2da
GitOrigin-RevId: ac4654084f80a145d4c4462a649ef67ee6f00d91
  • Loading branch information
Privacy Sandbox Team authored and copybara-github committed Oct 18, 2024
1 parent 68b191e commit 40780f6
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 56 deletions.
9 changes: 3 additions & 6 deletions src/roma/byob/sample_udf/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ proto_library(
cc_proto_library(
name = "sample_cc_proto",
visibility = ["//src/roma/byob:__subpackages__"],
deps = [
":sample_proto",
],
deps = [":sample_proto"],
)

buf_lint_test(
Expand All @@ -58,9 +56,7 @@ proto_library(
cc_proto_library(
name = "sample_callback_cc_proto",
visibility = ["//src/roma/byob:__subpackages__"],
deps = [
":sample_callback_proto",
],
deps = [":sample_callback_proto"],
)

buf_lint_test(
Expand Down Expand Up @@ -95,6 +91,7 @@ sample_api = declare_roma_api(

roma_byob_sdk(
name = "sample_byob_sdk",
generated_proto_path = "generated/sample.proto",
roma_app_api = sample_api,
visibility = ["//visibility:public"],
)
Expand Down
175 changes: 175 additions & 0 deletions src/roma/byob/sample_udf/generated/sample.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
// Copyright 2024 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.

//
// Generated from: src/roma/byob/sample_udf/sample.proto
//
// See /docs/Guide to the SDK.md for information on using this spec.
//
//
// SampleServer UDF Spec
// A sample server showcasing declarative APIs for BYOB
//

syntax = "proto3";

package privacy_sandbox.roma_byob.example;




//
// UDF rpc: Sample
// The Sample method MethodAnnotation. Add some information about this rpc
// method.
// request: SampleRequest
// response: SampleResponse

// SampleRequest specifies a single function to execute.
message SampleRequest {
// The function to be executed
FunctionType function = 1;
}

// SampleResponse returns the function's output.
message SampleResponse {
// The payload generated by the function.
string greeting = 1;
// A list of prime numbers.
repeated int32 prime_number = 2;
}

//
// UDF rpc: ReadPayload
// MethodAnnotation. Add some information about this rpc method.
// request: ReadPayloadRequest
// response: ReadPayloadResponse


message ReadPayloadRequest {
// The payloads sent into the UDF.
repeated bytes payloads = 1;
}


message ReadPayloadResponse {
// The size of the payloads sent to the UDF.
uint64 payload_size = 1;
}

//
// UDF rpc: GeneratePayload
// MethodAnnotation. Add some information about this rpc method.
// request: GeneratePayloadRequest
// response: GeneratePayloadResponse


message GeneratePayloadRequest {
// The size of the payload elements for the UDF to generate.
uint64 element_size = 1;
// The number of the payload elements for the UDF to generate.
uint64 element_count = 2;
}


message GeneratePayloadResponse {
// The payloads generated by the UDF.
repeated bytes payloads = 1;
}

//
// UDF rpc: ReadCallbackPayload
// MethodAnnotation
// request: ReadCallbackPayloadRequest
// response: ReadCallbackPayloadResponse


message ReadCallbackPayloadRequest {
// The size of the payload elements to generate as input to the Host API
// function.
uint64 element_size = 1;
// The number of the payload elements to generate as input to the Host API
// function.
uint64 element_count = 2;
}


message ReadCallbackPayloadResponse {
// The size of the payloads sent to the Host API function.
uint64 payload_size = 1;
}

//
// UDF rpc: WriteCallbackPayload
// MethodAnnotation
// request: WriteCallbackPayloadRequest
// response: WriteCallbackPayloadResponse


message WriteCallbackPayloadRequest {
// The size of the payload elements for the Host API function to generate.
uint64 element_size = 1;
// The number of the payload elements for the Host API function to generate.
uint64 element_count = 2;
}


message WriteCallbackPayloadResponse {
// The size of the payloads returned by the Host API function.
uint64 payload_size = 1;
}

//
// UDF rpc: RunPrimeSieve
// MethodAnnotation
// request: RunPrimeSieveRequest
// response: RunPrimeSieveResponse


message RunPrimeSieveRequest {
// The count of prime numbers to generate.
int32 prime_count = 1;
}


message RunPrimeSieveResponse {
// The Nth (and largest) of the prime numbers generated.
int32 largest_prime = 1;
}

//
// UDF rpc: SortList
// MethodAnnotation
// request: SortListRequest
// response: SortListResponse


message SortListRequest {
}


message SortListResponse {
}


// Functions that can be executed by the Sample UDF.
enum FunctionType {
FUNCTION_UNSPECIFIED = 0;
// The hello world function.
FUNCTION_HELLO_WORLD = 1;
// The sieve-based prime generator function.
FUNCTION_PRIME_SIEVE = 2;
FUNCTION_CALLBACK = 3;
FUNCTION_TEN_CALLBACK_INVOCATIONS = 4;
}
5 changes: 2 additions & 3 deletions src/roma/byob/sample_udf/sample.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ import "apis/privacysandbox/apis/roma/app_api/v1/options.proto";
service SampleService {
option (privacysandbox.apis.roma.app_api.v1.roma_svc_annotation) = {
name: 'Sample Server',
code_id: "app_api_roma_app_test_v1",
roma_app_name: 'SampleServer',
description: 'A sample server showcasing declarative APIs for BYOB',
cpp_namespace: 'privacy_sandbox::roma_byob::example',
roma_app_name: 'SampleServer'
cpp_namespace: 'privacy_sandbox::roma_byob::example'
};

rpc Sample(SampleRequest) returns (SampleResponse) {
Expand Down
12 changes: 12 additions & 0 deletions src/roma/tools/api_plugin/roma_api.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

"""Macro for the Roma Application API."""

load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_file")
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@com_google_googleapis_imports//:imports.bzl", "cc_proto_library")
Expand Down Expand Up @@ -861,6 +862,7 @@ def roma_byob_sdk(
extra_docs = [],
exclude_tools = False,
guide_intro_text = _default_guide_intro,
generated_proto_path = "",
**kwargs):
"""
Top-level macro for the Roma BYOB SDK.
Expand All @@ -873,6 +875,9 @@ def roma_byob_sdk(
extra_docs: a list of declare_doc-created structs
exclude_tools: bool controlling inclusion of SDK tools
guide_intro_text: string containing markdown text for the guide introduction
generated_proto_path: path to the workspace source location to store the
generated protobuf spec. Must be in the same package as the sdk
build target.
**kwargs: attributes common to bazel build rules.
Targets:
Expand Down Expand Up @@ -912,6 +917,13 @@ def roma_byob_sdk(
config = Label("//src:buf.yaml"),
targets = [":{}_proto".format(name)],
)
if generated_proto_path:
write_source_file(
name = name + "_write_proto",
check_that_out_file_exists = False,
in_file = ":{}.proto".format(name),
out_file = generated_proto_path,
)
pkg_files(
name = name + "_specs",
srcs = [":{}.proto".format(name)],
Expand Down
Loading

0 comments on commit 40780f6

Please sign in to comment.