Skip to content

Commit d012e3c

Browse files
cblichmanncopybara-github
authored andcommitted
CMake: Make the Clang tool generator the default
The Clang-based header generator (version 2) is now the default. Added a dependency on RE2 for the Clang generator tool to fix the CMake build. PiperOrigin-RevId: 903209345 Change-Id: I22df09afa4ec142974ba0d3c0e303e648e087852
1 parent 3b7c637 commit d012e3c

6 files changed

Lines changed: 48 additions & 21 deletions

File tree

.github/workflows/generator-tool.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ jobs:
4747
-B "$GITHUB_WORKSPACE/build" \
4848
-G Ninja \
4949
-DCMAKE_BUILD_TYPE=Release \
50-
-DSAPI_ENABLE_CLANG_TOOL=ON \
5150
-DSAPI_ENABLE_CLANG_TOOL_STATIC=ON
5251
5352
- name: Build

cmake/SapiBuildDefs.cmake

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ endmacro()
8989
# version "1" is defined.
9090
# GENERATOR_VERSION Which version of the SAPI generator to use. Currently, only
9191
# version "1", "2", and "3" are defined. Note that if unset, this defaults to
92-
# version "1" unless SAPI_ENABLE_CLANG_TOOL is set, in which case it defaults
93-
# to version "2".
92+
# version "2".
9493
function(add_sapi_library)
9594
set(_sapi_opts NOEMBED)
9695
set(_sapi_one_value LIBRARY LIBRARY_NAME NAMESPACE API_VERSION GENERATOR_VERSION)
@@ -99,14 +98,14 @@ function(add_sapi_library)
9998
"${_sapi_one_value}" "${_sapi_multi_value}")
10099
set(_sapi_NAME "${ARGV0}")
101100

102-
if (_sapi_GENERATOR_VERSION AND (_sapi_GENERATOR_VERSION VERSION_LESS "1" OR _sapi_GENERATOR_VERSION VERSION_GREATER "3"))
101+
if(_sapi_GENERATOR_VERSION AND (_sapi_GENERATOR_VERSION VERSION_LESS "1" OR _sapi_GENERATOR_VERSION VERSION_GREATER "3"))
103102
message(FATAL_ERROR "GENERATOR_VERSION must be \"1\", \"2\" or \"3\"")
104103
endif()
105104

106-
if (_sapi_GENERATOR_VERSION)
105+
if(_sapi_GENERATOR_VERSION)
107106
set(_sapi_use_generator_version ${_sapi_GENERATOR_VERSION})
108107
else()
109-
if (SAPI_ENABLE_CLANG_TOOL)
108+
if(SAPI_ENABLE_CLANG_TOOL)
110109
set(_sapi_use_generator_version "2")
111110
else()
112111
set(_sapi_use_generator_version "1")
@@ -123,7 +122,7 @@ function(add_sapi_library)
123122
endif()
124123

125124
# The sandboxee client library.
126-
if (_sapi_use_generator_version VERSION_EQUAL "3")
125+
if(_sapi_use_generator_version VERSION_EQUAL "3")
127126
set(_sapi_sandboxee_client_target "${_sapi_NAME}_sandboxee_gen")
128127
add_library("${_sapi_sandboxee_client_target}" STATIC
129128
"${_sapi_gen_sandboxee_src}"
@@ -139,7 +138,7 @@ function(add_sapi_library)
139138
)
140139
set(_sapi_sandboxee_client_lib "${_sapi_sandboxee_client_target}")
141140
else()
142-
set (_sapi_sandboxee_client_lib "sapi::client_message_handler")
141+
set(_sapi_sandboxee_client_lib "sapi::client_message_handler")
143142
endif()
144143

145144
# The sandboxed binary
@@ -189,8 +188,10 @@ function(add_sapi_library)
189188
"--sapi_ns=${_sapi_NAMESPACE}"
190189
)
191190
if(_sapi_use_generator_version VERSION_GREATER_EQUAL "2")
192-
list(APPEND _sapi_generator_args "--sapi_api_version=${_sapi_API_VERSION}")
193-
if (_sapi_use_generator_version VERSION_EQUAL "3")
191+
if(_sapi_API_VERSION)
192+
list(APPEND _sapi_generator_args "--sapi_api_version=${_sapi_API_VERSION}")
193+
endif()
194+
if(_sapi_use_generator_version VERSION_EQUAL "3")
194195
list(APPEND _sapi_generator_args
195196
"--sapi_sandboxee_src_out=${_sapi_gen_sandboxee_src}"
196197
)

