Build and Test pstore Write Project with Repo based Standard Libraries - SNSystems/sn-musl-prepo GitHub Wiki
After porting the musl-libc to the program repository, we want to use the musl-libc to build other LLVM projects. The repo.cmake file is modified to support of building the project using musl libc library and the LLVM libc++ library.
Build LLVM runtime libraries using musl libc library.
To build pstore-write with repo-based standard libraries, some LLVM runtime libraries need to be build using the musl libc library. LLVM runtime libraries include the unwind library, compiler-rt, c++ ABI library and libc++ library. The following environment variables are defined.
* The path of the directory in which llvm-project-prepo sources is checked out from git.
LLVM_REPO = ${HOME}/llvm-project-prepo
* The cmake toolchain file which is used to use repo compiler and repo-based C/C++ static libraries.
TOOLCHAIN_FILE=$(LLVM_REPO)/llvm/utils/repo/repo.cmake
* The path of the llvm-project-prepo build directory.
LLVM_BUILD = ${LLVM_REPO}/build
* The path of the directory in which llvm libraries are installed.
LLVM = ${HOME}/LLVM
* The path of the directory in which musl libc is installed.
MUSL = ${HOME}/musl
Prerequisites:
- The musl-prepo libc library is installed in the $(MUSL) directory.
- llvm-project-prepo is built in the $(LLVM_BUILD) directory.
Build and install the unwind library via:
cd $(LLVM_REPO)
mkdir build_libunwind && cd build_libunwind
cmake -D musl=Yes \
-D CMAKE_BUILD_TYPE=Release \
-D LLVM_PATH=../ \
-D LIBUNWIND_ENABLE_SHARED=No \
-D LIBUNWIND_ENABLE_STATIC=Yes \
-D LLVM_ENABLE_UNWIND_TABLES=OFF \
-D CMAKE_TOOLCHAIN_FILE=$(TOOLCHAIN_FILE) \
-D CMAKE_CXX_COMPILER=$(LLVM_BUILD)/bin/clang++ \
-D CMAKE_C_COMPILER=$(LLVM_BUILD)/bin/clang \
-D CMAKE_INSTALL_PREFIX=$(LLVM) \
-D musl_install=$(MUSL) \
../libunwind
make -j 8
make install
Build and install the compiler-rt library via:
cd $(LLVM_REPO)
mkdir build_libcompiler-rt && cd build_libcompiler-rt
cmake -D musl=Yes \
-D CMAKE_BUILD_TYPE=Release \
-D LLVM_CONFIG_PATH=$(LLVM_BUILD)/bin/llvm-config \
-D COMPILER_RT_DEFAULT_TARGET_ONLY=ON \
-D COMPILER_RT_BUILD_BUILTINS=ON \
-D COMPILER_RT_BUILD_SANITIZERS=OFF \
-D COMPILER_RT_BUILD_XRAY=OFF \
-D COMPILER_RT_BUILD_LIBFUZZER=OFF \
-D COMPILER_RT_BUILD_PROFILE=OFF \
-D LLVM_ENABLE_UNWIND_TABLES=OFF \
-D CMAKE_TOOLCHAIN_FILE=$(TOOLCHAIN_FILE) \
-D CMAKE_CXX_COMPILER=$(LLVM_BUILD)/bin/clang++ \
-D CMAKE_C_COMPILER=$(LLVM_BUILD)/bin/clang \
-D CMAKE_INSTALL_PREFIX=$(LLVM) \
-D musl_install=$(MUSL) \
../compiler-rt
make -j 8
make install
Build and install the libc++abi library via:
cd $(LLVM_REPO)
mkdir build_libcxxabi && cd build_libcxxabi
cmake -D musl=Yes \
-D CMAKE_BUILD_TYPE=Release \
-D libcxxabi_include=-I$(LLVM_BUILD)/lib/clang/11.0.0/include/ \
-D LIBCXXABI_ENABLE_EXCEPTIONS=OFF \
-D LLVM_PATH=../ \
-D LIBCXXABI_USE_COMPILER_RT=YES \
-D LIBCXXABI_ENABLE_SHARED=No \
-D LIBCXXABI_ENABLE_STATIC=Yes \
-D LLVM_ENABLE_UNWIND_TABLES=OFF \
-D CMAKE_TOOLCHAIN_FILE=$(TOOLCHAIN_FILE) \
-D CMAKE_CXX_COMPILER=$(LLVM_BUILD)/bin/clang++ \
-D CMAKE_C_COMPILER=$(LLVM_BUILD)/bin/clang \
-D CMAKE_INSTALL_PREFIX=$(LLVM) \
-D musl_install=$(MUSL) \
../libcxxabi
make -j 8
make install
Build and install the libc++ library via:
cd $(LLVM_REPO)
mkdir build_libcxx && cd build_libcxx
cmake -D musl=Yes \
-D CMAKE_BUILD_TYPE=Release \
-D LIBCXX_ENABLE_SHARED=No \
-D LIBCXX_ENABLE_STATIC=Yes \
-D LIBCXX_CXX_ABI=libcxxabi \
-D LIBCXX_CXX_ABI_INCLUDE_PATHS=../libcxxabi/include \
-D LIBCXX_HAS_MUSL_LIBC=ON \
-D LLVM_ENABLE_UNWIND_TABLES=OFF \
-D CMAKE_TOOLCHAIN_FILE=$(TOOLCHAIN_FILE) \
-D CMAKE_CXX_COMPILER=$(LLVM_BUILD)/bin/clang++ \
-D CMAKE_C_COMPILER=$(LLVM_BUILD)/bin/clang \
-D CMAKE_INSTALL_PREFIX=$(LLVM) \
-D musl_install=$(MUSL) \
../libcxx
make -j 8
make install
The Makefile file is used to build the LLVM runtime libraries.
Build and test pstore-write project with installed musl libc and LLVM runtime libraries
Use the following series of commands to build the pstore-write project.
cd $(LLVM_REPO)
rm -rf build_pstore
mkdir build_pstore && cd build_pstore
cmake -G Ninja \
-Dmusl=Yes \
-Dlibcxx=Yes \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_PROJECTS="pstore" \
-DPSTORE_ENABLE_BROKER=OFF \
-DLLVM_ENABLE_UNWIND_TABLES=OFF \
-DCMAKE_TOOLCHAIN_FILE=$(TOOLCHAIN_FILE) \
-DCMAKE_CXX_COMPILER=$(LLVM_BUILD)/bin/clang++ \
-DCMAKE_C_COMPILER=$(LLVM_BUILD)/bin/clang \
-Dutils_dir=$(LLVM_REPO)/llvm/utils/repo \
-Dllvm_install=$(LLVM) \
-Dmusl_install=$(MUSL) \
../llvm
ninja pstore-write
To check the functionality of the pstore-write, we could follow a procedure like the one on the pstore project readme. I checked and all steps work fine.