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
This commit is contained in:
Christian Blichmann 2022-06-14 05:41:29 -07:00 committed by Copybara-Service
parent 3cb19e7378
commit e29e5cb1a2
7 changed files with 60 additions and 69 deletions

View File

@ -19,6 +19,7 @@ jobs:
- libraw
- libtiff
- libxls
- libzip
- lodepng
- pffft
ignore-errors: [true]

View File

@ -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)

View File

@ -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
)

View File

@ -20,9 +20,9 @@
#include <memory>
// 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 <zipconf.h> // 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({

View File

@ -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"
)

View File

@ -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/"
)

View File

@ -16,6 +16,7 @@
#define CONTRIB_LIBZIP_WRAPPER_WRAPPER_ZIP_H_
#include <zip.h>
#include <zipconf.h>
extern "C" {