GitHub Actions: Add libidn2 and tests

PiperOrigin-RevId: 454784764
Change-Id: Id8de7f34a0a5e0236f2fb92841e117cdcf386d2c
This commit is contained in:
Christian Blichmann 2022-06-14 00:04:54 -07:00 committed by Copybara-Service
parent 2a65b72ea6
commit 45d4b1ba5b
3 changed files with 27 additions and 6 deletions

View File

@ -15,6 +15,7 @@ jobs:
- brotli
- c-blosc
- jsonnet
- libidn2
- libraw
- libtiff
- lodepng
@ -63,6 +64,11 @@ jobs:
echo "CXX=g++-${{matrix.compiler-version}}" >> $GITHUB_ENV
echo "CC=gcc-${{matrix.compiler-version}}" >> $GITHUB_ENV
- name: Install extra dependencies for contrib
if: matrix.contrib == 'libidn2'
run: |
sudo apt-get install -qy libidn2-dev libunistring-dev
- name: Create Build Environment
run: |
pip3 install absl-py clang

View File

@ -16,6 +16,7 @@ cmake_minimum_required(VERSION 3.13..3.22)
project(libidn2-sapi CXX C)
include(CTest)
include(GoogleTest)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
@ -28,22 +29,33 @@ if(NOT TARGET sapi::sapi)
EXCLUDE_FROM_ALL)
endif()
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBIDN2 REQUIRED IMPORTED_TARGET libidn2)
# System libidn2 needs to have the libidn2-dev and libunistring-dev packages
# installed. We cannot use pkg-config here, as libidn2's config file does not
# support static linking.
find_library(libidn2 NAMES libidn2.a idn2)
find_library(libunistring NAMES libunistring.a unistring)
# Combine libidn2 and its dependency into a single static library
add_library(idn2_static STATIC
"${SAPI_BINARY_DIR}/sapi_force_cxx_linkage.cc"
)
target_link_libraries(idn2_static PUBLIC
"-Wl,--whole-archive,${libidn2},--no-whole-archive"
"-Wl,--whole-archive,${libunistring},--no-whole-archive"
)
add_sapi_library(libidn2_sapi
FUNCTIONS idn2_lookup_u8 idn2_register_u8
idn2_strerror idn2_strerror_name
idn2_free idn2_to_ascii_8z
idn2_to_unicode_8z8z
INPUTS "${LIBIDN2_INCLUDEDIR}/idn2.h"
LIBRARY idn2
INPUTS "${libidn2_INCLUDEDIR}/idn2.h"
LIBRARY idn2_static
LIBRARY_NAME IDN2
NAMESPACE ""
)
target_include_directories(libidn2_sapi INTERFACE
"${PROJECT_BINARY_DIR}"
"${SAPI_SOURCE_DIR}"
)
add_library(libidn2_sapi_wrapper

View File

@ -22,6 +22,7 @@
#include "libidn2_sapi.sapi.h" // NOLINT(build/include)
#include "sandboxed_api/util/fileops.h"
class Idn2SapiSandbox : public IDN2Sandbox {
public:
std::unique_ptr<sandbox2::Policy> ModifyPolicy(
@ -32,12 +33,13 @@ class Idn2SapiSandbox : public IDN2Sandbox {
.AllowStat()
.AllowWrite()
.AllowExit()
.AllowGetPIDs()
.AllowSyscalls({
__NR_futex,
__NR_close,
__NR_lseek,
__NR_getpid,
})
.BlockSyscallWithErrno(__NR_openat, ENOENT)
.BuildOrDie();
}
};
@ -62,4 +64,5 @@ class IDN2Lib {
Idn2SapiSandbox* sandbox_;
IDN2Api api_;
};
#endif // CONTRIB_LIBIDN2_LIBIDN2_SAPI_H_