add container build system for llvm (we will work on stripping later)

This commit is contained in:
Lily Tsuru 2023-07-17 00:10:31 -04:00
parent 8d7e8c3a11
commit 42dcddafdb
4 changed files with 68 additions and 43 deletions

30
Containerfile.llvm Normal file
View File

@ -0,0 +1,30 @@
# the base layer.
FROM debian:oldstable AS base
ENV DEBIAN_FRONTEND="noninteractive"
RUN apt-get update
# base layer for building
FROM base AS build-base
WORKDIR /build
ARG BUILD_DEPS="curl ca-certificates build-essential python3 cmake ninja-build pkg-config git zlib1g-dev"
RUN apt-get install -y --no-install-recommends $BUILD_DEPS
# This comes with the LLVM source code extracted to /build/llvm
FROM build-base as llvm-base
ARG LLVM_SOURCE_URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-16.0.0/llvm-project-16.0.0.src.tar.xz"
ARG LLVM_VERSION="16"
RUN mkdir llvm && \
cd llvm && \
curl -L $LLVM_SOURCE_URL | tar --strip-components=1 -xJf -
# This will launch the builder script.
# /build/llvm-bin is expected to be mounted to a host directory.
FROM llvm-base as llvm-build
COPY scripts/build_llvm.sh .
ENTRYPOINT ["/bin/bash", "-xeuo", "pipefail", "-O", "globstar", "-O", "dotglob"]
CMD [ "/build/build_llvm.sh" ]

View File

@ -13,6 +13,15 @@ It provides:
TODO: Steps to build the LCPU native module on Windows and Linux TODO: Steps to build the LCPU native module on Windows and Linux
LLVM is built using a podman container (see Containerfile). The steps for replicating this build follow:
```
mkdir llvm_build
podman build -t llvm-build -f Containerfile.llvm
podman run --cpus 16 -m 8G --mount type=bind,source=$PWD/llvm_build,destination=/build/llvm-bin localhost/llvm-build
```
# Installation # Installation
This repository is set up in the exact directory structure a Legacy Addon; therefore once you have built the native module (TODO), adding it to a server should work fine. This repository is set up in the exact directory structure to be a Legacy Addon; therefore once you have built the native module (TODO), adding it to a server should work fine.

View File

@ -1,42 +0,0 @@
#!/bin/bash
# this script builds llvm components
LLVM_VERSION=16.0.0
LLVM_URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-$LLVM_VERSION/llvm-project-$LLVM_VERSION.src.tar.xz"
LLVM_FILENAME="llvm-project-$LLVM_VERSION.src.tar.xz"
# download/extract LLVM (if need be)
[[ ! -d 'llvm_src' ]] && {
curl -LO $LLVM_URL
tar xf $LLVM_FILENAME
mv llvm-project-$LLVM_VERSION.src llvm_src/
rm $LLVM_FILENAME
};
# Configure LLVM. THis is a mouthful, but it's only a mouthful because we specialize things we don't
# want in our minimal build of the LLVM project/clang.
# -DLLVM_ENABLE_LTO=Thin
cmake -GNinja -S llvm_src/llvm -B llvm_build \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_INSTALL_PREFIX="$PWD/lua/bin/llvm" \
-DLLVM_USE_LINKER=lld \
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_ENABLE_PROJECTS="clang;lld" \
-DLLVM_TARGETS_TO_BUILD="RISCV" \
-DLLVM_DEFAULT_TARGET_TRIPLE="riscv32-none-gnu"
# TODO: Configure and build compiler-rt with our toolchain.
#cmake -GNinja -S llvm_src/compiler-rt \
# -DCOMPILER_RT_BUILD_SANITIZERS=OFF \
# -DCOMPILER_RT_BUILD_LIBFUZZER=OFF \
# -DCOMPILER_RT_BUILD_PROFILE=OFF \
# -DCOMPILER_RT_BUILD_MEMPROF=OFF \
# -DCOMPILER_RT_BUILD_ORC=OFF \
# -DCOMPILER_RT_BAREMETAL_BUILD=ON
# Build it
cmake --build llvm_build -j $(($(nproc) + 1))

28
scripts/build_llvm.sh Executable file
View File

@ -0,0 +1,28 @@
#!/bin/bash
# This script builds the llvm components used by the LCPU addon.
# This is run in a debian container to try and keep everything ABI stable
JOBS=$(nproc)
# Configure LLVM. THis is a mouthful, but it's only a mouthful because we specialize things we don't
# want in our minimal build of the LLVM project/clang.
cmake -GNinja -S /build/llvm/llvm -B /build/llvm-bin/build \
-DCMAKE_BUILD_TYPE=MinSizeRel \
-DCMAKE_INSTALL_PREFIX="/build/llvm-bin/install" \
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_ENABLE_PROJECTS="clang;lld" \
-DLLVM_TARGETS_TO_BUILD="RISCV" \
-DLLVM_DEFAULT_TARGET_TRIPLE="riscv32-none-gnu"
ninja -C /build/llvm-bin/build -j $JOBS
# TODO: Configure and build compiler-rt with our toolchain.
#cmake -GNinja -S llvm_src/compiler-rt \
# -DCOMPILER_RT_BUILD_SANITIZERS=OFF \
# -DCOMPILER_RT_BUILD_LIBFUZZER=OFF \
# -DCOMPILER_RT_BUILD_PROFILE=OFF \
# -DCOMPILER_RT_BUILD_MEMPROF=OFF \
# -DCOMPILER_RT_BUILD_ORC=OFF \
# -DCOMPILER_RT_BAREMETAL_BUILD=ON