1# Copyright 2020 Google LLC 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15load( 16 "@com_google_sandboxed_api//sandboxed_api/bazel:sapi.bzl", 17 "sapi_library", 18) 19 20# Library with code that should be sandboxed 21cc_library( 22 name = "hello_lib", 23 srcs = ["hello_lib.cc"], 24 alwayslink = 1, 25) 26 27# Sandboxed API for the library above 28sapi_library( 29 name = "hello_sapi", 30 functions = [ 31 "AddTwoIntegers", 32 ], 33 generator_version = 1, 34 input_files = ["hello_lib.cc"], 35 lib = ":hello_lib", 36 lib_name = "Hello", 37 visibility = ["//visibility:public"], 38) 39 40# Main executable demonstrating how the sandboxed library is used 41cc_binary( 42 name = "hello", 43 srcs = ["hello_main.cc"], 44 deps = [":hello_sapi"], 45) 46 47# Another example using the same library, but using the Transaction API that 48# automatically retries sandbox operations. Also demonstates error handling 49# and a custom security policy. 50cc_binary( 51 name = "hello_transacted", 52 srcs = ["hello_transacted.cc"], 53 deps = [ 54 ":hello_sapi", 55 "@com_google_absl//absl/memory", 56 "@com_google_absl//absl/status", 57 "@com_google_sandboxed_api//sandboxed_api/util:status", 58 ], 59) 60