From d5ab3ee90d8eabaa681213f8e699035e7366e43a Mon Sep 17 00:00:00 2001 From: Alexander Polyakov Date: Fri, 15 Nov 2024 10:56:43 +0300 Subject: [PATCH] Pass vendored libs from cmake --- compiler/make/objs-to-k2-component-target.h | 9 ++++++++- compiler/runtime_link_libs.h.in | 3 +++ runtime-light/runtime-light.cmake | 12 ++++++++++++ runtime/runtime.cmake | 3 +++ third-party/zlib-cmake/zlib.cmake | 4 ++-- 5 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 compiler/runtime_link_libs.h.in diff --git a/compiler/make/objs-to-k2-component-target.h b/compiler/make/objs-to-k2-component-target.h index 74e2e5353d..65536aaf53 100644 --- a/compiler/make/objs-to-k2-component-target.h +++ b/compiler/make/objs-to-k2-component-target.h @@ -4,11 +4,16 @@ #pragma once +#include #include +#include +#include +#include "auto/compiler/runtime_link_libs.h" #include "compiler/compiler-core.h" #include "compiler/compiler-settings.h" #include "compiler/make/target.h" +#include "compiler/utils/string-utils.h" class Objs2K2ComponentTarget : public Target { static std::string load_all_symbols_pre() { @@ -45,7 +50,9 @@ class Objs2K2ComponentTarget : public Target { } else { ss << deps.back()->get_name() << " "; } - ss << " /home/al-polyakov/workspace/kphp/objs/libz.a "; + // add vendored statically linking libs + std::vector libs = split(RUNTIME_LINK_LIBS); + std::for_each(libs.cbegin(), libs.cend(), [&ss](const auto &lib) noexcept { ss << lib << " "; }); return ss.str(); } }; diff --git a/compiler/runtime_link_libs.h.in b/compiler/runtime_link_libs.h.in new file mode 100644 index 0000000000..d37a2f513b --- /dev/null +++ b/compiler/runtime_link_libs.h.in @@ -0,0 +1,3 @@ +#pragma once + +#define RUNTIME_LINK_LIBS "${RUNTIME_LINK_LIBS}" diff --git a/runtime-light/runtime-light.cmake b/runtime-light/runtime-light.cmake index d187f7cb13..dd13bbfb19 100644 --- a/runtime-light/runtime-light.cmake +++ b/runtime-light/runtime-light.cmake @@ -41,6 +41,9 @@ set_target_properties(runtime-light PROPERTIES LIBRARY_OUTPUT_DIRECTORY target_compile_options(runtime-light PUBLIC -stdlib=libc++ -iquote ${GENERATED_DIR} -fPIC -O3) target_link_options(runtime-light PUBLIC -stdlib=libc++ -static-libstdc++) +# add statically linking libraries +set_property(TARGET runtime-light PROPERTY RUNTIME_LINK_LIBS + "${ZLIB_LIB_DIR}/libz.a") if(APPLE) target_link_options(runtime-light PUBLIC -undefined dynamic_lookup) @@ -113,3 +116,12 @@ list(JOIN RUNTIME_COMPILE_FLAGS "\;" RUNTIME_COMPILE_FLAGS) string(REPLACE "\"" "\\\"" RUNTIME_COMPILE_FLAGS ${RUNTIME_COMPILE_FLAGS}) configure_file(${BASE_DIR}/compiler/runtime_compile_flags.h.in ${AUTO_DIR}/compiler/runtime_compile_flags.h) + +get_property( + RUNTIME_LINK_LIBS + TARGET runtime-light + PROPERTY RUNTIME_LINK_LIBS) +list(JOIN RUNTIME_LINK_LIBS "\;" RUNTIME_LINK_LIBS) +string(REPLACE "\"" "\\\"" RUNTIME_LINK_LIBS ${RUNTIME_LINK_LIBS}) +configure_file(${BASE_DIR}/compiler/runtime_link_libs.h.in + ${AUTO_DIR}/compiler/runtime_link_libs.h) diff --git a/runtime/runtime.cmake b/runtime/runtime.cmake index da3018eedd..d2abdac47a 100644 --- a/runtime/runtime.cmake +++ b/runtime/runtime.cmake @@ -204,3 +204,6 @@ add_custom_command(OUTPUT ${OBJS_DIR}/php_lib_version.sha256 DEPENDS php_lib_version_j $ COMMENT "php_lib_version.sha256 generation") +# this is to create a dummy file so the compiler can find it and include +configure_file(${BASE_DIR}/compiler/runtime_link_libs.h.in + ${AUTO_DIR}/compiler/runtime_link_libs.h) diff --git a/third-party/zlib-cmake/zlib.cmake b/third-party/zlib-cmake/zlib.cmake index 91c095123b..e9d2152376 100644 --- a/third-party/zlib-cmake/zlib.cmake +++ b/third-party/zlib-cmake/zlib.cmake @@ -8,7 +8,7 @@ if(COMPILE_RUNTIME_LIGHT) ${THIRD_PARTY_DIR}/zlib/zconf.h) target_compile_options(zlibstatic PUBLIC ${ZLIB_COMPILE_FLAGS}) # Set output directories for zlib targets + set(ZLIB_LIB_DIR "${OBJS_DIR}/lib") set_target_properties(zlibstatic PROPERTIES ARCHIVE_OUTPUT_DIRECTORY - "${OBJS_DIR}") - set(ZLIB_LIB_DIR "${OBJS_DIR}") + ${ZLIB_LIB_DIR}) endif()