These are sources of KPHP, vkext, flex data (for Russian declensions), and all TL tools.
KPHP linkage depends on some custom packages, that are also compiled from source:
KPHP is compiled with CMake and packed with CPack.
Add external repositories
apt-get update
# utils for adding repositories
apt-get install -y --no-install-recommends apt-utils ca-certificates gnupg wget lsb-release
# for newest cmake package
echo "deb https://deb.debian.org/debian buster-backports main" >> /etc/apt/sources.list
# for curl-kphp-vk, libuber-h3-dev packages and kphp-timelib
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
# for php7.4-dev package
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
# for libmysqlclient-dev
TEMP_DEB="$(mktemp)"
wget -O "$TEMP_DEB" 'https://dev.mysql.com/get/mysql-apt-config_0.8.20-1_all.deb'
DEBIAN_FRONTEND=noninteractive dpkg -i "$TEMP_DEB"
rm -f "$TEMP_DEB"
# for postgresql
echo "deb http://apt.postgresql.org/pub/repos/apt buster-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \
wget -qO - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
Install packages
apt-get update
apt install git cmake-data=3.16* cmake=3.16* make g++ gperf python3-minimal python3-jsonschema \
curl-kphp-vk libuber-h3-dev kphp-timelib libfmt-dev libgtest-dev libgmock-dev libre2-dev libpcre3-dev \
libzstd-dev libyaml-cpp-dev libnghttp2-dev zlib1g-dev php7.4-dev libmysqlclient-dev libnuma-dev \
postgresql postgresql-server-dev-all libpq-dev libldap-dev libkrb5-dev
Add external repositories
apt-get update
# utils for adding repositories
apt-get install -y --no-install-recommends apt-utils ca-certificates gnupg wget
# for curl-kphp-vk, libuber-h3-dev packages and kphp-timelib
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
Install packages
apt-get update
apt install git cmake make g++ gperf python3-minimal python3-jsonschema \
curl-kphp-vk libuber-h3-dev kphp-timelib libfmt-dev libgtest-dev libgmock-dev libre2-dev libpcre3-dev \
libzstd-dev libyaml-cpp-dev libnghttp2-dev zlib1g-dev php7.4-dev libmysqlclient-dev libnuma-dev \
postgresql postgresql-server-dev-all libpq-dev libldap-dev libkrb5-dev
Make sure you have brew
and clang
(at least Apple clang version 10.0.0
)
brew tap shivammathur/php
brew update
brew install re2c cmake coreutils openssl libiconv re2 pcre yaml-cpp zstd googletest shivammathur/php/php@7.4
brew link --overwrite shivammathur/php/php@7.4
pip3 install jsonschema
Clone somewhere local epoll-shim from GitHub and switch to osx-platform branch. Add env variable EPOLL_SHIM_REPO
to your bash profile. It allows to avoid of cloning epoll-shim
on each clean cmake call.
git clone https://github.com/VKCOM/epoll-shim.git
cd epoll-shim
git checkout osx-platform
echo 'export "EPOLL_SHIM_REPO=$(pwd)" >> ~/.bash_profile'
Clone somewhere local h3 from GitHub and switch to stable-3.x branch.
git clone https://github.com/uber/h3.git
git checkout stable-3.x
mkdir build
cd build
cmake ..
sudo make install
Probably, there is an easier way to do this, but I couldn’t find it, at least for late 2021.
Follow the steps above. Later on, you'll have to patch the libucontext library locally.
git clone https://github.com/kaniini/libucontext
cd libucontext
nano Makefile
Find assignment to LIBUCONTEXT_LINKER_FLAGS
and replace it with:
LIBUCONTEXT_LINKER_FLAGS = -dynamiclib -install_name ${LIBUCONTEXT_SONAME} -current_version ${LIBUCONTEXT_SOVERSION} -compatibility_version ${LIBUCONTEXT_SOVERSION}
Now we are ready to make libucontext:
make FREESTANDING=yes ARCH=aarch64
Finally, copy resulting files to the default brew search folder /opt/homebrew
:
cp libucontext.a /opt/homebrew/lib
cp libucontext.dylib /opt/homebrew/lib
cp -r include/* /opt/homebrew/include/
Make sure you are using the same package list. You may use system default libcurl package, it would work, but without DNS resolving. uber-h3
must be installed from sources.
It's also recommended having a libfmt >= 7
installed (if not, pass -DDOWNLOAD_MISSING_LIBRARIES=On
to CMake) and ccache
, it may speed up compilation time.
Here are available variables, that can be modified during the cmake
invocation:
DOWNLOAD_MISSING_LIBRARIES when libfmt / gtest / epoll-shim / etc not found, downloads them to a local folder [Off]
ADDRESS_SANITIZER enables the address sanitizer [Off]
UNDEFINED_SANITIZER enables the undefined sanitizer [Off]
KPHP_TESTS include tests to default target [On]
We use the make
command here, but of course, parallel compilation means make -j$(nproc)
or env settings.
mkdir build
cd build
cmake ..
make
This is achieved with the same command:
# in build/ folder
make
To build and install vkext locally, you need to have php
and php-dev
packages installed for PHP 7.2 or above.
vkext is also compiled with CMake.
# in build/ folder
make
Install for the default PHP version (recommended)
sudo cp ../objs/vkext/modules/vkext.so $(php-config --extension-dir)
If you want to use it everywhere, update the global php.ini file by adding the following lines:
extension=vkext.so
tl.conffile="/path/to/scheme.tlo"
If you don't want to install it globally, pass it as the -d
option to php instead of updating php.ini:
php -d extension=vkext.so -d tl.conffile=/path/to/scheme.tlo ...
Build for a specific PHP version (optional)
Run the following script with the desirable PHP_VERSION (only “7.2” and “7.4” are supported so far):
# in build/ folder
make vkext${PHP_VERSION}
sudo cp ../objs/vkext/modules${PHP_VERSION}/vkext.so $(php-config${PHP_VERSION} --extension-dir)
Compiling .tlo for php.ini
Use the tl-compiler
executable from vk-tl-tools
package:
tl-compiler -e /path/to/output.tlo input1.tl input2.tl ...
# in build/ folder
cpack -D CPACK_COMPONENTS_ALL="KPHP;FLEX" .