Skip to content

Commit

Permalink
cmake: use TARGET_OBJECTS to import object library
Browse files Browse the repository at this point in the history
- test load system ca on linux/openwrt/alpine
  • Loading branch information
Chilledheart committed Jul 23, 2024
1 parent f4057af commit 716aa65
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 32 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/releases-android-binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,19 +210,22 @@ jobs:
if: ${{ matrix.arch == 'x86' || matrix.arch == 'x64' }}
run: |
# android sysimg doesn't like resolv.conf
mkdir -p $SYSROOT/etc/ssl/certs $SYSROOT/dev $SYSROOT/proc $SYSROOT/data/local/tmp
mkdir -p $SYSROOT/etc/ssl/certs $SYSROOT/dev $SYSROOT/proc $SYSROOT/data/local/tmp $SYSROOT/build
bwrap --die-with-parent --ro-bind $SYSROOT / \
--ro-bind /sys /sys \
--ro-bind /etc/ssl/certs /etc/ssl/certs \
--proc /proc --dev /dev \
--unshare-all --share-net \
--bind $PWD/build-android${{ matrix.apilevel }}-${{ matrix.arch }} /data/local/tmp \
/data/local/tmp/yass_test
--bind /tmp /data/local/tmp \
--bind $PWD/build-android${{ matrix.apilevel }}-${{ matrix.arch }} /build \
/build/yass_test
- name: Run tests (non x86, under qemu emulation)
if: ${{ matrix.arch != 'x86' && matrix.arch != 'x64' }}
run: |
# required by leveldb unittests
# tmpfs is required by leveldb unittests
rm -rf $SYSROOT/data/local/tmp
mkdir -p $SYSROOT/data/local/tmp
ln -sf /tmp $SYSROOT/data/local/
qemu-${{ matrix.qemu_suffix }}-static -L $SYSROOT \
-E TMPDIR=$SYSROOT/data/local/tmp \
$PWD/build-android${{ matrix.apilevel }}-${{ matrix.arch }}/yass_test
Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/releases-linux-binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,26 @@ jobs:
- name: Run tests (i386 and amd64)
if: ${{ matrix.arch == 'i386' || matrix.arch == 'amd64' }}
run: |
mkdir -p $SDK_ROOT/etc $SDK_ROOT/dev $SDK_ROOT/proc $SDK_ROOT/tmp
rm -rf $SDK_ROOT/tmp
mkdir -p $SDK_ROOT/etc/ssl/certs $SDK_ROOT/dev $SDK_ROOT/proc $SDK_ROOT/tmp $SDK_ROOT/build
touch $SDK_ROOT/etc/resolv.conf
bwrap --die-with-parent --bind $SDK_ROOT / \
--ro-bind /sys /sys \
--ro-bind /etc/resolv.conf /etc/resolv.conf \
--ro-bind /etc/ssl/certs /etc/ssl/certs \
--proc /proc --dev /dev \
--unshare-all --share-net \
--bind $PWD/build-linux-${{ matrix.arch }} /tmp \
/tmp/yass_test
--bind /tmp /tmp \
--bind $PWD/build-linux-${{ matrix.arch }} /build \
/build/yass_test
- name: Run tests (non x86, under qemu emulation)
if: ${{ matrix.arch != 'i386' && matrix.arch != 'amd64' }}
run: |
rm -rf $SDK_ROOT/tmp
ln -sf /tmp $SDK_ROOT/
qemu-${{ matrix.qemu_suffix }}-static -L $SDK_ROOT \
$PWD/build-linux-${{ matrix.arch }}/yass_test \
-E TMPDIR=$SDK_ROOT/tmp \
--no_exec_proc_tests
- name: Upload dist tarball (including debuginfo)
if: ${{ github.event_name == 'release' }}
Expand Down
17 changes: 12 additions & 5 deletions .github/workflows/releases-openwrt-binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,27 @@ jobs:
- name: Run tests (x86 and x86_64)
if: ${{ matrix.arch_name == 'x86' || matrix.arch_name == 'x86_64' }}
run: |
mkdir -p ${{ env.SDK_ROOT }}/etc/ssl/certs ${{ env.SDK_ROOT }}/dev ${{ env.SDK_ROOT }}/proc ${{ env.SDK_ROOT }}/tmp
touch ${{ env.SDK_ROOT }}/etc/resolv.conf
bwrap --die-with-parent --ro-bind ${{ env.SDK_ROOT }} / \
rm -rf $SDK_ROOT/tmp
mkdir -p $SDK_ROOT/etc/ssl/certs $SDK_ROOT/dev $SDK_ROOT/proc $SDK_ROOT/tmp $SDK_ROOT/build
touch $SDK_ROOT/etc/resolv.conf
bwrap --die-with-parent --ro-bind $SDK_ROOT / \
--ro-bind /etc/resolv.conf /etc/resolv.conf \
--ro-bind /etc/ssl/certs /etc/ssl/certs \
--proc /proc --dev /dev \
--unshare-all --share-net \
--bind $PWD/build-linux-openwrt-${{ matrix.arch }} /tmp \
/tmp/yass_test
--bind /tmp /tmp \
--bind $PWD/build-linux-openwrt-${{ matrix.arch }} /build \
/build/yass_test
- name: Run tests (non x86, under qemu emulation)
if: ${{ matrix.arch_name != 'x86' && matrix.arch_name != 'x86_64' }}
run: |
mkdir -p $SDK_ROOT/etc/ssl
ln -sf /etc/ssl/certs $SDK_ROOT/etc/ssl/
rm -rf $SDK_ROOT/tmp
ln -sf /tmp $SDK_ROOT/
qemu-${{ matrix.qemu_suffix }}-static -L $SDK_ROOT \
$PWD/build-linux-openwrt-${{ matrix.arch }}/yass_test \
-E TMPDIR=$SDK_ROOT/tmp \
--no_exec_proc_tests
- name: Upload dist tarball (including debuginfo)
if: ${{ github.event_name == 'release' }}
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/releases-rpm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,15 @@ jobs:
./tools/build --variant gui --arch ${{ matrix.arch }} --system linux --subsystem musl --sysroot "${{ env.SDK_ROOT }}" -build-test --cmake-build-type MinSizeRel -nc
- name: Run tests
run: |
bwrap --die-with-parent --bind "${{ env.SDK_ROOT }}" / \
mkdir -p $SDK_ROOT/build
bwrap --die-with-parent --bind "$SDK_ROOT" / \
--ro-bind /sys /sys \
--ro-bind /etc/resolv.conf /etc/resolv.conf \
--proc /proc --dev /dev \
--unshare-all --share-net \
--bind $PWD/build-linux-musl-${{ matrix.arch }} /tmp \
/tmp/yass_test
--bind /tmp /tmp \
--bind $PWD/build-linux-musl-${{ matrix.arch }} /build \
/build/yass_test
- name: Upload dist tarball (including debuginfo)
if: ${{ github.event_name == 'release' }}
env:
Expand Down
29 changes: 14 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3079,11 +3079,12 @@ if (USE_BUILTIN_CA_BUNDLE_CRT)
endif()

