C++ Bazel support

The file bazel/asylo.bzl defines the bazel repository rules needed to build enclave applications and enclave tests in your WORKSPACE file. Asylo provides the following rules and macros to build and test enclaves: `enclave_loader`, `enclave_test`, `cc_test`, `cc_test_and_cc_enclave_test`, `cc_enclave_test`. The SGX backend provides a C++-specific macro: `sgx_enclave`. You may include asylo macros (e.g., enclave_loader) with the following line in your WORKSPACE file:

load("@com_google_asylo//asylo/bazel:asylo.bzl", "enclave_loader")

You may include sgx macros (e.g., sgx_enclave) with the following line in your WORKSPACE file:

load("@linux_sgx//:sgx_sdk.bzl", "sgx_enclave")

enclave_loader

The rule used to create cc_binary for a given enclave. It combines the driver and enclave targets and ensures that the source is compiled with the host crosstool.

Argument Type Description
name string

Name for the build target.

enclaves dictionary

Dictionary of enclave names to enclave dependency targets.

loader_args list of strings

List of arguments to pass to the enclave loader when executed. Placeholders for enclave names (e.g., {my_enclave} where my_enclave is present in the enclaves argument dictionary) will be replaced with the path to the enclave file.

**kwargs dictionary

[optional] cc_binary arguments.

enclave_test

The rule to build target for testing one or more enclave targets.

Argument Type Description
name string

Name for the test.

enclave list of strings

[optional] The enclave targets to test against.

tags list of strings

[optional] Label attached to this test to allow for querying.

**kwargs dictionary

[optional] cc_test arguments.

cc_enclave_test

The rule that builds targets running cc_test srcs inside an enclave.

Argument Type Description
name string

Name for the test.

srcs list of strings

The path of the source files to be built.

tags list of strings

[optional] Label attached to this test to allow for querying.

deps list of strings

[optional] The targets that this target depends on.

**kwargs dictionary

[optional] cc_test arguments.

cc_test

The rule that creates a cc_test target which runs a normal test, and optionally a cc_enclave_test target, which runs the test inside an enclave.

Argument Type Description
name string

Name for the test.

enclave_test_name string

[optional] Name for the generated cc_enclave_test.

srcs list of strings

[optional] The path of the source files to be built.

deps list of strings

[optional] The targets that this target depends on.

**kwargs dictionary

[optional] cc_test arguments.

cc_test_and_cc_enclave_test

This rule is similar as cc_test, but with a default enclave_test_name.

Argument Type Description
name string

Name for the test.

enclave_test_name string

[optional] See documentation for enclave_test_name in cc_test. If not provided and name ends with "_test", then default this to name with "_test" replaced with "_enclave_test". If not provided and name does not end with "_test", default this to name appended with "_enclave".

srcs list of strings

[optional] The path of the source files to be built.

deps list of strings

[optional] The targets that this target depends on.

**kwargs dictionary

[optional] cc_test arguments.

sgx_enclave

The rule for creating SGX enclave shared object files signed for testing.

Argument Type Description
name string

Name of the enclave target.

config string

[optional] The sgx_enclave configuration rule.

testonly bool

[optional] Set to 0 if the target is only used in tests.

**kwargs dictionary

[optional] cc_test arguments.