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 - libraw
- libtiff - libtiff
- libxls - libxls
- libzip
- lodepng - lodepng
- pffft - pffft
ignore-errors: [true] ignore-errors: [true]

View File

@ -12,10 +12,11 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
cmake_minimum_required(VERSION 3.13) cmake_minimum_required(VERSION 3.13..2.22)
project(sapi_zip CXX) project(sapi_zip CXX)
include(CTest) include(CTest)
include(GoogleTest)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True) 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) set(LIBZIP_DO_INSTALL OFF CACHE BOOL "" FORCE)
FetchContent_Declare(libzip FetchContent_Declare(libzip
GIT_REPOSITORY https://github.com/nih-at/libzip/ GIT_REPOSITORY https://github.com/nih-at/libzip/
GIT_TAG 34b13ca4e887a5aba050015e3a179069643f4e76 GIT_TAG e076a6fd97663025785a64cc8160aa633220be61 # 2022-06-08
) )
FetchContent_MakeAvailable(libzip) FetchContent_MakeAvailable(libzip)
include_directories("${libzip_BINARY_DIR}")
add_subdirectory(wrapper) add_subdirectory(wrapper)
add_sapi_library( add_sapi_library(sapi_zip
sapi_zip FUNCTIONS zip_open_from_source
zip_close
FUNCTIONS zip_get_name
zip_open_from_source zip_get_num_entries
zip_close
zip_get_name zip_stat
zip_get_num_entries zip_stat_index
zip_stat zip_fopen
zip_stat_index zip_fopen_index
zip_fclose
zip_fopen zip_fread
zip_fopen_index zip_fseek
zip_fclose zip_ftell
zip_fread zip_source_buffer
zip_fseek zip_read_fd_to_source
zip_ftell zip_source_to_fd
zip_source_filefd
zip_source_filefd_create
zip_source_keep
zip_source_free
zip_source_buffer zip_file_add
zip_read_fd_to_source zip_file_replace
zip_source_to_fd zip_delete
zip_source_filefd
zip_source_filefd_create
zip_source_keep
zip_source_free
zip_file_add zip_strerror
zip_file_replace INPUTS "${libzip_BINARY_DIR}/zipconf.h"
zip_delete "${libzip_SOURCE_DIR}/lib/zip.h"
wrapper/wrapper_zip.h
zip_strerror LIBRARY libzip::zip
INPUTS
"${libzip_BINARY_DIR}/zipconf.h"
"${libzip_SOURCE_DIR}/lib/zip.h"
"wrapper/wrapper_zip.h"
LIBRARY wrapper_zip
LIBRARY_NAME Zip LIBRARY_NAME Zip
NAMESPACE "" NAMESPACE ""
) )
add_library(sapi_contrib::libzip ALIAS sapi_zip) add_library(sapi_contrib::libzip ALIAS sapi_zip)
target_include_directories(sapi_zip INTERFACE target_include_directories(sapi_zip PUBLIC
"${PROJECT_BINARY_DIR}" "${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) if(SAPI_BUILD_EXAMPLES)

View File

@ -14,12 +14,10 @@
add_executable(sapi_minizip add_executable(sapi_minizip
main.cc main.cc
../utils/utils_zip.cc
) )
target_link_libraries(sapi_minizip PRIVATE
target_link_libraries(sapi_minizip sapi_contrib::libzip
PRIVATE sapi_contrib::libzip sapi::logging
sapi::logging sapi::sapi
sapi::sapi absl::flags_parse
absl::flags_parse
) )

View File

@ -20,9 +20,9 @@
#include <memory> #include <memory>
// Note: This header is required because of the bug in generator. The generator // Note: This header is required because to work around an issue with the
// for some reason doesn't catch the types defined by zip (for example // libclang based header generator, which doesn't catch the types
// zip_uint32_t). // defined by zip (for example zip_uint32_t).
#include <zipconf.h> // NOLINT(build/include_order) #include <zipconf.h> // NOLINT(build/include_order)
#include "sapi_zip.sapi.h" // NOLINT(build/include) #include "sapi_zip.sapi.h" // NOLINT(build/include)
@ -36,6 +36,7 @@ class ZipSapiSandbox : public ZipSandbox {
.AllowRead() .AllowRead()
.AllowWrite() .AllowWrite()
.AllowSystemMalloc() .AllowSystemMalloc()
.AllowGetPIDs()
.AllowExit() .AllowExit()
.AllowSafeFcntl() .AllowSafeFcntl()
.AllowSyscalls({ .AllowSyscalls({

View File

@ -12,22 +12,15 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
include(GoogleTest) add_executable(sapi_zip_test
add_executable(
sapi_zip_test
test_zip.cc test_zip.cc
../utils/utils_zip.cc
) )
target_link_libraries(sapi_zip_test PRIVATE
sapi_contrib::libzip
target_link_libraries(
sapi_zip_test PRIVATE
sapi_zip
sapi::temp_file sapi::temp_file
sapi::test_main 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 # See the License for the specific language governing permissions and
# limitations under the License. # 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.cc
wrapper_zip.h
) )
target_link_libraries(wrapper_zip PUBLIC target_link_libraries(zip PRIVATE
libzip::zip absl::cleanup
sapi::sapi 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_ #define CONTRIB_LIBZIP_WRAPPER_WRAPPER_ZIP_H_
#include <zip.h> #include <zip.h>
#include <zipconf.h>
extern "C" { extern "C" {