Commit Graph

86 Commits (main)

Author SHA1 Message Date
Christian Blichmann 00e724fb8a CMake build improvements
- Try to fix Ninja needlessly rebuilding everything every time
  See https://stackoverflow.com/questions/47087237/cmake-and-ninja-rebuild-unnecessary-files/47100426#47100426
- Since SAPI requires CMake >= 3.12, remove custom `list_join`

PiperOrigin-RevId: 333281764
Change-Id: I334d67d7ee54d21824b19e60a7a7f1e43bb5a057
2020-09-23 06:43:01 -07:00
Christian Blichmann 13c28403a6 Implement system include detection for CMake build
The Bazel build already queries the current toolchain for its system include
directories. This change brings feature parity and is necessary for systems
with unusual include locations.

PiperOrigin-RevId: 332195812
Change-Id: Ie81d614d21e90b4bd9edf2084ef80bf0d85dd750
2020-09-17 03:08:11 -07:00
Christian Blichmann fdf0483ca0 Migrate to open-source `absl::StatusOr<>`
This removes our own fork of `absl::StatusOr<>`. Sandboxed API still includes
a custom matcher for Googletest, as that is not open source yet. For
compatibility, the `statusor.h` header is still retained and now aliases
`sapi::StatusOr<>` to `absl::StatusOr<>`.

PiperOrigin-RevId: 329916309
Change-Id: I0544b73a9e312dce499bc4128c28457e04ab9929
2020-09-03 07:40:48 -07:00
Wiktor Garbacz e9f7293e21 Fix ptrace_hook dependency graph
PiperOrigin-RevId: 321748143
Change-Id: Idb453054b78e932ce13c5f44f7d408cc0f9c31f2
2020-07-17 03:20:43 -07:00
Christian Blichmann a574b66e99 Do not add third_party test targets in CMake build
This way, one can just run `ctest .` in the build directory and it will only
run Sandboxed API and Sandbox2 tests.

PiperOrigin-RevId: 321342543
Change-Id: I42537e64bfb3127dca00bd92a3f7b35ca64004d9
2020-07-15 05:31:50 -07:00
Christian Blichmann a51c275a3a Avoid arch names in libffi build directories
This is done by simply building libffi in-tree. Normally, this is not
desirable, but in our case is actually ok, as this is an external
dependency to be pulled in and cleaning the source tree is easy in this
case.

Signed-off-by: Christian Blichmann <mail@blichmann.eu>
2020-06-30 08:59:50 +02:00
Christian Blichmann 2ffea13759 Mark zlib as found when using SAPI CMake build
Signed-off-by: Christian Blichmann <mail@blichmann.eu>
2020-06-30 08:59:50 +02:00
Christian Blichmann ae473c4bd1
Fix build issue if an incompatible local version of libunwind is
installed.
2020-05-15 15:36:09 +02:00
Christian Blichmann 143e539d79 First MVP of a LibTooling based SAPI header generator
- Extract dependent types directly from the Clang AST and re-serialize
  back into compilable code
- Collect types and emit diagnostics
- Format generated code

Signed-off-by: Christian Blichmann <mail@blichmann.eu>
2020-05-15 15:35:42 +02:00
Christian Blichmann d6b8e0b3e3 CMake: Fix inclusion and paths for external embedding
When using SAPI from an external project via CMake, the small zlib patch
cannot be found during the config phase.

This change also fixes an oversight in that the tests depend on some of
the example code.

Regardless embedding code should set `SAPI_ENABLE_EXAMPLES` to `OFF`.
Disabling tests by setting `SAPI_ENABLE_TESTS` to `OFF` stays optional.

PiperOrigin-RevId: 311290454
Change-Id: Ibe105895859b793b20f47c89b1a9e11cbfef2e2f
2020-05-13 02:09:33 -07:00
Christian Blichmann aafc597630 Add zlib as dependency for examples
Similar to what the Bazel build does, this change adds zlib as an additional
dependency when `SAPI_ENABLE_EXAMPLES` is set to `ON`.

PiperOrigin-RevId: 309203959
Change-Id: I201a9e6415789afb1e058bc48cebbc0fc0004fe9
2020-04-30 04:57:33 -07:00
Christian Blichmann fea5e8c485 CMake: Avoid Google Test error when re-configuring with latest Abseil
Abseil insists on having a Google Test directory, even if we're not going to
run (or even build) the tests.

This changes forces all test settings to `OFF` just for Abseil, allowing
SAPI builds to complete normally. Embedding projects should not be affected,
if they already included Abseil.

PiperOrigin-RevId: 309035680
Change-Id: Ie46297d8b502d92d0c10ef04360e992bcee4964b
2020-04-29 09:17:26 -07:00
Christian Blichmann 7ec20bd5d5 Update dependencies to latest versions
- Abseil (HEAD)
- Benchmark (HEAD)
- Google Flags (HEAD)
- Google Logging (HEAD)
- Google Test/Mock (HEAD)
- Protocol Buffers (3.11.4)

