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..014c1f4 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,85 @@ +#!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 aarch64 darwin') { + agent { + node('macos-arm64') + } + steps { + sh(''' + git clone https://github.com/llvm/llvm-project --branch=llvmorg-14.0.0 --single-branch + cd llvm-project + + mkdir build + cd build + + cmake -GNinja ../llvm \ + -DCMAKE_INSTALL_PREFIX=../out/ \ + -DCMAKE_C_COMPILER_LAUNCHER=sccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=sccache \ + -DCMAKE_OSX_ARCHITECTURES='arm64' \ + -DCMAKE_C_COMPILER=`which clang` \ + -DCMAKE_CXX_COMPILER=`which clang++` \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=../out \ + -DLLVM_ENABLE_PROJECTS='clang' \ + -DLLVM_DISTRIBUTION_COMPONENTS='clang' \ + -C ../../llvm/Apple-stage1.cmake + ninja help + ninja stage2-install-distribution + ''') + uploadDistribution("clang+llvm-14.0.0-arm64-apple-darwin", context) + } + post { + cleanup { + cleanWs() + } + } + } + } + } + } + post { + always { + cleanWs() + } + } +} + +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) +} diff --git a/llvm/Apple-stage1.cmake b/llvm/Apple-stage1.cmake new file mode 100644 index 0000000..5e55231 --- /dev/null +++ b/llvm/Apple-stage1.cmake @@ -0,0 +1,62 @@ +# This file sets up a CMakeCache for Apple-style bootstrap builds. It can be +# used on any Darwin system to approximate Apple Clang builds. + +if($ENV{DT_TOOLCHAIN_DIR}) + set(CMAKE_INSTALL_PREFIX $ENV{DT_TOOLCHAIN_DIR}/usr/) +else() + set(CMAKE_INSTALL_PREFIX /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.toolchain/usr/) +endif() + +set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra" CACHE STRING "") + +set(LLVM_TARGETS_TO_BUILD AArch64 CACHE STRING "") +set(CLANG_VENDOR Apple CACHE STRING "") +set(LLVM_INCLUDE_TESTS OFF CACHE BOOL "") +set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "") +set(LLVM_INCLUDE_UTILS OFF CACHE BOOL "") +set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "") +set(CLANG_INCLUDE_TESTS OFF CACHE BOOL "") +set(COMPILER_RT_INCLUDE_TESTS OFF CACHE BOOL "") +set(COMPILER_RT_BUILD_SANITIZERS OFF CACHE BOOL "") +set(CMAKE_MACOSX_RPATH ON CACHE BOOL "") +set(LLVM_ENABLE_ZLIB OFF CACHE BOOL "") +set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "") +set(CLANG_PLUGIN_SUPPORT OFF CACHE BOOL "") +set(CLANG_SPAWN_CC1 ON CACHE BOOL "") +set(CLANG_BOOTSTRAP_PASSTHROUGH + CMAKE_OSX_ARCHITECTURES + CACHE STRING "") + +# Disabling embedded darwin compiler-rt on stage1 builds is required because we +# don't build stage1 to support arm code generation. +set(COMPILER_RT_ENABLE_IOS OFF CACHE BOOL "") +set(COMPILER_RT_ENABLE_WATCHOS OFF CACHE BOOL "") +set(COMPILER_RT_ENABLE_TVOS OFF CACHE BOOL "") + +set(BOOTSTRAP_LLVM_ENABLE_LTO ON CACHE BOOL "") +set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "") + +set(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE BOOL "") +set(LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS ON CACHE BOOL "") + +set(CLANG_BOOTSTRAP_TARGETS + generate-order-file + check-all + check-llvm + check-clang + llvm-config + test-suite + test-depends + llvm-test-depends + clang-test-depends + distribution + install-distribution + install-xcode-toolchain + install-distribution-toolchain + clang CACHE STRING "") + +#bootstrap +set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "") +set(CLANG_BOOTSTRAP_CMAKE_ARGS + -C ${CMAKE_CURRENT_LIST_DIR}/Apple-stage2.cmake + CACHE STRING "") \ No newline at end of file diff --git a/llvm/Apple-stage2-ThinLTO.cmake b/llvm/Apple-stage2-ThinLTO.cmake new file mode 100644 index 0000000..54e54e3 --- /dev/null +++ b/llvm/Apple-stage2-ThinLTO.cmake @@ -0,0 +1,6 @@ +# This file sets up a CMakeCache for Apple-style stage2 ThinLTO bootstrap. It is +# specified by the stage1 build. + + +set(LLVM_ENABLE_LTO THIN CACHE BOOL "") +include(${CMAKE_CURRENT_LIST_DIR}/Apple-stage2.cmake) diff --git a/llvm/Apple-stage2.cmake b/llvm/Apple-stage2.cmake new file mode 100644 index 0000000..0ca1fd4 --- /dev/null +++ b/llvm/Apple-stage2.cmake @@ -0,0 +1,46 @@ +# This file sets up a CMakeCache for Apple-style stage2 bootstrap. It is +# specified by the stage1 build. + +set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra" CACHE STRING "") +set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "") + +set(LLVM_TARGETS_TO_BUILD AArch64 CACHE STRING "") +set(PACKAGE_VENDOR Apple CACHE STRING "") + +set(CMAKE_MACOSX_RPATH ON CACHE BOOL "") + +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 "") + +# Generating Xcode toolchains is useful for developers wanting to build and use +# clang without installing over existing tools. +# set(LLVM_CREATE_XCODE_TOOLCHAIN ON CACHE BOOL "") + +# 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 + clang-format + builtins + runtimes + clang-resource-headers + # clang-tidy + ${LLVM_TOOLCHAIN_TOOLS} + CACHE STRING "") + +# test args + +set(LLVM_LIT_ARGS "--xunit-xml-output=testresults.xunit.xml -v" CACHE STRING "") diff --git a/patches/0003-Add-missing-include-diagnosed-by-the-modules-build.patch b/patches/0003-Add-missing-include-diagnosed-by-the-modules-build.patch new file mode 100644 index 0000000..4dba31b --- /dev/null +++ b/patches/0003-Add-missing-include-diagnosed-by-the-modules-build.patch @@ -0,0 +1,24 @@ +From 4904e853130825d1c6fa93faf289e1ccf2f01c68 Mon Sep 17 00:00:00 2001 +From: Adrian Prantl +Date: Wed, 2 Feb 2022 09:08:11 -0800 +Subject: [PATCH] Add missing include diagnosed by the modules build. + +--- + llvm/include/llvm/Transforms/InstCombine/InstCombine.h | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/llvm/include/llvm/Transforms/InstCombine/InstCombine.h b/llvm/include/llvm/Transforms/InstCombine/InstCombine.h +index 6dee38c83b36..35a3a8c3218b 100644 +--- a/llvm/include/llvm/Transforms/InstCombine/InstCombine.h ++++ b/llvm/include/llvm/Transforms/InstCombine/InstCombine.h +@@ -18,6 +18,7 @@ + + #include "llvm/IR/Function.h" + #include "llvm/IR/PassManager.h" ++#include "llvm/Pass.h" + + #define DEBUG_TYPE "instcombine" + #include "llvm/Transforms/Utils/InstructionWorklist.h" +-- +2.34.1 +