Skip to content

Commit bf48ed8

Browse files
authored
implement vk_flex in runtime-common (#1446)
In k2 mode, the flex library is compiled into runtime-light.
1 parent 6d11cef commit bf48ed8

12 files changed

Lines changed: 40 additions & 51 deletions

File tree

builtin-functions/kphp-light/stdlib/vkext-functions.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
// ===== SUPPORTED =====
4-
53
function vk_utf8_to_win ($text ::: string, $max_len ::: int = 0, $exit_on_error ::: bool = false) ::: string;
64

75
function vk_win_to_utf8 ($text ::: string, $escape ::: bool = true) ::: string;
@@ -36,7 +34,4 @@ function vk_stats_hll_unpack($hll ::: string) ::: string | false;
3634

3735
function vk_stats_hll_is_packed($hll ::: string) ::: bool;
3836

39-
// ===== UNSUPPORTED =====
40-
41-
/** @kphp-extern-func-info stub generation-required */
4237
function vk_flex ($name ::: string, $case_name ::: string, $sex ::: int, $type ::: string, $lang_id ::: int = 0) ::: string;

compiler/compiler-settings.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,16 @@ void CompilerSettings::init() {
389389

390390
#if defined(__APPLE__)
391391
append_if_doesnt_contain(ld_flags.value_, system_installed_static_libs, "-l");
392-
auto flex_prefix = kphp_src_path.value_ + "objs/flex/lib";
393-
append_if_doesnt_contain(ld_flags.value_, vk::to_array({"vk-flex-data"}), flex_prefix, ".a");
392+
if (!is_k2_mode) {
393+
auto flex_prefix = kphp_src_path.value_ + "objs/flex/lib";
394+
append_if_doesnt_contain(ld_flags.value_, vk::to_array({"vk-flex-data"}), flex_prefix, ".a");
395+
}
394396
system_installed_dynamic_libs.emplace_back("iconv");
395397
#else
396-
system_installed_static_libs.emplace_back("vk-flex-data");
398+
if (!is_k2_mode) {
399+
// In the case of K2, the vk-flex-data library is compiled into runtime-light
400+
system_installed_static_libs.emplace_back("vk-flex-data");
401+
}
397402
append_if_doesnt_contain(ld_flags.value_, system_installed_static_libs, "-l:lib", ".a");
398403
system_installed_dynamic_libs.emplace_back("rt");
399404
#endif

flex/flex.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ add_dependencies(flex-data-src-pic flex-data)
2424
vk_add_library_no_pic(flex-data-src-no-pic OBJECT ${FLEX_SOURCES})
2525
add_dependencies(flex-data-src-no-pic flex-data)
2626

27+
if (COMPILE_RUNTIME_LIGHT)
28+
target_compile_options(flex-data-src-pic PUBLIC -stdlib=libc++ ${RUNTIME_LIGHT_VISIBILITY})
29+
target_link_options(flex-data-src-pic PUBLIC -stdlib=libc++)
30+
endif()
31+
2732
vk_add_library_pic(flex_data_shared-pic SHARED $<TARGET_OBJECTS:flex-data-src-pic>)
2833
add_dependencies(flex_data_shared-pic flex-data-src-pic)
2934

runtime-common/stdlib/vkext/vkext-functions.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
#include <array>
77
#include <cstdio>
88

9+
#include "flex/flex.h"
10+
11+
#include "runtime-common/core/utils/kphp-assert-core.h"
12+
#include "runtime-common/stdlib/string/string-context.h"
13+
914
namespace {
1015

1116
constexpr std::array<int, 256> utf8_to_win_convert_0x400 = {
@@ -458,3 +463,19 @@ string f$vk_whitespace_pack(const string& str, bool html_opt) noexcept {
458463
}
459464
return buffered.result;
460465
}
466+
467+
string f$vk_flex(const string& name, const string& case_name, int64_t sex, const string& type, int64_t lang_id) noexcept {
468+
constexpr size_t ERROR_MSG_BUG_SIZE{1000};
469+
std::array<char, ERROR_MSG_BUG_SIZE> error_msg_buffer{'\0'};
470+
471+
auto* static_buffer{StringLibContext::get().static_buf.get()};
472+
std::string_view res = flex(std::string_view{name.c_str(), name.size()}, std::string_view{case_name.c_str(), case_name.size()}, sex == 1,
473+
std::string_view{type.c_str(), type.size()}, lang_id, static_buffer, error_msg_buffer.data(), ERROR_MSG_BUG_SIZE);
474+
if (error_msg_buffer[0] != '\0') {
475+
php_warning("%s", error_msg_buffer.data());
476+
}
477+
if (res.data() == name.c_str()) {
478+
return name;
479+
}
480+
return string{res.data(), static_cast<string::size_type>(res.size())};
481+
}

runtime-common/stdlib/vkext/vkext-functions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,5 @@ inline string f$vk_sp_to_cyrillic(const string& s) noexcept {
5050
inline string f$vk_sp_words_only(const string& s) noexcept {
5151
return vkext_impl_::sp_words_only(s);
5252
}
53+
54+
string f$vk_flex(const string& name, const string& case_name, int64_t sex, const string& type, int64_t lang_id = 0) noexcept;

runtime-light/runtime-light.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ set(RUNTIME_LIGHT_LINK_LIBS "${KPHP_TIMELIB_PIC_LIBRARIES} ${PCRE2_PIC_LIBRARIES
6363
vk_add_library_pic(kphp-light-runtime-pic STATIC)
6464
target_compile_options(kphp-light-runtime-pic PUBLIC ${RUNTIME_LIGHT_COMPILE_FLAGS})
6565
target_link_options(kphp-light-runtime-pic PUBLIC ${RUNTIME_LIGHT_LINK_FLAGS})
66-
target_link_libraries(kphp-light-runtime-pic PUBLIC vk::pic::light-common vk::pic::unicode vk::pic::runtime-light vk::pic::runtime-common)
66+
target_link_libraries(kphp-light-runtime-pic PUBLIC vk::pic::flex-data-src vk::pic::light-common vk::pic::unicode vk::pic::runtime-light vk::pic::runtime-common)
6767

6868
set_target_properties(kphp-light-runtime-pic PROPERTIES LIBRARY_OUTPUT_NAME libkphp-light-runtime.a)
6969

runtime/misc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <unistd.h>
1313

1414
#include "runtime-common/stdlib/serialization/json-functions.h"
15+
#include "runtime-common/stdlib/vkext/vkext-functions.h"
1516
#include "runtime/context/runtime-context.h"
1617
#include "runtime/critical_section.h"
1718
#include "runtime/datetime/datetime_functions.h"
@@ -20,7 +21,6 @@
2021
#include "runtime/interface.h"
2122
#include "runtime/math_functions.h"
2223
#include "runtime/string_functions.h"
23-
#include "runtime/vkext.h"
2424
#include "server/json-logger.h"
2525
#include "server/php-engine-vars.h"
2626

runtime/runtime.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ prepend(KPHP_RUNTIME_SOURCES ${BASE_DIR}/runtime/
113113
typed_rpc.cpp
114114
udp.cpp
115115
tcp.cpp
116-
vkext.cpp
117116
ffi.cpp
118117
zlib.cpp
119118
zstd.cpp)

runtime/vkext.cpp

Lines changed: 0 additions & 27 deletions
This file was deleted.

runtime/vkext.h

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)