Skip to content

Commit

Permalink
Merge pull request #634 from andreasfertig/inSourceBuildTest
Browse files Browse the repository at this point in the history
Building C++ Insights inside LLVM source tree test.
  • Loading branch information
andreasfertig authored Apr 9, 2024
2 parents acba6ec + fafa45e commit d8327f6
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 16 deletions.
56 changes: 55 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -630,11 +630,65 @@ jobs:
if-no-files-found: error
path: |
${{ github.workspace }}/build/archive/*
#------------------------------------------------------------------------------
# BUILD INSIDE DOCKER INSIDE LLVM-SOURCE-TREE
#------------------------------------------------------------------------------
in-source-tree:
runs-on: ubuntu-22.04
name: ${{ matrix.config.name }} LLVM source tree
container:
image: andreasfertig/cppinsights-builder
continue-on-error: false
strategy:
fail-fast: false
matrix:
arch:
- amd64

config:
# GCC 13 / LLVM 18
- {
name: "GCC 13 / LLVM 18 @ Ubuntu Release",
build_type: Release,
cxx: "g++-13",
llvm_version: "18.1.0",
llvm_config: "/usr/bin/llvm-config-18",
coverage: "No",
static: "Yes",
debug: "No",
libcxx: "No",
}

steps:
- uses: actions/checkout@v4
with:
path: cppinsights

- uses: actions/checkout@v4
name: Checkout Clang
with:
repository: llvm/llvm-project
ref: llvmorg-${{ env.LLVM_VERSION }}
path: llvm-project
fetch-tags: true

- name: Configure
id: cmake_configure
shell: bash
run: |
mkdir build
cd build
CXX=${{ matrix.config.cxx }}
cmake -G Ninja -D=CMAKE_BUILD_TYPE=Release -DLLVM_EXTERNAL_PROJECTS=cppinsights -DLLVM_EXTERNAL_CPPINSIGHTS_SOURCE_DIR=${GITHUB_WORKSPACE}/cppinsights -DINSIGHTS_STATIC=${{ matrix.config.static }} -DDEBUG=${{ matrix.config.debug }} -DINSIGHTS_COVERAGE=${{ matrix.config.coverage }} -DINSIGHTS_USE_LIBCPP=${{ matrix.config.libcxx }} ${GITHUB_WORKSPACE}/llvm-project/llvm
# For now a successful configure is enough
#------------------------------------------------------------------------------
# DEPLOY
#------------------------------------------------------------------------------
deploy:
needs: [build, docker]
needs: [build, docker, in-source-tree]
if: github.ref == 'refs/heads/main'
name: Final Deploy
continue-on-error: false
Expand Down
24 changes: 18 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,18 @@ set(INSIGHTS_LLVM_CONFIG "llvm-config" CACHE STRING "LLVM config executable to u
set(INSIGHTS_MIN_LLVM_MAJOR_VERSION 18)
set(INSIGHTS_MIN_LLVM_VERSION ${INSIGHTS_MIN_LLVM_MAJOR_VERSION}.0)

if(NOT DEFINED LLVM_VERSION_MAJOR) # used when build inside the clang tool/extra folder
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(BUILD_INSIGHTS_OUTSIDE_LLVM On)
else()
# used when build inside the clang tool/extra folder
set(BUILD_INSIGHTS_OUTSIDE_LLVM Off)
include_directories(BEFORE
${LLVM_SOURCE_DIR}/include
${LLVM_EXTERNAL_CLANG_SOURCE_DIR}/include
${LLVM_BINARY_DIR}/include
${LLVM_BINARY_DIR}/tools/clang/include
)

endif()

if(INSIGHTS_COVERAGE OR DEBUG)
Expand Down Expand Up @@ -367,11 +377,6 @@ if (BUILD_INSIGHTS_OUTSIDE_LLVM)
set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${COVERAGE_LINK_FLAGS}")
endif()

# copied from: llvm/tools/clang/cmake/modules/AddClang.cmake
macro(add_clang_tool name)
add_executable( ${name} ${ARGN} )
endmacro(add_clang_tool)

# additional libs required when building insights outside llvm
set(ADDITIONAL_LIBS
${LLVM_LDFLAGS}
Expand Down Expand Up @@ -422,6 +427,12 @@ if (${LLVM_PACKAGE_VERSION} VERSION_LESS ${INSIGHTS_MIN_LLVM_VERSION})
message(FATAL_ERROR "LLVM version ${INSIGHTS_MIN_LLVM_VERSION} or higher required. Current version is: ${LLVM_PACKAGE_VERSION}.")
endif()

# copied from: llvm/tools/clang/cmake/modules/AddClang.cmake
macro(add_clang_tool name)
add_executable( ${name} ${ARGN} )
endmacro(add_clang_tool)



if(WIN32)
# First for the generic no-config case (e.g. with mingw)
Expand Down Expand Up @@ -815,6 +826,7 @@ endif()

message(STATUS "")
message(STATUS "[ Build summary ]")
message(STATUS "BUILD_INSIGHTS_OUTSIDE_LLVM : ${BUILD_INSIGHTS_OUTSIDE_LLVM}")
message(STATUS "CMAKE_GENERATOR : ${CMAKE_GENERATOR}")
message(STATUS "CMAKE_EXE_LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS}")
message(STATUS "CMAKE_LINKER : ${CMAKE_LINKER}")
Expand Down
16 changes: 7 additions & 9 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ See https://github.com/andreasfertig/cppinsights/issues/186 for an explanation o
`extra/clang` and `extra/llvm` provide `/usr/lib/{libclangAST.so,libLLVM*.a,libLLVM.so}`. `libclangAST.so` needs `libLLVM.so` and there would be a conflict if `libLLVM*.a` (instead of `libLLVM.so`) are linked. See https://bugs.archlinux.org/task/60512
### Building outside Clang
You need to have a Clang installation in the search path.
Expand All @@ -144,23 +145,20 @@ The resulting binary (insights) can be found in the `build` folder.
### Building inside Clang
For building it inside the Clang source tree, assuming you have your source tree already prepared under `llvm-project`:
The easiest way to build C++ Insights inside the Clang source tree is using the `LLVM_EXTERNAL_PROJECTS` option.
```
cd llvm-project/clang-tools-extra/
git clone https://github.com/llvm/llvm-project.git
git clone https://github.com/andreasfertig/cppinsights.git
echo "add_subdirectory(cppinsights)" >> CMakeLists.txt
```
To activate the C++ Insights build you have to set `-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra"` for `cmake`:
mkdir build
cd build
cmake -G Ninja -D=CMAKE_BUILD_TYPE=Release -DLLVM_EXTERNAL_PROJECTS=cppinsights -DLLVM_EXTERNAL_CPPINSIGHTS_SOURCE_DIR=<PATH/TO/cppinsights> [INSIGHTS CMAKE OPTIONS] ../llvm-project/llvm
```
cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -G "Unix Makefiles" ../llvm-project
ninja
```
Then, build Clang as you normally do.
### cmake options
Expand Down

0 comments on commit d8327f6

Please sign in to comment.