diff --git a/.github/workflows/build-llvm.yaml b/.github/workflows/build-llvm.yaml new file mode 100644 index 0000000..1bfd4e7 --- /dev/null +++ b/.github/workflows/build-llvm.yaml @@ -0,0 +1,58 @@ +name: "Build LLVM" + +on: + workflow_dispatch: + inputs: + tag: + description: 'Git tag for the release.' + required: true + type: string + +jobs: + build_llvm: + name: Build LLVM + strategy: + matrix: + # os: [ubuntu-20.04, macos-11, windows-2019] + os: [ubuntu-20.04] + runs-on: ${{ matrix.os }} + permissions: + contents: write # for creating releases + container: + # Intentionally old ubuntu version with old glibc. + image: ubuntu:18.04 + steps: + - name: checkout + uses: actions/checkout@v3 + + # Install build dependencies. + - run: "apt update && apt install -y clang git wget build-essential python3 ninja-build" + # cmake from package manager is to old for the LLVM build. + - run: "wget https://github.com/Kitware/CMake/releases/download/v3.30.0-rc2/cmake-3.30.0-rc2-linux-x86_64.sh" + - run: "chmod +x cmake-*.sh" + - run: "./cmake-*.sh --skip-license --prefix=/usr" + # Build and package LLVM. + - run: "./build-llvm-libs.sh" + - uses: actions/upload-artifact@v3 + with: + name: llvm-static-libs + path: llvm-static-libs.tar.gz + - name: create release + id: create-release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ inputs.tag }} + release_name: ${{ inputs.tag }} + draft: false + prerelease: true + - name: upload linux artifact + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + upload_url: ${{ steps.create-release.outputs.upload_url }} + asset_path: ./llvm-static-libs.tar.gz + asset_name: llvm-static-linux-amd64.tar.gz + asset_content_type: application/gzip diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..5ef866c --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,46 @@ +cmake_minimum_required(VERSION 3.5) +project(llvm-static) + +if(POLICY CMP0114) + cmake_policy(SET CMP0114 NEW) +endif() + +# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24: +if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0") + cmake_policy(SET CMP0135 NEW) +endif() + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +# set(CMAKE_POSITION_INDEPENDENT_CODE ON) +set(CMAKE_BUILD_TYPE Release) + +include(ExternalProject) +ExternalProject_Add(${LLVM_PROJECT_TARGET} + PREFIX ${LLVM_PROJECT_TARGET} + GIT_REPOSITORY https://github.com/llvm/llvm-project.git + GIT_TAG llvmorg-18.1.5 + GIT_SHALLOW ON + SOURCE_SUBDIR llvm + CMAKE_ARGS + -G${CMAKE_GENERATOR} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_INSTALL_PREFIX= + -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER} + -DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER} + -DCMAKE_C_COMPILER_LAUNCHER:FILEPATH=${CMAKE_C_COMPILER_LAUNCHER} + -DCMAKE_CXX_COMPILER_LAUNCHER:FILEPATH=${CMAKE_CXX_COMPILER_LAUNCHER} + -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} + -DCMAKE_POSITION_INDEPENDENT_CODE=${CMAKE_POSITION_INDEPENDENT_CODE} + -DLLVM_ENABLE_PROJECTS=clang + -DLLVM_ENABLE_RTTI=ON + -DLLVM_ENABLE_PIC=ON + -DLLVM_TARGETS_TO_BUILD=X86 + -DLLVM_BUILD_TOOLS=OFF + -DLLVM_BUILD_TESTS=OFF + -DLLVM_ENABLE_TERMINFO=OFF + -DLLVM_ENABLE_ZLIB=OFF + -DLLVM_ENABLE_ZSTD=OFF + -DLLVM_ENABLE_LIBXML2=OFF + BUILD_COMMAND ${CMAKE_COMMAND} --build --target clangTooling -j16 +) diff --git a/README.md b/README.md index cdd4cea..4e748ac 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -# llvm-static \ No newline at end of file +# LLVM Tooling + +This repository contains scripts to build static LLVM libraries which can be used to develop libclangTooling based tools. See the release page for downloadable archives. diff --git a/build-llvm-libs.sh b/build-llvm-libs.sh new file mode 100755 index 0000000..7949f37 --- /dev/null +++ b/build-llvm-libs.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +BUILD_DIR="$SCRIPT_DIR/build" +LLVM_BUILD_DIR="$BUILD_DIR/external.llvm-project" + +cd "$SCRIPT_DIR" +mkdir -p build +# cmake -B build -GNinja . +# cmake --build build +mkdir -p $LLVM_BUILD_DIR/include +touch $LLVM_BUILD_DIR/include/clang.h +mkdir -p $LLVM_BUILD_DIR/lib +touch $LLVM_BUILD_DIR/lib/libclang.a + +# Pack everything we need into a tar archive. +# We only need the header files, static libraries and add +# a CMake file that makes it easy to link libclangTooling. +cp $SCRIPT_DIR/cmake/CMakeLists.txt $LLVM_BUILD_DIR +cd $LLVM_BUILD_DIR +tar -czvf "$SCRIPT_DIR/llvm-static-libs.tar.gz" include/ lib/*.a CMakeLists.txt diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt new file mode 100644 index 0000000..30ad904 --- /dev/null +++ b/cmake/CMakeLists.txt @@ -0,0 +1,54 @@ +# Static libraries that are needed when using libclangTooling +set(CLANG_TOOLING_DEPS + clangFormat + clangToolingInclusions + clangFrontend + clangDriver + clangParse + clangSerialization + clangSema + clangAPINotes + clangEdit + clangAnalysis + clangASTMatchers + clangAST + clangSupport + clangToolingCore + clangRewrite + clangLex + clangBasic + # Order as reported by llvm-config --libs --link-static + LLVMWindowsDriver + LLVMOption + LLVMFrontendOpenMP + LLVMFrontendOffloading + LLVMScalarOpts + LLVMTransformUtils + LLVMAnalysis + LLVMProfileData + LLVMDebugInfoDWARF + LLVMObject + LLVMTextAPI + LLVMMCParser + LLVMIRReader + LLVMAsmParser + LLVMMC + LLVMBitReader + LLVMCore + LLVMRemarks + LLVMBitstreamReader + LLVMBinaryFormat + LLVMTargetParser + LLVMSupport + LLVMDemangle) + +foreach(lib ${CLANG_TOOLING_DEPS}) + add_library(${lib} STATIC IMPORTED) + set_property(TARGET ${lib} PROPERTY IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/lib/lib${lib}.a") +endforeach(lib) + +# Exported clangTooling target. +add_library(clangTooling STATIC IMPORTED GLOBAL) +set_property(TARGET clangTooling PROPERTY IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/lib/libclangTooling.a") +target_include_directories(clangTooling INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include) +set_target_properties(clangTooling PROPERTIES INTERFACE_LINK_LIBRARIES "${CLANG_TOOLING_DEPS}")