PiperOrigin-RevId: 309012925
Change-Id: I826846afb3f2c4e92180915796890fce6b5a1d6c
2020-04-29 06:45:44 -07:00
Christian Blichmann 57d374e667 Fix libffi configure directory in Bazel/CMake builds 2020-03-23 13:52:02 +01:00
Christian Blichmann 0772d71264 Download libffi at CMake config time (fixes #35)
Drive-by:
- Make Bazel config action more robust
- Disable dependency tracking in libunwind configure

Signed-off-by: Christian Blichmann <mail@blichmann.eu>
2020-03-22 16:44:39 +01:00
Christian Blichmann f44cca6c98 Fix path to generated proto sources when embedding
When embedding SAPI in an external CMake project, the version of
`protobuf_generate_cpp` that we lifted from upstream protobuf produces
the wrong generated file paths.

For example, given this project structure:

```
/parent/
+-- myproject/
+-- myproject_build/  <- CMake build directory
+-- sandboxed-api/    <- Checkout from GitHub
```

And a CMake file in `myproject/CMakeLists.txt` that embeds SAPI like
this:

```
cmake_minimum_required(VERSION 3.12)
project(SandboxedTest LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_subdirectory(
  ${PROJECT_SOURCE_DIR}/../sandboxed-api
  ${PROJECT_BINARY_DIR}/sandboxed-api
)
```

Then `protobuf_generate_cpp` correctly invokes the protoc compiler to
generate
`/parent/myproject_build/sandboxed-api/sandboxed_api/proto_arg.proto.pb.cc'.
However, the path of the generated source file that is passed to the C++
compiler will be
`/parent/myproject_build/sandboxed-api/sandboxed_api/../../myproject_build/sandboxed-api/sandboxed_api/proto_arg.pb.cc`.
Note the duplicated project build directory component in the
canonicalized version:
`/parent/myproject_build/myproject_build/sandboxed-api/sandboxed_api/proto_arg.pb.cc`.

This change simple omits the computation of any relative file paths and
simply uses `_pb_PROTOC_OUT_DIR` which defauls to
`CMAKE_CURRENT_BINARY_DIR`, which should always contain the correct
path.

Signed-off-by: Christian Blichmann <mail@blichmann.eu>
2020-03-18 18:47:02 +01:00
Christian Blichmann 509c7bca94 Cache the location of Python 3 interpreter
Add the location of the Python 3 interpreter to the CMake cache so
that its available in the `add_sapi_library()` macro in downstream
embedding projects.

Signed-off-by: Christian Blichmann <mail@blichmann.eu>
2020-03-17 21:26:14 +01:00
Christian Blichmann f6c3db4c6e Replace sapi::Status with absl::Status
PiperOrigin-RevId: 297614681
Change-Id: I89fe1357a172ed4d28df6dd84b80fee364ce1c14
2020-02-27 09:24:12 -08:00
Christian Blichmann 441201884a Update license header with recommended best practices
PiperOrigin-RevId: 290250533
Change-Id: Ic34b253446463cf971a055b70a242df93a598ee3
2020-01-17 05:05:29 -08:00
Christian Blichmann e7eb1f97a3 Download and build libcap along with other dependencies when using CMake
PiperOrigin-RevId: 282353228
Change-Id: I3175949556b2468eb252bc618e6c6d10a8ada68f
2019-11-25 07:30:40 -08:00
Christian Blichmann 4f892864c8 Update dependencies to newer version
- Same upstream dependency versions for CMake and Bazel
- Use maybe() from build_defs to conditionally define Bazel repositories

PiperOrigin-RevId: 282331418
Change-Id: I8a7db84a1d3115f3c1f31cc1dfcc8c29fe391a62
2019-11-25 04:32:01 -08:00
Christian Blichmann 948b75efe9 CMake cleanups
- Bump minimum requred version to 3.12 (Ubuntu Cosmic LTS)
- Rename `SAPI_USE_?` options to `SAPI_DOWNLOAD_?`
- Improve detection of Python 3
- Use platform independent static library suffixes for `find_library()`

PiperOrigin-RevId: 281727467
Change-Id: I45596b6ba08e4f8201d8dcde19a03baf825b83ec
2019-11-21 05:17:25 -08:00
Christian Blichmann d47c066112 Enable sapi_test target in CMake, add Benchmark dependency
PiperOrigin-RevId: 281719298
Change-Id: Idd2570fff4907c81cdab1070bd1f3e41e29c76f6
2019-11-21 04:04:14 -08:00
Christian Blichmann d91879f752 Ensure compatibility with CMake 3.10
This fixes some CMake-3.12+-isms, like `list(JOIN ...)` and setting link
properties on OBJECT libraries.

PiperOrigin-RevId: 265033725
Change-Id: I0ee1ec0e1b1097ea8226ad6fdeff794a97c2881b
2019-08-23 05:08:55 -07:00
Christian Blichmann c966f21109 Improve handling of protobuf dependency
PiperOrigin-RevId: 264631771
Change-Id: I341fd31ee7acd3f7748b1f0cada5fcd9d27341a7
2019-08-21 10:01:12 -07:00
Christian Blichmann 3c51348aaf Enable CMake projects to consume Sandboxed API via add_subdirectory()
This change moves away from a classical superbuild which downloads and builds
at build time. Instead, we now follow a "Fetch Content" workflow (available as
FetchContent in CMake 3.11+) and download dependencies at config time.

Rationale: Superbuild projects have the disadvantage that projects cannot
directly access their individual declared targets. This is not a problem with
regular libraries, as those are usually/supposed to be installed. With
Sandboxed API, this is not desirable, as it has dependencies like Abseil and
glog, which are almost always consumed by including their source tree using
add_subdirectory().

Fixes #10 and makes external embedding easier.

PiperOrigin-RevId: 260129870
Change-Id: I70f295f29a6e4fc8c330512c94b01ef10c017166
2019-07-26 05:51:08 -07:00
Christian Blichmann 6d33c1f908 Add CMake options to exclude examples and tests from build
PiperOrigin-RevId: 258136393
Change-Id: Ifb2d7a24f93cd1d2782b4e4d6ac2c34a0d1c2bff
2019-07-15 04:42:58 -07:00
Christian Blichmann 99ac7fa60d Refactor CMake files
* Move add_sapi_library() into a build defs file
* Override protobuf_generate_cpp() instead of naming it sapi_protobuf_generate_cpp()
* Factor out inclusion/find_package() calls of external dependencies

PiperOrigin-RevId: 258133422
Change-Id: Ibdbab0c735157eac0ed6122ab78f9d583c6905cc
2019-07-15 04:13:15 -07:00
Christian Blichmann b219661be0 Add basic CMake support for SAPI, build examples
* Implement add_sapi_library() similar to the Bazel rule
* Fix SuperBuild so that glog properly depends on gflags (needed for --logtostderr)
* Raise minimum required version of CMake to 3.10 (Ubuntu 18.04 LTS)
* Update sum sandbox policy to allow to get IDs and PIDs

PiperOrigin-RevId: 258124160
Change-Id: I64c2f8b27a3e842874adca9100bfce20a2b74f17
2019-07-15 02:53:43 -07:00
Christian Blichmann 25709ee4cc Add missing FindLibffi.cmake
PiperOrigin-RevId: 257378727
Change-Id: Ib1a6b6734a56280ff5dc9cc75380fcb9b9f51197
2019-07-10 04:39:47 -07:00
Christian Blichmann b5d85f5e56 Do not use any global compiler settings in CMake build
This change also tries to make the build more idempotent wrt to embedding projects.

PiperOrigin-RevId: 257177255
Change-Id: I291cd02840496db901f829e902623887f6e0eb10
2019-07-09 06:12:11 -07:00
Christian Blichmann 4e20e0702a Use full workspace name to access Bazel packages in generator
Since the interface generator is invoked via a Bazel macro, it will be
expanded in the embedding context of the project using SAPI, so package access
needs to go through the full workspace root @com_google_sandboxed_api.

This change also modifies the CMakeLists.txt accordingly, as the "external"
subdirectory is no longer needed/wanted.

PiperOrigin-RevId: 255918784
Change-Id: I052c687509f65fef7f011a9d1a074a171595330f
2019-07-01 02:53:41 -07:00
Christian Blichmann 65440dddd6 Update to latest Google Test
PiperOrigin-RevId: 251640007
Change-Id: Ied7b1c07c49c6574bc26591902c520a53b56b658
2019-06-05 07:40:13 -07:00
Christian Blichmann e09bda2628 Internal change
PiperOrigin-RevId: 251624033
Change-Id: I9b2ab423082be3bfdb6da66ab7a8e77e5673789b
2019-06-05 05:28:56 -07:00
Christian Blichmann 5f3c7171b7 Use Abseil's flag library released in aa468ad75539619b47979911297efbb629c52e44
PiperOrigin-RevId: 247424939
Change-Id: I22a4696f705f9dcfa7394b329c78bd126f42bd16
2019-05-09 07:57:55 -07:00
Christian Blichmann 6bfa83befe CMake support for Sandbox2
- Add a superbuild in cmake/SuperBuild.cmake that downloads and builds
  dependencies
- Builds for sandbox2/ and a its tests
- Helper CMake function to strip proto paths
- Module to find libcap
- Custom build for libunwind that wraps its symbols
- Fix environment so that CTest executes tests similar to Bazel
- Filewrapper functionality, like Bazel's cc_embed_data()
- Build forkserver with embedded binary
- Enable ASM language so that libunwind builds correctly
- Allow glog target to propagate transitively (to propagate its include dirs)

Signed-off-by: Christian Blichmann <cblichmann@google.com>
2019-05-06 14:03:29 +02:00