add_library(asio_ca_bundle_crt OBJECT ${ASIO_CA_BUNDLE_CRT_SRC})
target_compile_definitions(asio_ca_bundle_crt PUBLIC HAVE_BUILTIN_CA_BUNDLE_CRT=1)
target_include_directories(asio_ca_bundle_crt PRIVATE third_party/ca-certificates)

list(APPEND YASS_APP_FEATURES "ca-certificates 20240203.3.98")
target_link_libraries(asio PUBLIC asio_ca_bundle_crt)
# macro used in yass_test
target_compile_definitions(asio PUBLIC HAVE_BUILTIN_CA_BUNDLE_CRT=1)
target_sources(asio PRIVATE $<TARGET_OBJECTS:asio_ca_bundle_crt>)
endif()

#
Expand Down Expand Up @@ -3127,7 +3128,7 @@ endif()
add_library(asio_supplementary_ca_bundle_crt OBJECT ${ASIO_SUPPLEMENARY_CA_BUNDLE_CRT_SRC})
target_include_directories(asio_supplementary_ca_bundle_crt PRIVATE third_party/ca-certificates)

target_link_libraries(asio PRIVATE asio_supplementary_ca_bundle_crt)
target_sources(asio PRIVATE $<TARGET_OBJECTS:asio_supplementary_ca_bundle_crt>)

