Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge static libs into libphoton.a automatically #186

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/ci.macos.arm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
runs-on: [self-hosted, macOS, ARM64]

steps:
- uses: szenius/set-timezone@v1.2
with:
timezoneLinux: "Asia/Shanghai"
timezoneMacos: "Asia/Shanghai"
timezoneWindows: "China Standard Time"
# - uses: szenius/set-timezone@v1.2
# with:
# timezoneLinux: "Asia/Shanghai"
# timezoneMacos: "Asia/Shanghai"
# timezoneWindows: "China Standard Time"

- uses: actions/checkout@v3

Expand Down
7 changes: 3 additions & 4 deletions CMake/build-from-src.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ function(build_from_src [dep])
set(BINARY_DIR ${PROJECT_BINARY_DIR}/uring-build)
ExternalProject_Add(
uring
GIT_REPOSITORY ${PHOTON_URING_SOURCE}
GIT_TAG liburing-2.3
GIT_PROGRESS ON
URL ${PHOTON_URING_SOURCE}
BUILD_IN_SOURCE ON
PATCH_COMMAND sed -ie "/L_CFLAGS=$/ s/=/=-fPIC $/" src/Makefile
CONFIGURE_COMMAND ./configure --prefix=${BINARY_DIR}
BUILD_COMMAND make -C src -j
BUILD_COMMAND V=1 make -C src
INSTALL_COMMAND make install
)
set(URING_INCLUDE_DIRS ${BINARY_DIR}/include PARENT_SCOPE)
Expand Down
54 changes: 32 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ set(PHOTON_AIO_SOURCE "https://pagure.io/libaio/archive/libaio-0.3.113/libaio-0.
set(PHOTON_ZLIB_SOURCE "https://github.com/madler/zlib/releases/download/v1.2.13/zlib-1.2.13.tar.gz" CACHE STRING "")
set(PHOTON_OPENSSL_SOURCE "" CACHE STRING "")
set(PHOTON_CURL_SOURCE "" CACHE STRING "")
set(PHOTON_URING_SOURCE "https://github.com/axboe/liburing.git" CACHE STRING "")
set(PHOTON_URING_SOURCE "https://github.com/axboe/liburing/archive/refs/tags/liburing-2.3.tar.gz" CACHE STRING "")
set(PHOTON_FUSE_SOURCE "" CACHE STRING "")
set(PHOTON_GSASL_SOURCE "" CACHE STRING "")
set(PHOTON_FSTACK_SOURCE "" CACHE STRING "")
Expand Down Expand Up @@ -255,13 +255,13 @@ if (PHOTON_ENABLE_EXTFS)
list(APPEND static_deps ${E2FS_LIBRARIES})
endif ()

# It's OK to have some duplicates both in shared and static deps.
# It's OK to have some `shared_deps` duplicated in `static_deps`.
# Even though .a is suggested, we may still probably find .so in local installed dir.
# This is for the max compatability.
if (NOT APPLE)
set(suffix ".*.so")
set(suffix "\.so$")
else ()
set(suffix ".*.dylib" ".*.tbd")
set(suffix "\.dylib$" "\.tbd$")
endif ()
foreach (dep ${static_deps})
foreach (suf ${suffix})
Expand All @@ -270,37 +270,47 @@ foreach (dep ${static_deps})
break()
endif ()
endforeach ()
if (dep MATCHES "\.a$")
list(APPEND static_deps_archive ${dep})
endif ()
endforeach ()

set(version_scripts)
list(APPEND version_scripts "-Wl,--version-script=${PROJECT_SOURCE_DIR}/tools/libaio.map")

add_library(_static_archive INTERFACE)
if (NOT APPLE)
target_link_libraries(_static_archive INTERFACE
${version_scripts}
-Wl,--whole-archive ${static_deps} -Wl,--no-whole-archive
)
else ()
target_link_libraries(_static_archive INTERFACE
-Wl,-force_load ${static_deps}
)
endif ()

add_library(photon_shared_deps INTERFACE)
target_link_libraries(photon_shared_deps INTERFACE ${shared_deps})

################################################################################

# Link photon shared lib
add_library(photon_shared SHARED $<TARGET_OBJECTS:photon_obj>)
set_target_properties(photon_shared PROPERTIES OUTPUT_NAME photon)
target_link_libraries(photon_shared PUBLIC photon_shared_deps PRIVATE _static_archive)
if (NOT APPLE)
target_link_libraries(photon_shared
PRIVATE ${version_scripts} -Wl,--whole-archive ${static_deps} -Wl,--no-whole-archive
PUBLIC ${shared_deps}
)
else ()
target_link_libraries(photon_shared
PUBLIC ${shared_deps}
PRIVATE -Wl,-force_load ${static_deps}
)
endif ()

# Link photon static lib
add_library(photon_static STATIC $<TARGET_OBJECTS:photon_obj>)
set_target_properties(photon_static PROPERTIES OUTPUT_NAME photon)
target_link_libraries(photon_static PUBLIC photon_shared_deps PRIVATE ${static_deps})
set_target_properties(photon_static PROPERTIES OUTPUT_NAME photon_sole)
target_link_libraries(photon_static
PUBLIC ${shared_deps}
PRIVATE ${static_deps}
)

# Merge static libs into libphoton.a
# Do NOT use this target directly.
add_custom_target(_photon_static_archive ALL
COMMAND ar -crT libphoton.a $<TARGET_FILE:photon_static> $<TARGET_FILE:easy_weak> $<TARGET_FILE:fstack_weak>
DEPENDS photon_static
WORKING_DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}
VERBATIM
)

# Build test cases
if (PHOTON_BUILD_TESTING)
Expand Down
2 changes: 1 addition & 1 deletion net/security-context/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ add_executable(test-tls test.cpp)
target_link_libraries(test-tls PRIVATE photon_shared ${testing_libs})
add_test(NAME test-tls COMMAND $<TARGET_FILE:test-tls>)

if (ENABLE_SASL)
if (ENABLE_SASL AND (NOT (APPLE AND (${ARCH} STREQUAL arm64))))
add_executable(test-sasl test-sasl.cpp)
target_link_libraries(test-sasl PRIVATE photon_shared ${testing_libs})
add_test(NAME test-sasl COMMAND $<TARGET_FILE:test-sasl>)
Expand Down
Loading