cmake/SapiDeps.cmake

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ if(SAPI_DOWNLOAD_ABSL)
6060
endif()
6161
sapi_check_target(absl::core_headers)
6262

63+
if(SAPI_DOWNLOAD_LIBUNWIND)
64+
include(cmake/libunwind.cmake)
65+
endif()
66+
sapi_check_target(unwind_ptrace)
67+
6368
if(SAPI_DOWNLOAD_LIBCAP)
6469
include(cmake/libcap.cmake)
6570
sapi_check_target(libcap::libcap)
@@ -74,16 +79,16 @@ else()
7479
find_package(Libffi REQUIRED)
7580
endif()
7681

77-
if(SAPI_DOWNLOAD_LIBUNWIND)
78-
include(cmake/libunwind.cmake)
79-
endif()
80-
sapi_check_target(unwind_ptrace)
81-
8282
if(SAPI_DOWNLOAD_PROTOBUF)
8383
include(cmake/protobuf.cmake)
8484
endif()
8585
find_package(Protobuf REQUIRED)
8686

87+
if(SAPI_DOWNLOAD_RE2)
88+
include(cmake/re2.cmake)
89+
endif()
90+
sapi_check_target(re2)
91+
8792
if(SAPI_BUILD_EXAMPLES)
8893
if(SAPI_DOWNLOAD_ZLIB)
8994
include(cmake/zlib.cmake)

cmake/SapiOptions.cmake

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ endif()
2828
# dependencies. This is useful for cases where embedding projects already
2929
# depend on some of these libraries (e.g. Abseil).
3030
option(SAPI_DOWNLOAD_ABSL "Download Abseil at config time" ON)
31-
option(SAPI_DOWNLOAD_GOOGLETEST "Download googletest at config time" ON)
3231
option(SAPI_DOWNLOAD_BENCHMARK "Download benchmark at config time" ON)
33-
option(SAPI_DOWNLOAD_PROTOBUF "Download protobuf at config time" ON)
34-
option(SAPI_DOWNLOAD_LIBUNWIND "Download libunwind at config time" ON)
32+
option(SAPI_DOWNLOAD_GOOGLETEST "Download googletest at config time" ON)
3533
option(SAPI_DOWNLOAD_LIBCAP "Download libcap at config time" ON)
3634
option(SAPI_DOWNLOAD_LIBFFI "Download libffi at config time" ON)
35+
option(SAPI_DOWNLOAD_LIBUNWIND "Download libunwind at config time" ON)
36+
option(SAPI_DOWNLOAD_PROTOBUF "Download protobuf at config time" ON)
37+
option(SAPI_DOWNLOAD_RE2 "Download re2 at config time" ON)
3738

3839
# Options for building examples
3940
option(SAPI_BUILD_EXAMPLES
@@ -51,9 +52,7 @@ option(SAPI_BUILD_TESTING
5152
# Disabled by default, as this will download a lot of extra content.
5253
option(SAPI_CONTRIB_BUILD_TESTING "Build tests for sandboxes in 'contrib'" OFF)
5354

54-
option(SAPI_ENABLE_CLANG_TOOL
55-
"Use the new Clang tool based header generator" OFF
56-
)
55+
option(SAPI_ENABLE_CLANG_TOOL "Use the Clang tool header generator" ON)
5756
option(SAPI_ENABLE_CLANG_TOOL_STATIC
5857
"Link the Clang libraries statically into the tool" OFF
5958
)

cmake/re2.cmake

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2026 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+
15+
FetchContent_Declare(re2
16+
URL https://github.com/google/re2/releases/download/2025-11-05/re2-2025-11-05.tar.gz
17+
URL_HASH SHA256=87f6029d2f6de8aa023654240a03ada90e876ce9a4676e258dd01ea4c26ffd67
18+
)
19+
set(RE2_INSTALL OFF CACHE BOOL "" FORCE)
20+
21+
FetchContent_MakeAvailable(re2)

sandboxed_api/tools/clang_generator/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ target_link_libraries(sapi_generator PUBLIC
115115
absl::status
116116
absl::statusor
117117
absl::strings
118+
re2
118119
sapi::fileops
119120
sapi::status
120121
${_sapi_generator_clang_libs}
@@ -163,6 +164,7 @@ if(BUILD_TESTING AND SAPI_BUILD_TESTING)
163164
sapi::file_helpers
164165
sapi::runfiles
165166
sapi::sapi
167+
sapi::testing
166168
sapi::generator
167169
sapi::status
168170
sapi::test_main

0 commit comments

Comments
 (0)