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

Add mbstring to KPHP (Package I & II & III -- 26 new functions) #965

Draft
wants to merge 32 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
cb60059
fix issue
andarut Apr 7, 2023
4c156df
mbstring functions
andarut Apr 10, 2023
8121ae9
build libmbfl from source
andarut Apr 17, 2023
406b0c9
fix for ubuntu from mac os
andarut Apr 17, 2023
35bcc8f
remove trash
andarut Apr 17, 2023
e951d86
fix path
andarut Apr 17, 2023
fac68a6
fix path
andarut Apr 17, 2023
3c0c54e
fix including
andarut Apr 17, 2023
9332f45
finish basic mbstring functions and building libmbfl
andarut Apr 19, 2023
8b3d40e
fix external libs
andarut Apr 20, 2023
7e137cb
move kphp-timelib installation to the top and add explanatory comment
andarut Apr 20, 2023
5aff222
move kphp-timelib installation to the top and add explanatory comment
andarut Apr 20, 2023
aa64dd0
Merge branch 'master' into dev
andarut Apr 20, 2023
07af7a0
add MBFL flag to runtime, restore mbstring functions for only UTF-8 a…
andarut Apr 30, 2023
ac8f997
small fixes
andarut Apr 30, 2023
0b967c4
add test workflow
andarut Dec 26, 2023
9a330a2
Merge pull request #7 from andreylzmw/gh-install
andarut Dec 26, 2023
2cfb962
add test workflow
andarut Dec 26, 2023
dfbdaa3
Merge pull request #8 from andreylzmw/gh-install
andarut Dec 26, 2023
b6bec7e
Add 14 functions (mb_substr, mb_strlen, mb_substr_count, mb_strtolowe…
Feb 6, 2024
125a924
Merge branch 'master' into mbstring
Feb 7, 2024
482d782
Fix small compilation errors
Feb 7, 2024
c6be4b3
Fix null encoding input, small fix mb_convert_case
Feb 24, 2024
ad25841
Add mb_strcut function with simple tests
mt-omarov Mar 8, 2024
600e393
Add mb_str_split function
mt-omarov Mar 9, 2024
cfbe230
Add mb_preferred_mime_name function and simple php-tests
mt-omarov Mar 9, 2024
07588d3
Add mb_list_encodings function
mt-omarov Mar 11, 2024
2ecb94d
Add mb_encoding_aliases function
mt-omarov Mar 12, 2024
24400a0
Add oniguruma and regular expressions
Jul 10, 2024
86453a0
Fix linking problem
Jul 18, 2024
cf7f205
Add php tests
Jul 23, 2024
69e7975
Merge remote-tracking branch 'remote/mbstring' into mbstring
Jul 23, 2024
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
16 changes: 16 additions & 0 deletions .github/workflows/Dockerfile.buster.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM debian:buster
ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
apt-get install -y --no-install-recommends apt-utils ca-certificates gnupg wget lsb-release && \
echo "deb https://deb.debian.org/debian buster-backports main" >> /etc/apt/sources.list && \
wget -qO /etc/apt/trusted.gpg.d/vkpartner.asc https://artifactory-external.vkpartner.ru/artifactory/api/gpg/key/public && \
echo "deb https://artifactory-external.vkpartner.ru/artifactory/kphp buster main" >> /etc/apt/sources.list && \
wget -qO - https://packages.sury.org/php/apt.gpg | apt-key add - && \
echo "deb https://packages.sury.org/php/ buster main" >> /etc/apt/sources.list.d/php.list

RUN apt-get update && apt-get install -y git cmake make g++ lld gperf netcat php7.4-vkext kphp vk-tl-tools && \
mkdir -p /var/www/vkontakte/data/www/vkontakte.com/tl/ && \
tl-compiler -e /var/www/vkontakte/data/www/vkontakte.com/tl/scheme.tlo /usr/share/vkontakte/examples/tl-files/common.tl /usr/share/vkontakte/examples/tl-files/tl.tl

RUN useradd -ms /bin/bash kitten
13 changes: 13 additions & 0 deletions .github/workflows/Dockerfile.focal.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM ubuntu:20.04
ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
apt-get install -y --no-install-recommends apt-utils ca-certificates gnupg wget software-properties-common pkg-config && \
wget -qO /etc/apt/trusted.gpg.d/vkpartner.asc https://artifactory-external.vkpartner.ru/artifactory/api/gpg/key/public && \
echo "deb https://artifactory-external.vkpartner.ru/artifactory/kphp focal main" >> /etc/apt/sources.list

RUN apt-get update && apt-get install -y git cmake make g++ lld gperf netcat php7.4-vkext kphp vk-tl-tools && \
mkdir -p /var/www/vkontakte/data/www/vkontakte.com/tl/ && \
tl-compiler -e /var/www/vkontakte/data/www/vkontakte.com/tl/scheme.tlo /usr/share/vkontakte/examples/tl-files/common.tl /usr/share/vkontakte/examples/tl-files/tl.tl

RUN useradd -ms /bin/bash kitten
17 changes: 17 additions & 0 deletions .github/workflows/Dockerfile.jammy.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM ubuntu:22.04
ARG DEBIAN_FRONTEND=noninteractive

RUN apt update && \
apt install -y --no-install-recommends apt-utils ca-certificates gnupg wget software-properties-common pkg-config && \
wget -qO /etc/apt/trusted.gpg.d/vkpartner.asc https://artifactory-external.vkpartner.ru/artifactory/api/gpg/key/public && \
echo "deb [arch=amd64] https://artifactory-external.vkpartner.ru/artifactory/kphp jammy main" | tee /etc/apt/sources.list.d/vkpartner.list

RUN apt install -y software-properties-common && apt update && \
add-apt-repository ppa:ondrej/php -y && \
apt update

RUN apt install -y git cmake make g++ lld gperf netcat php7.4-vkext kphp vk-tl-tools && \
mkdir -p /var/www/vkontakte/data/www/vkontakte.com/tl/ && \
tl-compiler -e /var/www/vkontakte/data/www/vkontakte.com/tl/scheme.tlo /usr/share/vkontakte/examples/tl-files/common.tl /usr/share/vkontakte/examples/tl-files/tl.tl

RUN useradd -ms /bin/bash kitten
31 changes: 31 additions & 0 deletions .github/workflows/linux-install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: linux-install

on:
workflow_dispatch:

env:
kphp_root_dir: /home/kitten/kphp
kphp_polyfills_dir: /home/kitten/kphp/kphp-polyfills
kphp_build_dir: /home/kitten/kphp/build

jobs:
install-linux:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- os: buster
- os: focal
# - os: jammy # TODO: enable after release to artifactory servers

steps:
- uses: actions/checkout@v3

- name: Build and start Docker container
run: |
docker build -f $GITHUB_WORKSPACE/.github/workflows/Dockerfile.${{matrix.os}}.install $GITHUB_WORKSPACE -t kphp-build-img-${{matrix.os}}-install
docker run -dt --name kphp-build-container-${{matrix.os}}-install kphp-build-img-${{matrix.os}}-install

- name: Run php dummy script
run: docker exec -u kitten kphp-build-container-${{matrix.os}}-install bash -c
"cd ${{env.demo_dir}} && echo 'hello world' > demo.php && kphp --mode=cli --cxx=g++ demo.php && ./kphp_out/cli -o --user kitten"
3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 28 additions & 8 deletions builtin-functions/_functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -762,14 +762,6 @@ function setlocale ($category ::: int, $locale ::: string) ::: string | false;

function iconv ($input_encoding ::: string, $output_encoding ::: string, $input_str ::: string) ::: string | false;

function mb_check_encoding ($str ::: string, $encoding ::: string = "cp1251") ::: bool;
function mb_strlen ($str ::: string, $encoding ::: string = "cp1251") ::: int;
function mb_strpos ($haystack ::: string, $needle ::: string, $offset ::: int = 0, $encoding ::: string = "cp1251") ::: int | false;
function mb_stripos ($haystack ::: string, $needle ::: string, $offset ::: int = 0, $encoding ::: string = "cp1251") ::: int | false;
function mb_strtolower ($str ::: string, $encoding ::: string = "cp1251") ::: string;
function mb_strtoupper ($str ::: string, $encoding ::: string = "cp1251") ::: string;
function mb_substr ($str ::: string, $start ::: int, $length ::: mixed = PHP_INT_MAX, $encoding ::: string = "cp1251") ::: string;

define('PHP_ROUND_HALF_UP', 123423141);
define('PHP_ROUND_HALF_DOWN', 123423144);
define('PHP_ROUND_HALF_EVEN', 123423145);
Expand Down Expand Up @@ -1654,3 +1646,31 @@ class DateTimeImmutable implements DateTimeInterface {
}

function getenv(string $varname = '', bool $local_only = false): mixed;

function mb_check_encoding(array|string $value, ?string $encoding = null): bool;
function mb_convert_encoding(array|string $string, string $to_encoding, array|string|null $from_encoding = null): array|string|false;
function mb_encoding_aliases(string $encoding): array;
function mb_list_encodings(): array;
function mb_preferred_mime_name(string $encoding): string|false;
function mb_str_split(string $string, int $length = 1, ?string $encoding = null): array;
function mb_strcut(string $string, int $start, ?int $length = null, ?string $encoding = null): string;
function mb_substr(string $string, int $start, ?int $length = null, ?string $encoding = null): string;
function mb_substitute_character(string|int|null $substitute_character = null): string|int|false;
function mb_strlen(string $string, ?string $encoding = null): int;
function mb_substr_count(string $haystack, string $needle, ?string $encoding = null): int;
function mb_strtolower(string $string, ?string $encoding = null): string;
function mb_strtoupper(string $string, ?string $encoding = null): string;
function mb_strwidth(string $string, ?string $encoding = null): int;
function mb_strpos(string $haystack, string $needle, int $offset = 0, ?string $encoding = null): int|false;
function mb_stripos(string $haystack, string $needle, int $offset = 0, ?string $encoding = null): int|false;
function mb_strripos(string $haystack, string $needle, int $offset = 0, ?string $encoding = null): int|false;
function mb_strrpos(string $haystack, string $needle, int $offset = 0, string $encoding = null): int|false;
function mb_stristr(string $haystack, string $needle, bool $before_needle = false, ?string $encoding = null): string|false;
function mb_strrchr(string $haystack, string $needle, bool $before_needle = false, ?string $encoding = null): string|false;
function mb_strrichr(string $haystack, string $needle, bool $before_needle = false, ?string $encoding = null): string|false;
function mb_strstr(string $haystack, string $needle, bool $before_needle = false, ?string $encoding = null): string|false;
function mb_strimwidth(string $string, int $start, int $width, string $trim_marker = "", ?string $encoding = null): string;
function mb_scrub(string $string, ?string $encoding = null): string;
function mb_regex_encoding(?string $encoding = null): string|false;
function mb_regex_set_options(?string $options = null): string;
function mb_ereg_match(string $pattern, string $string, ?string $options = null): bool;
26 changes: 26 additions & 0 deletions cmake/external-libraries.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
option(DOWNLOAD_MISSING_LIBRARIES "download and build missing libraries if needed" OFF)
option(MBFL "download and build libmbfl" OFF)
cmake_print_variables(DOWNLOAD_MISSING_LIBRARIES)
cmake_print_variables(MBFL)
function(handle_missing_library LIB_NAME)
message(STATUS "------${LIB_NAME}---------")
if(DOWNLOAD_MISSING_LIBRARIES)
Expand All @@ -9,6 +11,30 @@ function(handle_missing_library LIB_NAME)
endif()
endfunction()

if(MBFL)
message(STATUS "MBFL=On, libmbfl will be downloaded and built")
add_compile_options(-DMBFL)
FetchContent_Declare(libmbfl GIT_REPOSITORY https://github.com/andreylzmw/libmbfl)
FetchContent_MakeAvailable(libmbfl)
include_directories(${libmbfl_SOURCE_DIR}/include)
add_definitions(-DLIBMBFL_LIB_DIR="${libmbfl_SOURCE_DIR}/objs")
add_link_options(-L${libmbfl_SOURCE_DIR}/objs)

find_package(onig QUIET)
if(NOT onig_FOUND)
handle_missing_library("onig")
FetchContent_Declare(
onig
GIT_REPOSITORY https://github.com/kkos/oniguruma/
GIT_TAG v6.9.9
)
FetchContent_MakeAvailable(onig)
include_directories(${onig_SOURCE_DIR}/src)
add_definitions(-DONIG_LIB_DIR="${onig_BINARY_DIR}")
message(STATUS "---------------------")
endif()
endif()

find_package(fmt QUIET)
if(NOT fmt_FOUND)
handle_missing_library("fmtlib")
Expand Down
35 changes: 35 additions & 0 deletions cmake/init-compilation-flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,41 @@ if(UNDEFINED_SANITIZER)
endif()
cmake_print_variables(ADDRESS_SANITIZER UNDEFINED_SANITIZER)

option(PDO_LIBS_STATIC_LINKING "Enable static linking with database libs for PDO")
if(PDO_LIBS_STATIC_LINKING)
add_definitions(-DPDO_LIBS_STATIC_LINKING)
endif()
cmake_print_variables(PDO_LIBS_STATIC_LINKING)

option(PDO_DRIVER_MYSQL "Enable MySQL PDO driver")
if(PDO_DRIVER_MYSQL)
add_definitions(-DPDO_DRIVER_MYSQL)
endif()
cmake_print_variables(PDO_DRIVER_MYSQL)

option(PDO_DRIVER_PGSQL "Enable pgSQL PDO driver")
if (PDO_DRIVER_PGSQL)
if (APPLE)
set(PostgreSQL_ROOT "/usr/local/opt/libpq" CACHE INTERNAL "")
else()
set(PostgreSQL_ADDITIONAL_VERSIONS "14")
endif()
find_package(PostgreSQL REQUIRED)
include_directories(${PostgreSQL_INCLUDE_DIR})
string(FIND ${PostgreSQL_VERSION_STRING} "." PostgreSQL_VERSION_POS)
string(SUBSTRING ${PostgreSQL_VERSION_STRING} 0 ${PostgreSQL_VERSION_POS} PostgreSQL_VERSION)
add_definitions(-DPDO_DRIVER_PGSQL)
add_compile_definitions(PDO_DRIVER_PGSQL_VERSION=${PostgreSQL_VERSION})
endif()

cmake_print_variables(PDO_DRIVER_PGSQL)

option(KPHP_TESTS "Build the tests" ON)
cmake_print_variables(KPHP_TESTS)

option(KPHP_CUSTOM_CMAKE "Use CMakeLists.txt of custom php project" OFF)
cmake_print_variables(KPHP_CUSTOM_CMAKE)

if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to `${DEFAULT_BUILD_TYPE}` as none was specified.")
set(CMAKE_BUILD_TYPE ${DEFAULT_BUILD_TYPE} CACHE STRING "Build type (default ${DEFAULT_BUILD_TYPE})" FORCE)
Expand Down
12 changes: 12 additions & 0 deletions compiler/compiler-settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ void CompilerSettings::init() {

remove_extra_spaces(extra_cxx_flags.value_);
std::stringstream ss;
#ifdef MBFL
ss << " -DMBFL ";
#endif
ss << "-Wall "
<< extra_cxx_flags.get()
<< " -iquote" << kphp_src_path.get()
Expand Down Expand Up @@ -334,6 +337,15 @@ void CompilerSettings::init() {
ld_flags.value_ += " -L /usr/local/lib";
#endif

#ifdef LIBMBFL_LIB_DIR
external_static_libs.emplace_back("libmbfl");
ld_flags.value_ += " -L" LIBMBFL_LIB_DIR;
#endif

#ifdef ONIG_LIB_DIR
ld_flags.value_ += " -L " ONIG_LIB_DIR " -lonig";
#endif

#ifdef KPHP_H3_LIB_DIR
ld_flags.value_ += " -L" KPHP_H3_LIB_DIR;
#else
Expand Down
Loading