diff --git a/Dockerfile.llvm b/Dockerfile.llvm new file mode 100644 index 0000000..15c5b3c --- /dev/null +++ b/Dockerfile.llvm @@ -0,0 +1,14 @@ +FROM ubuntu:jammy + +RUN apt-get update +RUN apt-get install -y \ + build-essential \ + clang-14 \ + clang++-14 \ + cmake \ + libc6-dev-i386 \ + python3-pip \ + python3-distutils \ + vim \ + ninja-build \ + git diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..a1ac56d --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,121 @@ +#!groovy + +/** + * This Jenkinsfile will only work in a Swift Navigation build/CI environment, as it uses + * non-public docker images and pipeline libraries. + */ + +// Use 'ci-jenkins@somebranch' to pull shared lib from a different branch than the default. +// Default is configured in Jenkins and should be from "stable" tag. +@Library("ci-jenkins") import com.swiftnav.ci.* + +def context = new Context(context: this) +context.setRepo("swift-toolchains") + +/** + * - Mount the refrepo to keep git operations functional on a repo that uses ref-repo during clone + **/ +String dockerMountArgs = "-v /mnt/efs/refrepo:/mnt/efs/refrepo" + +pipeline { + // Override agent in each stage to make sure we don't share containers among stages. + agent any + options { + // Make sure job aborts after 2 hours if hanging. + timeout(time: 4, unit: 'HOURS') + timestamps() + // Keep builds for 7 days. + buildDiscarder(logRotator(daysToKeepStr: '7')) + } + + stages { + stage('Build') { + parallel { + stage('llvm x86_64 linux') { + agent { + dockerfile { + filename "Dockerfile.llvm" + } + } + steps { + sh(''' + git clone https://github.com/llvm/llvm-project --branch=llvmorg-14.0.6 --single-branch + cd llvm-project + + mkdir build + cd build + + cmake -GNinja ../llvm \ + -DCMAKE_INSTALL_PREFIX=../out/ \ + -C ../../llvm/Distribution.cmake + ninja stage2-install-distribution + ''') + uploadDistribution("clang+llvm-14.0.6-x86_64-linux", context) + } + } + stage('llvm aarch64 darwin') { + agent { + node('macos-arm64') + } + steps { + sh(''' + git clone https://github.com/llvm/llvm-project --branch=llvmorg-14.0.6 --single-branch + cd llvm-project + + mkdir build + cd build + + cmake -GNinja ../llvm \ + -DCMAKE_INSTALL_PREFIX=../out/ \ + -DCMAKE_OSX_ARCHITECTURES='arm64' \ + -DCMAKE_C_COMPILER=`which clang` \ + -DCMAKE_CXX_COMPILER=`which clang++` \ + -DCMAKE_BUILD_TYPE=Release \ + -C ../../llvm/Distribution.cmake + ninja stage2-install-distribution + ''') + uploadDistribution("clang+llvm-14.0.6-arm64-apple-darwin", context) + } + } + stage('llvm x86_64 darwin') { + agent { + node('macos') + } + steps { + sh(''' + git clone https://github.com/llvm/llvm-project --branch=llvmorg-14.0.6 --single-branch + cd llvm-project + mkdir build + cd build + cmake -GNinja ../llvm \ + -DCMAKE_INSTALL_PREFIX=../out/ \ + -DCMAKE_OSX_ARCHITECTURES='x86_64' \ + -DLLVM_ENABLE_RUNTIMES='compiler-rt;libcxx;libcxxabi' \ + -DCMAKE_C_COMPILER=`which clang` \ + -DCMAKE_CXX_COMPILER=`which clang++` \ + -DCMAKE_BUILD_TYPE=Release \ + -C ../../llvm/Distribution.cmake + ninja stage2-install-distribution + ''') + uploadDistribution("clang+llvm-14.0.6-x86_64-apple-darwin", context) + } + } + } + } + } +} + +def uploadDistribution(name, context) { + sh(""" + mkdir -p tar/${name}/ + cp -rH llvm-project/out/* tar/${name}/ + """) + tar(file: "${name}.tar.gz", dir: 'tar', archive: true) + script{ + context.archivePatterns( + patterns: ["${name}.tar.gz"], + path: "swift-toolchains/${context.gitDescribe()}/${name}.tar.gz", + jenkins: false + ) + } +} diff --git a/llvm/Distribution-stage2.cmake b/llvm/Distribution-stage2.cmake new file mode 100644 index 0000000..f661665 --- /dev/null +++ b/llvm/Distribution-stage2.cmake @@ -0,0 +1,37 @@ +# This file sets up a CMakeCache for the second stage of a simple distribution +# bootstrap build. + +set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;lld" CACHE STRING "") +set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "") + +set(COMPILER_RT_BUILD_BUILTINS ON CACHE BOOL "") + +set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "") + +set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "") +set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -gline-tables-only -DNDEBUG" CACHE STRING "") +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -gline-tables-only -DNDEBUG" CACHE STRING "") + +# setup toolchain +set(LLVM_INSTALL_TOOLCHAIN_ONLY ON CACHE BOOL "") +set(LLVM_TOOLCHAIN_TOOLS + llvm-ar + llvm-cov + llvm-dwp + llvm-nm + llvm-objcopy + llvm-objdump + llvm-profdata + llvm-strip + llvm-symbolizer + CACHE STRING "") + +set(LLVM_DISTRIBUTION_COMPONENTS + clang + lld + builtins + runtimes + clang-resource-headers + clang-tidy + ${LLVM_TOOLCHAIN_TOOLS} + CACHE STRING "") diff --git a/llvm/Distribution.cmake b/llvm/Distribution.cmake new file mode 100644 index 0000000..fdc2f0c --- /dev/null +++ b/llvm/Distribution.cmake @@ -0,0 +1,36 @@ +# This file sets up a CMakeCache for a simple distribution bootstrap build. + +#Enable LLVM projects and runtimes +set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;lld" CACHE STRING "") + +# Only build the native target in stage1 since it is a throwaway build. +set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "") + +# Optimize the stage1 compiler, but don't LTO it because that wastes time. +set(CMAKE_BUILD_TYPE Release CACHE STRING "") + +# Setup vendor-specific settings. +set(PACKAGE_VENDOR LLVM.org CACHE STRING "") + +# Setting up the stage2 LTO option needs to be done on the stage1 build so that +# the proper LTO library dependencies can be connected. +set(BOOTSTRAP_LLVM_ENABLE_LTO ON CACHE BOOL "") + +if (NOT APPLE) + # Since LLVM_ENABLE_LTO is ON we need a LTO capable linker + set(BOOTSTRAP_LLVM_ENABLE_LLD ON CACHE BOOL "") +endif() + +# Expose stage2 targets through the stage1 build configuration. +set(CLANG_BOOTSTRAP_TARGETS + distribution + install-distribution + clang CACHE STRING "") + +# Setup the bootstrap build. +set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "") + +set(CLANG_BOOTSTRAP_CMAKE_ARGS + -C ${CMAKE_CURRENT_LIST_DIR}/Distribution-stage2.cmake + CACHE STRING "") +