Skip to content

Commit

Permalink
Pass vendored libs from cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
apolyakov committed Nov 15, 2024
1 parent 722cf04 commit d5ab3ee
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
9 changes: 8 additions & 1 deletion compiler/make/objs-to-k2-component-target.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@

#pragma once

#include <algorithm>
#include <sstream>
#include <string>
#include <vector>

#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() {
Expand Down Expand Up @@ -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<std::string> libs = split(RUNTIME_LINK_LIBS);
std::for_each(libs.cbegin(), libs.cend(), [&ss](const auto &lib) noexcept { ss << lib << " "; });
return ss.str();
}
};
3 changes: 3 additions & 0 deletions compiler/runtime_link_libs.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

#define RUNTIME_LINK_LIBS "${RUNTIME_LINK_LIBS}"
12 changes: 12 additions & 0 deletions runtime-light/runtime-light.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
3 changes: 3 additions & 0 deletions runtime/runtime.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,6 @@ add_custom_command(OUTPUT ${OBJS_DIR}/php_lib_version.sha256
DEPENDS php_lib_version_j $<TARGET_OBJECTS: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)
4 changes: 2 additions & 2 deletions third-party/zlib-cmake/zlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit d5ab3ee

Please sign in to comment.