From e29e5cb1a22fed098fd7dfa5bcb621a85a6ebd4d Mon Sep 17 00:00:00 2001 From: Christian Blichmann Date: Tue, 14 Jun 2022 05:41:29 -0700 Subject: [PATCH] GitHub Actions: Add libzip and tests - Update Sandbox policy - Compile libzip wrapper functions as part of libzip in CMake PiperOrigin-RevId: 454837665 Change-Id: Ife6cc99296873e030b9613959eff88d4b0746a5e --- .github/workflows/ubuntu-cmake-contrib.yml | 1 + contrib/libzip/CMakeLists.txt | 76 +++++++++++----------- contrib/libzip/example/CMakeLists.txt | 12 ++-- contrib/libzip/sandboxed.h | 7 +- contrib/libzip/test/CMakeLists.txt | 19 ++---- contrib/libzip/wrapper/CMakeLists.txt | 13 ++-- contrib/libzip/wrapper/wrapper_zip.h | 1 + 7 files changed, 60 insertions(+), 69 deletions(-) diff --git a/.github/workflows/ubuntu-cmake-contrib.yml b/.github/workflows/ubuntu-cmake-contrib.yml index 5ba4bdd..6bb4c5e 100644 --- a/.github/workflows/ubuntu-cmake-contrib.yml +++ b/.github/workflows/ubuntu-cmake-contrib.yml @@ -19,6 +19,7 @@ jobs: - libraw - libtiff - libxls + - libzip - lodepng - pffft ignore-errors: [true] diff --git a/contrib/libzip/CMakeLists.txt b/contrib/libzip/CMakeLists.txt index 6363581..5b587d5 100644 --- a/contrib/libzip/CMakeLists.txt +++ b/contrib/libzip/CMakeLists.txt @@ -12,10 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.13) +cmake_minimum_required(VERSION 3.13..2.22) project(sapi_zip CXX) include(CTest) +include(GoogleTest) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED True) @@ -35,61 +36,60 @@ set(BUILD_DOC OFF CACHE BOOL "" FORCE) set(LIBZIP_DO_INSTALL OFF CACHE BOOL "" FORCE) FetchContent_Declare(libzip GIT_REPOSITORY https://github.com/nih-at/libzip/ - GIT_TAG 34b13ca4e887a5aba050015e3a179069643f4e76 + GIT_TAG e076a6fd97663025785a64cc8160aa633220be61 # 2022-06-08 ) FetchContent_MakeAvailable(libzip) -include_directories("${libzip_BINARY_DIR}") - add_subdirectory(wrapper) -add_sapi_library( - sapi_zip +add_sapi_library(sapi_zip + FUNCTIONS zip_open_from_source + zip_close - FUNCTIONS - zip_open_from_source - zip_close + zip_get_name + zip_get_num_entries - zip_get_name - zip_get_num_entries + zip_stat + zip_stat_index - zip_stat - zip_stat_index + zip_fopen + zip_fopen_index + zip_fclose - zip_fopen - zip_fopen_index - zip_fclose + zip_fread + zip_fseek + zip_ftell - zip_fread - zip_fseek - zip_ftell + zip_source_buffer + zip_read_fd_to_source + zip_source_to_fd + zip_source_filefd + zip_source_filefd_create + zip_source_keep + zip_source_free - zip_source_buffer - zip_read_fd_to_source - zip_source_to_fd - zip_source_filefd - zip_source_filefd_create - zip_source_keep - zip_source_free + zip_file_add + zip_file_replace + zip_delete - zip_file_add - zip_file_replace - zip_delete + zip_strerror + INPUTS "${libzip_BINARY_DIR}/zipconf.h" + "${libzip_SOURCE_DIR}/lib/zip.h" + wrapper/wrapper_zip.h - zip_strerror - INPUTS - "${libzip_BINARY_DIR}/zipconf.h" - "${libzip_SOURCE_DIR}/lib/zip.h" - "wrapper/wrapper_zip.h" - - LIBRARY wrapper_zip + LIBRARY libzip::zip LIBRARY_NAME Zip NAMESPACE "" ) add_library(sapi_contrib::libzip ALIAS sapi_zip) -target_include_directories(sapi_zip INTERFACE +target_include_directories(sapi_zip PUBLIC "${PROJECT_BINARY_DIR}" - "${SAPI_SOURCE_DIR}" + "${libzip_BINARY_DIR}" +) +target_sources(sapi_zip PUBLIC + sandboxed.h + utils/utils_zip.cc + utils/utils_zip.h ) if(SAPI_BUILD_EXAMPLES) diff --git a/contrib/libzip/example/CMakeLists.txt b/contrib/libzip/example/CMakeLists.txt index 60519c1..4037c7f 100644 --- a/contrib/libzip/example/CMakeLists.txt +++ b/contrib/libzip/example/CMakeLists.txt @@ -14,12 +14,10 @@ add_executable(sapi_minizip main.cc - ../utils/utils_zip.cc ) - -target_link_libraries(sapi_minizip - PRIVATE sapi_contrib::libzip - sapi::logging - sapi::sapi - absl::flags_parse +target_link_libraries(sapi_minizip PRIVATE + sapi_contrib::libzip + sapi::logging + sapi::sapi + absl::flags_parse ) diff --git a/contrib/libzip/sandboxed.h b/contrib/libzip/sandboxed.h index 795c8b6..7aa7aac 100644 --- a/contrib/libzip/sandboxed.h +++ b/contrib/libzip/sandboxed.h @@ -20,9 +20,9 @@ #include -// Note: This header is required because of the bug in generator. The generator -// for some reason doesn't catch the types defined by zip (for example -// zip_uint32_t). +// Note: This header is required because to work around an issue with the +// libclang based header generator, which doesn't catch the types +// defined by zip (for example zip_uint32_t). #include // NOLINT(build/include_order) #include "sapi_zip.sapi.h" // NOLINT(build/include) @@ -36,6 +36,7 @@ class ZipSapiSandbox : public ZipSandbox { .AllowRead() .AllowWrite() .AllowSystemMalloc() + .AllowGetPIDs() .AllowExit() .AllowSafeFcntl() .AllowSyscalls({ diff --git a/contrib/libzip/test/CMakeLists.txt b/contrib/libzip/test/CMakeLists.txt index c416a05..ce0282a 100644 --- a/contrib/libzip/test/CMakeLists.txt +++ b/contrib/libzip/test/CMakeLists.txt @@ -12,22 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -include(GoogleTest) - -add_executable( - sapi_zip_test - +add_executable(sapi_zip_test test_zip.cc - ../utils/utils_zip.cc ) - - -target_link_libraries( - sapi_zip_test PRIVATE - - sapi_zip +target_link_libraries(sapi_zip_test PRIVATE + sapi_contrib::libzip sapi::temp_file sapi::test_main ) -gtest_discover_tests(sapi_zip_test PROPERTIES ENVIRONMENT "TEST_FILES_DIR=${PROJECT_SOURCE_DIR}/files") +gtest_discover_tests(sapi_zip_test PROPERTIES + ENVIRONMENT "TEST_FILES_DIR=${PROJECT_SOURCE_DIR}/files" +) diff --git a/contrib/libzip/wrapper/CMakeLists.txt b/contrib/libzip/wrapper/CMakeLists.txt index 41ab439..fe5e7dc 100644 --- a/contrib/libzip/wrapper/CMakeLists.txt +++ b/contrib/libzip/wrapper/CMakeLists.txt @@ -12,15 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -add_library(wrapper_zip STATIC +# Directly compile the wrapper sources as part of the libzip archive +target_sources(zip PRIVATE wrapper_zip.cc + wrapper_zip.h ) -target_link_libraries(wrapper_zip PUBLIC - libzip::zip - +target_link_libraries(zip PRIVATE + absl::cleanup sapi::sapi ) -target_include_directories(wrapper_zip PUBLIC - "${SAPI_SOURCE_DIR}" - "${libzip_SOURCE_DIR}/lib/" -) diff --git a/contrib/libzip/wrapper/wrapper_zip.h b/contrib/libzip/wrapper/wrapper_zip.h index 00a4c0c..fa1672e 100644 --- a/contrib/libzip/wrapper/wrapper_zip.h +++ b/contrib/libzip/wrapper/wrapper_zip.h @@ -16,6 +16,7 @@ #define CONTRIB_LIBZIP_WRAPPER_WRAPPER_ZIP_H_ #include +#include extern "C" {