set(SUPPORT_LIBS asio ${SUPPORT_LIBS})

Expand Down Expand Up @@ -4226,6 +4227,7 @@ target_link_libraries(yass_cli_lib PUBLIC yass_net)
if (CLI)
add_executable(yass_cli
src/cli/cli.cpp
$<TARGET_OBJECTS:yass_cli_nogui_lib>
)
minject_patch_exetuable(yass_cli)
if (USE_LTO_CMAKE)
Expand All @@ -4251,10 +4253,7 @@ if (CLI)
target_include_directories(yass_cli PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src)

target_link_libraries(yass_cli PUBLIC
yass_cli_nogui_lib
yass_net
)
target_link_libraries(yass_cli PUBLIC yass_net)

if (NOT CMAKE_SKIP_INSTALL_RULES AND NOT WIN32 AND NOT IOS)
install(TARGETS yass_cli RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
Expand Down Expand Up @@ -4286,6 +4285,7 @@ target_link_libraries(yass_server_lib PUBLIC yass_net)
if (SERVER)
add_executable(yass_server
src/server/server.cpp
$<TARGET_OBJECTS:yass_server_lib>
)
minject_patch_exetuable(yass_server)
if (USE_LTO_CMAKE)
Expand All @@ -4311,10 +4311,7 @@ if (SERVER)
target_include_directories(yass_server PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src)

target_link_libraries(yass_server PUBLIC
yass_server_lib
yass_net
)
target_link_libraries(yass_server PUBLIC yass_net)

if (NOT CMAKE_SKIP_INSTALL_RULES AND NOT WIN32 AND NOT IOS)
install(TARGETS yass_server RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
Expand Down Expand Up @@ -4988,6 +4985,8 @@ if (BUILD_TESTS)
src/net/dns_message_test.cpp
src/net/doh_resolver_test.cpp
src/net/dot_resolver_test.cpp
$<TARGET_OBJECTS:yass_cli_nogui_lib>
$<TARGET_OBJECTS:yass_server_lib>
)

if (IOS)
Expand Down Expand Up @@ -5022,8 +5021,7 @@ if (BUILD_TESTS)
${CMAKE_CURRENT_SOURCE_DIR}/src/server
)
target_link_libraries(yass_test PUBLIC
yass_cli_nogui_lib
yass_server_lib
yass_net
yass_gtest
)
if (WIN32)
Expand Down Expand Up @@ -5132,6 +5130,8 @@ endif()
if (BUILD_BENCHMARKS)
set(yass_benchmark_SOURCE
src/ss_benchmark.cpp
$<TARGET_OBJECTS:yass_cli_nogui_lib>
$<TARGET_OBJECTS:yass_server_lib>
)
if (IOS)
enable_testing()
Expand Down Expand Up @@ -5166,8 +5166,7 @@ if (BUILD_BENCHMARKS)
${CMAKE_CURRENT_SOURCE_DIR}/src/server
)
target_link_libraries(yass_benchmark PUBLIC
yass_cli_nogui_lib
yass_server_lib
yass_net
benchmark::benchmark
)
if (WIN32)
Expand Down
5 changes: 3 additions & 2 deletions src/net/asio_ssl_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ TEST(SSL_TEST, LoadSystemCa) {
} else {
GTEST_SKIP() << "skipped as system version is too low";
}
#elif BUILDFLAG(IS_MAC) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_OHOS) || !defined(HAVE_BUILTIN_CA_BUNDLE_CRT)
#elif BUILDFLAG(IS_MAC) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_OHOS) || BUILDFLAG(IS_FREEBSD) || \
BUILDFLAG(IS_LINUX) || !defined(HAVE_BUILTIN_CA_BUNDLE_CRT)
ASSERT_NE(result, 0);
#else
// we don't test on openwrt
// we don't test on iOS
GTEST_SKIP() << "skipped as system is not supported";
#endif
}

0 comments on commit 716aa65

Please sign in to comment.