Introduce an API version to the build rules

This will allow us to experiment with (and subsequently migrate to)
changes to the generated API, possibly incompatible ones.

This change should be a no-op for current builds, as there is only
a single version of Sandboxed API.

PiperOrigin-RevId: 438003314
Change-Id: Ia23ea4360bee0227692d9f5220ab20d85f089ba7
This commit is contained in:
Christian Blichmann 2022-03-29 05:56:49 -07:00 committed by Copybara-Service
parent 15fab1322a
commit dc895f6dc8
2 changed files with 28 additions and 5 deletions

View File

@ -87,14 +87,20 @@ endmacro()
# LIBRARY_NAME into.
# HEADER If set, does not generate an interface header, but uses the one
# specified.
# API_VERSION Which version of the Sandboxed API to generate. Currently, only
# version "1" is defined.
function(add_sapi_library)
set(_sapi_opts NOEMBED)
set(_sapi_one_value HEADER LIBRARY LIBRARY_NAME NAMESPACE)
set(_sapi_one_value HEADER LIBRARY LIBRARY_NAME NAMESPACE API_VERSION)
set(_sapi_multi_value SOURCES FUNCTIONS INPUTS)
cmake_parse_arguments(PARSE_ARGV 0 _sapi "${_sapi_opts}"
"${_sapi_one_value}" "${_sapi_multi_value}")
set(_sapi_NAME "${ARGV0}")
if(_sapi_API_VERSION AND NOT _sapi_API_VERSION VERSION_EQUAL "1")
message(FATAL_ERROR "API_VERSION \"1\" is the only one defined right now")
endif()
set(_sapi_gen_header "${_sapi_NAME}.sapi.h")
foreach(func IN LISTS _sapi_FUNCTIONS)
list(APPEND _sapi_exported_funcs "LINKER:--export-dynamic-symbol,${func}")

View File

@ -148,12 +148,25 @@ sapi_interface = rule(
"out": attr.output(mandatory = True),
"embed_dir": attr.string(),
"embed_name": attr.string(),
"functions": attr.string_list(allow_empty = True, default = []),
"input_files": attr.label_list(allow_files = True),
"lib": attr.label(providers = [CcInfo], mandatory = True),
"functions": attr.string_list(
allow_empty = True,
default = [],
),
"input_files": attr.label_list(
providers = [CcInfo],
allow_files = True,
),
"lib": attr.label(
providers = [CcInfo],
mandatory = True,
),
"lib_name": attr.string(mandatory = True),
"namespace": attr.string(),
"limit_scan_depth": attr.bool(default = False),
"api_version": attr.int(
default = 1,
values = [1], # Only a single version is defined right now
),
"generator": attr.label(
executable = True,
cfg = "host",
@ -173,6 +186,7 @@ def sapi_library(
lib,
lib_name,
namespace = "",
api_version = 1,
embed = True,
add_default_deps = True,
limit_scan_depth = False,
@ -197,6 +211,8 @@ def sapi_library(
embed: Whether the SAPI library should be embedded inside the host code
add_default_deps: Add SAPI dependencies to target (deprecated)
limit_scan_depth: Limit include depth for header generator (deprecated)
api_version: Which version of the Sandboxed API to generate. Currently,
only version 1 is defined.
srcs: Any additional sources to include with the sandboxed library
hdrs: Like srcs, any additional headers to include with the sandboxed
library
@ -204,7 +220,7 @@ def sapi_library(
header: If set, do not generate a header, but use the specified one
(deprecated).
input_files: List of source files which the SAPI interface generator
should scan for function declaration
should scan for function declarations
deps: Extra dependencies to add to the SAPI library
tags: Extra tags to associate with the target
generator_executable: Label of the SAPI interface generator to use
@ -303,6 +319,7 @@ def sapi_library(
embed_name = embed_name,
embed_dir = embed_dir,
namespace = namespace,
api_version = api_version,
generator = generator_executable,
limit_scan_depth = limit_scan_depth,
**common