Skip to main content

编译

获取源码

git clone https://github.com/alibaba/PhotonLibOS.git
tip

如果您的网络无法访问github,可以使用国内的 镜像仓库.

安装依赖

dnf install git gcc-c++ cmake
dnf install openssl-devel libcurl-devel libaio-devel zlib-devel

编译基础库

cd PhotonLibOS
cmake -B build
cmake --build build -j 8
info

所有的库和可执行程序将被放置于 build/output.

编译样例与测试程序

样例和测试程序是一起构建的

# Install additional dependencies
dnf install epel-release
dnf config-manager --set-enabled powertools
dnf install gtest-devel gmock-devel gflags-devel fuse-devel libgsasl-devel

# Build examples and test code
cmake -B build -D PHOTON_BUILD_TESTING=ON
cmake --build build -j 8

# Run all test cases
cd build
ctest

高级编译选项

OptionDefaultDescription
CMAKE_BUILD_TYPEReleaseBuild类型,可以是 Debug/Release/RelWithDebInfo
PHOTON_BUILD_TESTINGOFF是否编译样例和测试程序
PHOTON_BUILD_DEPENDENCIESOFF不查找本地库作为依赖,而是源码编译第三方依赖
PHOTON_CXX_STANDARD14C++标准,影响-std=c++xx
PHOTON_ENABLE_URINGOFF开启 io_uring,需要liburing
PHOTON_ENABLE_FUSEOFF开启 fuse. 需要 libfuse
PHOTON_ENABLE_SASLOFF开启 SASL. 需要 libgsasl
PHOTON_ENABLE_FSTACK_DPDKOFF开启 F-Stack and DPDK,需要两者的库
PHOTON_ENABLE_EXTFSOFF开启 extfs. 需要 libe2fs
PHOTON_ENABLE_ECOSYSTEMOFF编译Photon生态库,包含一些三方工具和封装

例子1

用源码编译所有依赖,这样你就可以随意分发Photon二进制了,只要运行机器上的libc和libc++的版本满足条件。

cmake -B build -D CMAKE_BUILD_TYPE=RelWithDebInfo \
-D PHOTON_BUILD_TESTING=ON \
-D PHOTON_BUILD_DEPENDENCIES=ON \
-D PHOTON_ENABLE_URING=ON \
-D PHOTON_AIO_SOURCE=https://pagure.io/libaio/archive/libaio-0.3.113/libaio-0.3.113.tar.gz \
-D PHOTON_ZLIB_SOURCE=https://github.com/madler/zlib/releases/download/v1.2.13/zlib-1.2.13.tar.gz \
-D PHOTON_URING_SOURCE=https://github.com/axboe/liburing/archive/refs/tags/liburing-2.3.tar.gz \
-D PHOTON_CURL_SOURCE=https://github.com/curl/curl/archive/refs/tags/curl-7_42_1.tar.gz \
-D PHOTON_OPENSSL_SOURCE=https://github.com/openssl/openssl/archive/refs/heads/OpenSSL_1_0_2-stable.tar.gz \
-D PHOTON_GFLAGS_SOURCE=https://github.com/gflags/gflags/archive/refs/tags/v2.2.2.tar.gz \
-D PHOTON_GOOGLETEST_SOURCE=https://github.com/google/googletest/archive/refs/tags/release-1.12.1.tar.gz

例子2

动态依赖 libcurl.so 和 libssl.so,libaio 源码编译

cmake -B build -D CMAKE_BUILD_TYPE=RelWithDebInfo \
-D PHOTON_BUILD_DEPENDENCIES=ON \
-D PHOTON_AIO_SOURCE=https://pagure.io/libaio/archive/libaio-0.3.113/libaio-0.3.113.tar.gz \
-D PHOTON_CURL_SOURCE="" \
-D PHOTON_OPENSSL_SOURCE=""