Skip to content

Commit

Permalink
Move mbstring functions into runtime-common
Browse files Browse the repository at this point in the history
  • Loading branch information
apolyakov committed Oct 29, 2024
1 parent eff369e commit e4e982d
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 85 deletions.
21 changes: 17 additions & 4 deletions common/unicode/unicode.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,21 @@ add_custom_command(
DEPENDS ${UNICODE_DATA_LIST}
COMMENT "unicode-utils-auto.h generation")

vk_add_library(unicode OBJECT
${UNICODE_DIR}/unicode-utils.cpp
${UNICODE_DIR}/utf8-utils.cpp
${AUTO_DIR}/common/unicode-utils-auto.h)
set(UNICODE_SOURCES unicode-utils.cpp utf8-utils.cpp)

if (COMPILE_RUNTIME_LIGHT)
set(UNICODE_SOURCES_FOR_COMP "${UNICODE_SOURCES}")
configure_file(${BASE_DIR}/compiler/unicode_sources.h.in ${AUTO_DIR}/compiler/unicode_sources.h)

prepend(UNICODE_SOURCES ${UNICODE_DIR}/ ${UNICODE_SOURCES})
vk_add_library(light_unicode OBJECT ${UNICODE_SOURCES} ${AUTO_DIR}/common/unicode-utils-auto.h)
set_property(TARGET light_unicode PROPERTY POSITION_INDEPENDENT_CODE ON)

target_compile_options(light_unicode PUBLIC -stdlib=libc++)
target_link_options(light_unicode PUBLIC -stdlib=libc++ -static-libstdc++)
else()
prepend(UNICODE_SOURCES ${UNICODE_DIR}/ ${UNICODE_SOURCES})
endif()

vk_add_library(unicode OBJECT ${UNICODE_SOURCES} ${AUTO_DIR}/common/unicode-utils-auto.h)

13 changes: 13 additions & 0 deletions compiler/compiler-core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,14 @@ static std::vector<std::string> get_common_sources() {
#endif
}

static std::vector<std::string> get_unicode_sources() {
#ifdef RUNTIME_LIGHT
return split(UNICODE_SOURCES, ';');
#else
return {};
#endif
}

void CompilerCore::init_runtime_and_common_srcs_dir() {
runtime_common_sources_dir = settings().runtime_and_common_src.get() + "runtime-common/";
runtime_common_sources_index.sync_with_dir(runtime_common_sources_dir);
Expand All @@ -707,6 +715,11 @@ void CompilerCore::init_runtime_and_common_srcs_dir() {
common_sources_index.sync_with_dir(common_sources_dir);
common_sources_dir = common_sources_index.get_dir(); // As in init_dest_dir, IDK what is it for
common_sources_index.filter_with_whitelist(get_common_sources());

unicode_sources_dir = settings().runtime_and_common_src.get() + "common/unicode/";
unicode_sources_index.sync_with_dir(unicode_sources_dir);
unicode_sources_dir = unicode_sources_index.get_dir(); // As in init_dest_dir, IDK what is it for
unicode_sources_index.filter_with_whitelist(get_unicode_sources());
}

bool CompilerCore::try_require_file(SrcFilePtr file) {
Expand Down
2 changes: 2 additions & 0 deletions compiler/compiler-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class CompilerCore {
Index runtime_common_sources_index;
Index runtime_sources_index;
Index common_sources_index;
Index unicode_sources_index;
TSHashTable<SrcFilePtr> file_ht;
TSHashTable<SrcDirPtr> dirs_ht;
TSHashTable<FunctionPtr> functions_ht;
Expand Down Expand Up @@ -71,6 +72,7 @@ class CompilerCore {
std::string runtime_common_sources_dir;
std::string runtime_sources_dir;
std::string common_sources_dir;
std::string unicode_sources_dir;

CompilerCore();
void start();
Expand Down
1 change: 1 addition & 0 deletions compiler/compiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set(KEYWORDS_GPERF ${KPHP_COMPILER_DIR}/keywords.gperf)
if (COMPILE_RUNTIME_LIGHT)
prepend(RUNTIME_BUILD_INFO ${KPHP_COMPILER_AUTO_DIR}/
common_sources.h
unicode_sources.h
runtime_sources.h
runtime_common_sources.h
runtime_compile_flags.h)
Expand Down
1 change: 1 addition & 0 deletions compiler/runtime_build_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#ifdef RUNTIME_LIGHT

#include "auto/compiler/common_sources.h"
#include "auto/compiler/unicode_sources.h"
#include "auto/compiler/runtime_compile_flags.h"
#include "auto/compiler/runtime_common_sources.h"
#include "auto/compiler/runtime_sources.h"
Expand Down
3 changes: 3 additions & 0 deletions compiler/unicode_sources.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

#define UNICODE_SOURCES "${UNICODE_SOURCES_FOR_COMP}"
3 changes: 2 additions & 1 deletion runtime-common/stdlib/stdlib.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
prepend(STDLIB_STRING stdlib/string/ string-functions.cpp)
prepend(STDLIB_STRING stdlib/string/ string-functions.cpp
mbstring-functions.cpp)

set(STDLIB_SRC "${STDLIB_STRING}")
Loading

0 comments on commit e4e982d

Please sign in to comment.