diff --git a/.github/actions/Build_LLVM/action.yml b/.github/actions/Build_LLVM/action.yml index 4a1618175..10ecfd717 100644 --- a/.github/actions/Build_LLVM/action.yml +++ b/.github/actions/Build_LLVM/action.yml @@ -43,7 +43,8 @@ runs: ninja LLVMOrcDebugging -j ${{ env.ncpus }} ninja clingInterpreter -j ${{ env.ncpus }} else - if [[ "${{ matrix.oop-jit }}" == "On" ]]; then + llvm_vers=$(echo "${{ matrix.clang-runtime }}" | tr '[:lower:]' '[:upper:]') + if [[ "${{ matrix.oop-jit }}" == "On" && "${llvm_vers}" == "20" ]]; then git apply -v ../patches/llvm/clang20-1-out-of-process.patch echo "Apply clang20-1-out-of-process.patch:" fi diff --git a/.github/actions/Build_and_Test_CppInterOp/action.yml b/.github/actions/Build_and_Test_CppInterOp/action.yml index 873a6a5f9..e5e6cc00d 100644 --- a/.github/actions/Build_and_Test_CppInterOp/action.yml +++ b/.github/actions/Build_and_Test_CppInterOp/action.yml @@ -109,9 +109,9 @@ runs: } else { - $env:CPLUS_INCLUDE_PATH="$env:LLVM_DIR\llvm\include;$env:LLVM_DIR\clang\include;$env:LLVM_BUILD_DIR\include;$env:LLVM_BUILD_DIR\tools\clang\include;$env:PWD_DIR\include;" - echo "CPLUS_INCLUDE_PATH=$env:CPLUS_INCLUDE_PATH" - echo "CPLUS_INCLUDE_PATH=$env:CPLUS_INCLUDE_PATH" >> $env:GITHUB_ENV + $env:IncludePath="$env:IncludePath;$env:LLVM_DIR\llvm\include;$env:LLVM_DIR\clang\include;$env:LLVM_BUILD_DIR\include;$env:LLVM_BUILD_DIR\tools\clang\include;$env:PWD_DIR\include;" + echo "IncludePath=$env:IncludePath" + echo "IncludePath=$env:IncludePath" >> $env:GITHUB_ENV } $env:CB_PYTHON_DIR="$env:PWD_DIR\cppyy-backend\python" @@ -142,7 +142,7 @@ runs: { cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} ` -DLLVM_DIR="$env:LLVM_BUILD_DIR\lib\cmake\llvm" ` - -DLLVM_ENABLE_WERROR=On ` + -DLLVM_ENABLE_WERROR=On -DBUILD_SHARED_LIBS=ON ` -DClang_DIR="$env:LLVM_BUILD_DIR\lib\cmake\clang" -DCODE_COVERAGE=${{ env.CODE_COVERAGE }} -DCMAKE_INSTALL_PREFIX="$env:CPPINTEROP_DIR" ..\ } cmake --build . --config ${{ env.BUILD_TYPE }} --target check-cppinterop --parallel ${{ env.ncpus }} diff --git a/.github/actions/Build_and_Test_cppyy/action.yml b/.github/actions/Build_and_Test_cppyy/action.yml index b4c890cfd..a4efa68b6 100644 --- a/.github/actions/Build_and_Test_cppyy/action.yml +++ b/.github/actions/Build_and_Test_cppyy/action.yml @@ -138,3 +138,95 @@ runs: tail -n1 test_xfailed.log echo "Return Code: ${RETCODE}" exit $RETCODE + + - name: Build and Install cppyy-backend + if: ${{ matrix.cppyy == 'On' && runner.os == 'Windows' }} + shell: powershell + run: | + # Download cppyy-backend + git clone --depth=1 https://github.com/compiler-research/cppyy-backend.git + cd cppyy-backend + mkdir $env:CPPINTEROP_DIR\lib + mkdir build + cd build + # Install CppInterOp + cd $env:CPPINTEROP_BUILD_DIR + cmake --build . --target install --parallel ${{ env.ncpus }} + cd ..\cppyy-backend\build\ + # Build and Install cppyy-backend + cmake -DCppInterOp_DIR=$env:CPPINTEROP_DIR -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} .. + cmake --build . --config ${{ env.BUILD_TYPE }} --parallel ${{ env.ncpus }} + cp Release\libcppyy-backend.dll $env:CPPINTEROP_DIR\lib\ + cd .. + - name: Install CPyCppyy + if: ${{ matrix.cppyy == 'On' && runner.os == 'Windows' }} + shell: powershell + run: | + python -m venv .venv + . .\.venv\Scripts\Activate.ps1 + # Install CPyCppyy + git clone --depth=1 https://github.com/compiler-research/CPyCppyy.git + mkdir CPyCppyy\build + cd CPyCppyy\build + cmake .. + cmake --build . --parallel ${{ env.ncpus }} + # + env:CPYCPPYY_DIR = $PWD.Path + cd ../.. + # We need CPYCPPYY_DIR later + echo "CPYCPPYY_DIR=$env:CPYCPPYY_DIR" >> $env:GITHUB_ENV + - name: Install cppyy + if: ${{ matrix.cppyy == 'On' && runner.os == 'Windows' }} + shell: powershell + run: | + # source virtual environment + . .\.venv\Scripts\Activate.ps1 + # Install cppyy + git clone --depth=1 https://github.com/compiler-research/cppyy.git + cd cppyy + python -m pip install --upgrade . --no-deps + cd .. + - name: Run cppyy + if: ${{ matrix.cppyy == 'On' && runner.os == 'Windows' }} + shell: powershell + run: | + # Run cppyy + . .\.venv\Scripts\Activate.ps1 + $env:PYTHONPATH=$env:PYTHONPATH:$env:CPYCPPYY_DIR:$env:CB_PYTHON_DIR + python -c "import cppyy" + # We need PYTHONPATH later + echo "PYTHONPATH=$env:PYTHONPATH" >> $GITHUB_ENV + - name: Run the tests + if: ${{ matrix.cppyy == 'On' && runner.os == 'Windows' }} + shell: powershell + run: | + # Run the tests + . .\.venv\Scripts\Activate.ps1 + cd cppyy\test + echo ::group::Prepare For Testing + make all + python -m pip install --upgrade pip + python -m pip install pytest + python -m pip install pytest-xdist + python -m pip install numba + echo ::endgroup:: + echo ::group::Run complete test suite + $ErrorActionPreference = "Stop" + python -m pytest -sv -ra 2>&1 | Tee-Object -FilePath complete_testrun.log + $ErrorActionPreference = "Continue" + echo ::group::Crashing Test Logs + # See if we don't have a crash that went away + # Comment out all xfails but the ones that have a run=False condition. + find.exe . -name "*.py" -exec sed.exe -i '/run=False/!s/^ *@mark.xfail\(.*\)/#&/' {} \; + python -m pytest -n 1 -m "xfail" --runxfail -sv -ra --max-worker-restart 512 2>&1 | Tee-Object -FilePath test_crashed.log + $LASTEXITCODE = 0 + git checkout . + echo ::endgroup:: + echo ::group::XFAIL Test Logs + # Rewrite all xfails that have a run clause to skipif. This way we will + # avoid conditionally crashing xfails + find.exe . -name "*.py" -exec sed.exe -i -E 's/(^ *)@mark.xfail\(run=(.*)/\1@mark.skipif(condition=not \2/g' {} \; + # See if we don't have an xfail that went away + python -m pytest --runxfail -sv -ra | tee test_xfailed.log 2>&1 || true + git checkout . + echo ::endgroup:: diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml deleted file mode 100644 index 2be58cacb..000000000 --- a/.github/workflows/clang-format.yml +++ /dev/null @@ -1,50 +0,0 @@ -name: clang-format - -on: - pull_request: - paths: - - '**.h' - - '**.cpp' - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number }} - cancel-in-progress: true - -jobs: - precheckin: - runs-on: ubuntu-22.04 - steps: - - name: Checkout PR branch - uses: actions/checkout@v5 - with: - ref: ${{ github.event.pull_request.head.sha }} - fetch-depth: 0 - - - name: Setup Python - uses: actions/setup-python@v6 - with: - python-version: "3.11" - - - name: Install clang-format - run: | - curl https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - - os_codename="`cat /etc/os-release | grep UBUNTU_CODENAME | cut -d = -f 2`" - echo "deb https://apt.llvm.org/${os_codename}/ llvm-toolchain-${os_codename}-18 main" | sudo tee -a /etc/apt/sources.list - sudo apt update - sudo apt install -y clang-format-18 - - - name: Run git-clang-format - run: | - PR_BASE=$(git rev-list ${{ github.event.pull_request.head.sha }} ^${{ github.event.pull_request.base.sha }} | tail --lines 1 | xargs -I {} git rev-parse {}~1) - echo "running git clang-format against $PR_BASE commit" - git \ - -c color.ui=always \ - -c diff.wsErrorHighlight=all \ - -c color.diff.whitespace='red reverse' \ - clang-format-18 --diff --binary clang-format-18 --commit $PR_BASE -- include/ lib/ || \ - (echo "Please run the following git-clang-format locally to fix the formatting: \n - git-clang-format HEAD~\n - for multiple commits we should place the formatting changes in the related commit with:\n - \t\tgit rebase -i -x \"git-clang-format-18 main && git commit -a --allow-empty --fixup=HEAD\" --strategy-option=theirs origin/main\n - \t\t Then inspect the results with: git log --oneline\n - \t\t Then squash without poluting the history with: git rebase --autosquash -i main\n" && exit 1) diff --git a/.github/workflows/clang-tidy-review-post.yml b/.github/workflows/clang-tidy-review-post.yml deleted file mode 100644 index f1aecb0d4..000000000 --- a/.github/workflows/clang-tidy-review-post.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Post clang-tidy review comments - -on: - workflow_run: - workflows: ["clang-tidy-review"] - types: - - completed - -permissions: - checks: write - pull-requests: write - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number }} - cancel-in-progress: true - -jobs: - build: - runs-on: ubuntu-22.04 - - steps: - - name: Post review comments - id: post-review - uses: ZedThree/clang-tidy-review/post@v0.21.0 - with: - max_comments: 10 - - # If there are any comments, fail the check - - if: steps.post-review.outputs.total_comments > 0 - run: exit 1 \ No newline at end of file diff --git a/.github/workflows/clang-tidy-review.yml b/.github/workflows/clang-tidy-review.yml deleted file mode 100644 index 70ea9b12e..000000000 --- a/.github/workflows/clang-tidy-review.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: clang-tidy-review - -on: - pull_request: - paths: - - '**.h' - - '**.cpp' - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number }} - cancel-in-progress: true - -jobs: - review: - runs-on: ubuntu-22.04 - steps: - - name: Checkout PR branch - uses: actions/checkout@v5 - - - name: Setup Python - uses: actions/setup-python@v6 - with: - python-version: "3.11" - - - name: Install LLVM and Clang - uses: KyleMayes/install-llvm-action@v2.0.7 - with: - version: "20.1.4" - - - name: install lit - run: pip install lit - - - name: Run clang-tidy - uses: ZedThree/clang-tidy-review@v0.21.0 - id: review - with: - build_dir: build - apt_packages: cmake,libxml2,libxml2-dev,libtinfo-dev,zlib1g-dev,libzstd-dev - split_workflow: true - config_file: .clang-tidy - cmake_command: > - cmake . -B build -DCMAKE_BUILD_TYPE="Release" - -DCMAKE_C_COMPILER="$GITHUB_WORKSPACE/llvm/bin/clang" - -DCMAKE_CXX_COMPILER="$GITHUB_WORKSPACE/llvm/bin/clang++" - -DLLVM_DIR="$GITHUB_WORKSPACE/llvm" - -DBUILD_SHARED_LIBS=ON - -DCMAKE_EXPORT_COMPILE_COMMANDS=ON && - cd build && - cmake --build . --target googletest --parallel $(nproc --all) - - - name: Upload artifacts - uses: ZedThree/clang-tidy-review/upload@v0.21.0 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9db2b1d90..d5a9b0ac4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,9 +2,9 @@ name: Native Builds on: pull_request: - branches: [main] + branches: [CppInterOp-main] push: - branches: [main] + branches: [CppInterOp-main] release: types: [published] schedule: @@ -22,202 +22,20 @@ jobs: fail-fast: false matrix: include: - # Ubuntu Arm Jobs - - name: ubu24-arm-gcc12-clang-repl-20 - os: ubuntu-24.04-arm - compiler: gcc-12 - clang-runtime: '20' - cling: Off - cppyy: Off - llvm_enable_projects: "clang" - llvm_targets_to_build: "host;NVPTX" - Valgrind: On - - name: ubu24-arm-gcc12-clang-repl-19-cppyy - os: ubuntu-24.04-arm - compiler: gcc-12 - clang-runtime: '19' - cling: Off - cppyy: On - llvm_enable_projects: "clang" - llvm_targets_to_build: "host;NVPTX" - - name: ubu24-arm-gcc12-clang-repl-18-cppyy - os: ubuntu-24.04-arm - compiler: gcc-12 - clang-runtime: '18' - cling: Off - cppyy: On - llvm_enable_projects: "clang" - llvm_targets_to_build: "host;NVPTX" - - name: ubu24-arm-gcc9-clang18-cling-cppyy - os: ubuntu-24.04-arm - compiler: gcc-9 - clang-runtime: '18' - cling: On - cppyy: Off - cling-version: '1.2' - llvm_enable_projects: "clang" - llvm_targets_to_build: "host;NVPTX" - # Ubuntu X86 Jobs - - name: ubu24-x86-gcc12-clang-repl-20-coverage - os: ubuntu-24.04 - compiler: gcc-12 - clang-runtime: '20' - cling: Off - cppyy: Off - llvm_enable_projects: "clang;compiler-rt" - llvm_targets_to_build: "host;NVPTX" - coverage: true - oop-jit: On - Valgrind: On - - name: ubu24-x86-gcc12-clang-repl-20 - os: ubuntu-24.04 - compiler: gcc-12 - clang-runtime: '20' - cling: Off - cppyy: Off - llvm_enable_projects: "clang" - llvm_targets_to_build: "host;NVPTX" - - name: ubu24-x86-gcc12-clang-repl-20-out-of-process - os: ubuntu-24.04 - compiler: gcc-12 - clang-runtime: '20' - cling: Off - cppyy: Off - llvm_enable_projects: "clang;compiler-rt" - llvm_targets_to_build: "host;NVPTX" - oop-jit: On - - name: ubu24-x86-gcc12-clang-repl-19-cppyy - os: ubuntu-24.04 - compiler: gcc-12 - clang-runtime: '19' - cling: Off - cppyy: On - llvm_enable_projects: "clang" - llvm_targets_to_build: "host;NVPTX" - - name: ubu24-x86-gcc12-clang-repl-18-cppyy - os: ubuntu-24.04 - compiler: gcc-12 - clang-runtime: '18' - cling: Off - cppyy: On - llvm_enable_projects: "clang" - llvm_targets_to_build: "host;NVPTX" - - name: ubu24-x86-gcc9-clang18-cling-cppyy - os: ubuntu-24.04 - compiler: gcc-9 - clang-runtime: '18' - cling: On - cppyy: Off - cling-version: '1.2' - llvm_enable_projects: "clang" - llvm_targets_to_build: "host;NVPTX" - # MacOS Arm Jobs - - name: osx15-arm-clang-clang-repl-20-out-of-process - os: macos-15 - compiler: clang - clang-runtime: '20' - cling: Off - cppyy: Off - llvm_enable_projects: "clang;compiler-rt" - llvm_targets_to_build: "host" - oop-jit: On - - name: osx15-arm-clang-clang-repl-20 - os: macos-15 - compiler: clang - clang-runtime: '20' - cling: Off - cppyy: Off - llvm_enable_projects: "clang" - llvm_targets_to_build: "host" - - name: osx15-arm-clang-clang-repl-19-cppyy - os: macos-15 - compiler: clang - clang-runtime: '19' - cling: Off - cppyy: On - llvm_enable_projects: "clang" - llvm_targets_to_build: "host" - - name: osx15-arm-clang-clang-repl-18-cppyy - os: macos-15 - compiler: clang - clang-runtime: '18' - cling: Off - cppyy: On - llvm_enable_projects: "clang" - llvm_targets_to_build: "host" - - name: osx15-arm-clang-clang18-cling-cppyy - os: macos-15 - compiler: clang - clang-runtime: '18' - cling: On - cppyy: On - cling-version: '1.2' - llvm_enable_projects: "clang" - llvm_targets_to_build: "host;NVPTX" - # MacOS X86 Jobs - - name: osx15-x86-clang-clang-repl-20 - os: macos-15-intel - compiler: clang - clang-runtime: '20' - cling: Off - cppyy: Off - llvm_enable_projects: "clang" - llvm_targets_to_build: "host" - - name: osx15-x86-clang-clang-repl-19-cppyy - os: macos-15-intel - compiler: clang - clang-runtime: '19' - cling: Off - cppyy: On - llvm_enable_projects: "clang" - llvm_targets_to_build: "host" - - name: osx15-x86-clang-clang-repl-18-cppyy - os: macos-15-intel - compiler: clang - clang-runtime: '18' - cling: Off - cppyy: On - llvm_enable_projects: "clang" - llvm_targets_to_build: "host" - - name: osx15-x86-clang-clang18-cling-cppyy - os: macos-15-intel - compiler: clang - clang-runtime: '18' - cling: On - cppyy: On - cling-version: '1.2' - llvm_enable_projects: "clang" - llvm_targets_to_build: "host;NVPTX" # Windows Arm Jobs - - name: win11-msvc-clang-repl-20 - os: windows-11-arm - compiler: msvc - clang-runtime: '20' - cling: Off - llvm_enable_projects: "clang" - llvm_targets_to_build: "host;NVPTX" - - name: win11-msvc-clang18-cling + - name: win11-msvc-clang-repl-21 os: windows-11-arm compiler: msvc - clang-runtime: '18' - cling: On - cling-version: '1.2' + clang-runtime: '21' + cppyy: On llvm_enable_projects: "clang" llvm_targets_to_build: "host;NVPTX" # Windows X86 Jobs - - name: win2025-msvc-clang-repl-20 + - name: win2025-msvc-clang-repl-21 os: windows-2025 compiler: msvc - clang-runtime: '20' - cling: Off - llvm_enable_projects: "clang" - llvm_targets_to_build: "host;NVPTX" - - name: win2025-msvc-clang18-cling - os: windows-2025 - compiler: msvc - clang-runtime: '18' - cling: On - cling-version: '1.2' + clang-runtime: '21' + cppyy: On llvm_enable_projects: "clang" llvm_targets_to_build: "host;NVPTX" @@ -314,3 +132,4 @@ jobs: # When debugging increase to a suitable value! timeout-minutes: 30 + diff --git a/.github/workflows/markdown-linter.yml b/.github/workflows/markdown-linter.yml deleted file mode 100644 index 7569f9a3c..000000000 --- a/.github/workflows/markdown-linter.yml +++ /dev/null @@ -1,40 +0,0 @@ ---- -name: Markdown-Linter - -on: - pull_request: - branches: [main] - paths: - - '**.md' - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number }} - cancel-in-progress: true - -jobs: - build: - name: Linter - runs-on: ubuntu-22.04 - - permissions: - contents: read - packages: read - # To report GitHub Actions status checks - statuses: write - - steps: - - name: Checkout code - uses: actions/checkout@v5 - with: - # super-linter needs the full git history to get the - # list of files that changed across commits - fetch-depth: 0 - - - name: Super-linter - uses: super-linter/super-linter@v7.2.0 - env: - VALIDATE_ALL_CODEBASE: false - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - VALIDATE_MARKDOWN: true - DEFAULT_BRANCH: ${{ github.base_ref }} - MARKDOWN_LINT_CONFIG_FILE: .markdownlint.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 755abffeb..a28975329 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,14 +68,14 @@ include(GNUInstallDirs) ## Define supported version of clang and llvm set(CLANG_MIN_SUPPORTED 18.0) - set(CLANG_MAX_SUPPORTED "20.1.x") - set(CLANG_VERSION_UPPER_BOUND 21.0.0) + set(CLANG_MAX_SUPPORTED "21.1.x") + set(CLANG_VERSION_UPPER_BOUND 22.0.0) set(LLD_MIN_SUPPORTED 18.0) - set(LLD_MAX_SUPPORTED "20.1.x") - set(LLD_VERSION_UPPER_BOUND 21.0.0) + set(LLD_MAX_SUPPORTED "21.1.x") + set(LLD_VERSION_UPPER_BOUND 22.0.0) set(LLVM_MIN_SUPPORTED 18.0) - set(LLVM_MAX_SUPPORTED "20.1.x") - set(LLVM_VERSION_UPPER_BOUND 21.0.0) + set(LLVM_MAX_SUPPORTED "21.1.x") + set(LLVM_VERSION_UPPER_BOUND 22.0.0) ## Set Cmake packages search order diff --git a/Emscripten-build-instructions.md b/Emscripten-build-instructions.md index 7e9f516e1..740425483 100644 --- a/Emscripten-build-instructions.md +++ b/Emscripten-build-instructions.md @@ -42,11 +42,11 @@ $env:PWD_DIR= $PWD.Path $env:SYSROOT_PATH="$env:EMSDK/upstream/emscripten/cache/sysroot" ``` -Now clone the 20.x release of the LLVM project repository and CppInterOp (the building of the emscripten version of llvm can be +Now clone the 21.x release of the LLVM project repository and CppInterOp (the building of the emscripten version of llvm can be avoided by executing micromamba install llvm -c and setting the LLVM_BUILD_DIR/$env:LLVM_BUILD_DIR appropriately) ```bash -git clone --depth=1 --branch release/20.x https://github.com/llvm/llvm-project.git +git clone --depth=1 --branch release/21.x https://github.com/llvm/llvm-project.git git clone --depth=1 https://github.com/compiler-research/CppInterOp.git ``` @@ -55,16 +55,16 @@ executing ```bash cd ./llvm-project/ -git apply -v ../CppInterOp/patches/llvm/emscripten-clang20-*.patch +git apply -v ../CppInterOp/patches/llvm/emscripten-clang21-*.patch ``` On Windows execute the following ```powershell cd .\llvm-project\ -cp -r ..\patches\llvm\emscripten-clang20* -git apply -v emscripten-clang20-2-shift-temporary-files-to-tmp-dir.patch -git apply -v emscripten-clang20-3-enable_exception_handling.patch +cp -r ..\patches\llvm\emscripten-clang21* +git apply -v emscripten-clang21-1-shift-temporary-files-to-tmp-dir.patch +git apply -v emscripten-clang21-2-enable_exception_handling.patch ``` We are now in a position to build an emscripten build of llvm by executing the following on Linux @@ -343,7 +343,7 @@ of llvm you are building against) ```bash cd ../.. git clone --depth=1 https://github.com/compiler-research/xeus-cpp.git -export LLVM_VERSION=20 +export LLVM_VERSION=21 cd ./xeus-cpp mkdir build cd build diff --git a/README.md b/README.md index fd2f6a4bc..19133a965 100644 --- a/README.md +++ b/README.md @@ -104,10 +104,10 @@ git clone --depth=1 https://github.com/compiler-research/cppyy-backend.git #### Setup Clang-REPL -Clone the 20.x release of the LLVM project repository. +Clone the 21.x release of the LLVM project repository. ```bash -git clone --depth=1 --branch release/20.x https://github.com/llvm/llvm-project.git +git clone --depth=1 --branch release/21.x https://github.com/llvm/llvm-project.git cd llvm-project ``` @@ -456,10 +456,10 @@ git clone --depth=1 https://github.com/compiler-research/cppyy-backend.git #### Setup Clang-REPL -Clone the 20.x release of the LLVM project repository. +Clone the 21.x release of the LLVM project repository. ```bash -git clone --depth=1 --branch release/20.x https://github.com/llvm/llvm-project.git +git clone --depth=1 --branch release/21.x https://github.com/llvm/llvm-project.git cd llvm-project ``` diff --git a/docs/DevelopersDocumentation.rst b/docs/DevelopersDocumentation.rst index 347e07fda..77e89238a 100644 --- a/docs/DevelopersDocumentation.rst +++ b/docs/DevelopersDocumentation.rst @@ -34,11 +34,11 @@ library Setup Clang-REPL ****************** -Clone the 20.x release of the LLVM project repository. +Clone the 21.x release of the LLVM project repository. .. code:: bash - git clone --depth=1 --branch release/20.x https://github.com/llvm/llvm-project.git + git clone --depth=1 --branch release/21.x https://github.com/llvm/llvm-project.git cd llvm-project If you want to have out-of-process JIT execution enabled in CppInterOp, then apply this patch on Linux-x86_64 and MacOS arm64 environment. diff --git a/docs/Emscripten-build-instructions.rst b/docs/Emscripten-build-instructions.rst index c36f5e0bb..a46db3ef8 100644 --- a/docs/Emscripten-build-instructions.rst +++ b/docs/Emscripten-build-instructions.rst @@ -57,7 +57,7 @@ and on Windows execute in Powershell $env:PWD_DIR= $PWD.Path $env:SYSROOT_PATH="$env:EMSDK/upstream/emscripten/cache/sysroot" -Now clone the 20.x release of the LLVM project repository and CppInterOp +Now clone the 21.x release of the LLVM project repository and CppInterOp (the building of the emscripten version of llvm can be avoided by executing micromamba install llvm -c and setting the LLVM_BUILD_DIR/$env:LLVM_BUILD_DIR @@ -65,7 +65,7 @@ appropriately) .. code:: bash - git clone --depth=1 --branch release/20.x https://github.com/llvm/llvm-project.git + git clone --depth=1 --branch release/21.x https://github.com/llvm/llvm-project.git git clone --depth=1 https://github.com/compiler-research/CppInterOp.git Now move into the cloned llvm-project folder and apply the required patches. On Linux and osx this @@ -74,16 +74,16 @@ executing .. code:: bash cd ./llvm-project/ - git apply -v ../CppInterOp/patches/llvm/emscripten-clang20-*.patch + git apply -v ../CppInterOp/patches/llvm/emscripten-clang21-*.patch On Windows execute the following .. code:: powershell cd .\llvm-project\ - cp -r ..\patches\llvm\emscripten-clang20* - git apply -v emscripten-clang20-2-shift-temporary-files-to-tmp-dir.patch - git apply -v emscripten-clang20-3-enable_exception_handling.patch + cp -r ..\patches\llvm\emscripten-clang21* + git apply -v emscripten-clang21-1-shift-temporary-files-to-tmp-dir.patch + git apply -v emscripten-clang21-2-enable_exception_handling.patch We are now in a position to build an emscripten build of llvm by executing the following on Linux and osx @@ -365,7 +365,7 @@ by executing (replace LLVM_VERSION with the version of llvm you are building aga cd ../.. git clone --depth=1 https://github.com/compiler-research/xeus-cpp.git - export LLVM_VERSION=20 + export LLVM_VERSION=21 cd ./xeus-cpp mkdir build cd build diff --git a/docs/InstallationAndUsage.rst b/docs/InstallationAndUsage.rst index a5b1b1892..911281c25 100644 --- a/docs/InstallationAndUsage.rst +++ b/docs/InstallationAndUsage.rst @@ -34,11 +34,11 @@ library Setup Clang-REPL ****************** -Clone the 20.x release of the LLVM project repository. +Clone the 21.x release of the LLVM project repository. .. code:: bash - git clone --depth=1 --branch release/20.x https://github.com/llvm/llvm-project.git + git clone --depth=1 --branch release/21.x https://github.com/llvm/llvm-project.git cd llvm-project If you want to have out-of-process JIT execution enabled in CppInterOp, then apply this patch on Linux-x86_64 and MacOS arm64 environment. diff --git a/docs/ReleaseNotes.md b/docs/ReleaseNotes.md index 811519dea..a39ef6220 100644 --- a/docs/ReleaseNotes.md +++ b/docs/ReleaseNotes.md @@ -25,7 +25,7 @@ infrastructure are described first. ## External Dependencies - CppInterOp now works with: - - llvm20 + - llvm21 ## Introspection diff --git a/lib/CppInterOp/Compatibility.h b/lib/CppInterOp/Compatibility.h index 0c029910e..c5d9f7574 100644 --- a/lib/CppInterOp/Compatibility.h +++ b/lib/CppInterOp/Compatibility.h @@ -31,6 +31,23 @@ static inline char* GetEnv(const char* Var_Name) { #endif } +#if CLANG_VERSION_MAJOR < 21 +#define Print_Canonical_Types PrintCanonicalTypes +#else +#define Print_Canonical_Types PrintAsCanonical +#endif + +#if CLANG_VERSION_MAJOR < 21 +#define clang_LookupResult_Found clang::LookupResult::Found +#define clang_LookupResult_Not_Found clang::LookupResult::NotFound +#define clang_LookupResult_Found_Overloaded clang::LookupResult::FoundOverloaded +#else +#define clang_LookupResult_Found clang::LookupResultKind::Found +#define clang_LookupResult_Not_Found clang::LookupResultKind::NotFound +#define clang_LookupResult_Found_Overloaded \ + clang::LookupResultKind::FoundOverloaded +#endif + #if CLANG_VERSION_MAJOR < 19 #define Template_Deduction_Result Sema::TemplateDeductionResult #define Template_Deduction_Result_Success \ @@ -479,11 +496,14 @@ inline void InstantiateClassTemplateSpecialization( #if CLANG_VERSION_MAJOR < 20 interp.getSema().InstantiateClassTemplateSpecialization( clang::SourceLocation::getFromRawEncoding(1), CTSD, - clang::TemplateSpecializationKind::TSK_Undeclared, /*Complain=*/true); + + clang::TemplateSpecializationKind::TSK_ExplicitInstantiationDefinition, + /*Complain=*/true); #else interp.getSema().InstantiateClassTemplateSpecialization( clang::SourceLocation::getFromRawEncoding(1), CTSD, - clang::TemplateSpecializationKind::TSK_Undeclared, /*Complain=*/true, + clang::TemplateSpecializationKind::TSK_ExplicitInstantiationDefinition, + /*Complain=*/true, /*PrimaryHasMatchedPackOnParmToNonPackOnArg=*/false); #endif } diff --git a/lib/CppInterOp/CppInterOp.cpp b/lib/CppInterOp/CppInterOp.cpp index 46f2fe226..9b96a7abc 100755 --- a/lib/CppInterOp/CppInterOp.cpp +++ b/lib/CppInterOp/CppInterOp.cpp @@ -1182,16 +1182,16 @@ bool GetClassTemplatedMethods(const std::string& name, TCppScope_t parent, auto* DC = clang::Decl::castToDeclContext(D); Cpp_utils::Lookup::Named(&S, R, DC); - if (R.getResultKind() == clang::LookupResult::NotFound && funcs.empty()) + if (R.getResultKind() == clang_LookupResult_Not_Found && funcs.empty()) return false; // Distinct match, single Decl - else if (R.getResultKind() == clang::LookupResult::Found) { + else if (R.getResultKind() == clang_LookupResult_Found) { if (IsTemplatedFunction(R.getFoundDecl())) funcs.push_back(R.getFoundDecl()); } // Loop over overload set - else if (R.getResultKind() == clang::LookupResult::FoundOverloaded) { + else if (R.getResultKind() == clang_LookupResult_Found_Overloaded) { for (auto* Found : R) if (IsTemplatedFunction(Found)) funcs.push_back(Found); @@ -1960,7 +1960,7 @@ static void GetDeclName(const clang::Decl* D, ASTContext& Context, PrintingPolicy Policy(Context.getPrintingPolicy()); Policy.SuppressTagKeyword = true; Policy.SuppressUnwrittenScope = true; - Policy.PrintCanonicalTypes = true; + Policy.Print_Canonical_Types = true; if (const TypeDecl* TD = dyn_cast(D)) { // This is a class, struct, or union member. QualType QT; diff --git a/lib/CppInterOp/exports.ld b/lib/CppInterOp/exports.ld index e22490f2a..9d99a30c8 100644 --- a/lib/CppInterOp/exports.ld +++ b/lib/CppInterOp/exports.ld @@ -51,4 +51,6 @@ -Wl,--export=_ZNK5clang12FunctionDecl12getNumParamsEv -Wl,--export=__clang_Interpreter_SetValueNoAlloc -Wl,--export=__clang_Interpreter_SetValueWithAlloc +-Wl,--export=_ZN5clang11Interpreter6createENSt3__210unique_ptrINS_16CompilerInstanceENS1_14default_deleteIS3_EEEENS2_IN4llvm3orc12LLJITBuilderENS4_IS9_EEEE +-Wl,--export=_ZNK5clang13CXXRecordDecl19isInjectedClassNameEv -Wl,--export=_ZN4llvm15SmallVectorBaseIjE8set_sizeEm \ No newline at end of file diff --git a/patches/llvm/emscripten-clang21-1-shift-temporary-files-to-tmp-dir.patch b/patches/llvm/emscripten-clang21-1-shift-temporary-files-to-tmp-dir.patch new file mode 100644 index 000000000..32ac45c13 --- /dev/null +++ b/patches/llvm/emscripten-clang21-1-shift-temporary-files-to-tmp-dir.patch @@ -0,0 +1,15 @@ +diff --git a/clang/lib/Interpreter/Wasm.cpp b/clang/lib/Interpreter/Wasm.cpp +index aa10b160ccf8..184867e2b55f 100644 +--- a/clang/lib/Interpreter/Wasm.cpp ++++ b/clang/lib/Interpreter/Wasm.cpp +@@ -76,8 +76,8 @@ llvm::Error WasmIncrementalExecutor::addModule(PartialTranslationUnit &PTU) { + llvm::TargetMachine *TargetMachine = Target->createTargetMachine( + PTU.TheModule->getTargetTriple(), "", "", TO, llvm::Reloc::Model::PIC_); + PTU.TheModule->setDataLayout(TargetMachine->createDataLayout()); +- std::string ObjectFileName = PTU.TheModule->getName().str() + ".o"; +- std::string BinaryFileName = PTU.TheModule->getName().str() + ".wasm"; ++ std::string ObjectFileName = "/tmp/" + PTU.TheModule->getName().str() + ".o"; ++ std::string BinaryFileName = "/tmp/" + PTU.TheModule->getName().str() + ".wasm"; + + std::error_code Error; + llvm::raw_fd_ostream ObjectFileOutput(llvm::StringRef(ObjectFileName), Error); diff --git a/patches/llvm/emscripten-clang21-2-enable_exception_handling.patch b/patches/llvm/emscripten-clang21-2-enable_exception_handling.patch new file mode 100644 index 000000000..269fa5d24 --- /dev/null +++ b/patches/llvm/emscripten-clang21-2-enable_exception_handling.patch @@ -0,0 +1,67 @@ +diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp +index ed3bae59a..f1fedd532 100644 +--- a/clang/lib/Interpreter/Interpreter.cpp ++++ b/clang/lib/Interpreter/Interpreter.cpp +@@ -144,6 +144,48 @@ CreateCI(const llvm::opt::ArgStringList &Argv) { + return std::move(Clang); + } + ++static llvm::Error HandleFrontendOptions(const CompilerInstance &CI) { ++ const auto &FrontendOpts = CI.getFrontendOpts(); ++ ++ if (FrontendOpts.ShowHelp) { ++ driver::getDriverOptTable().printHelp( ++ llvm::outs(), "clang -cc1 [options] file...", ++ "LLVM 'Clang' Compiler: http://clang.llvm.org", ++ /*ShowHidden=*/false, /*ShowAllAliases=*/false, ++ llvm::opt::Visibility(driver::options::CC1Option)); ++ return llvm::createStringError(llvm::errc::not_supported, "Help displayed"); ++ } ++ ++ if (FrontendOpts.ShowVersion) { ++ llvm::cl::PrintVersionMessage(); ++ return llvm::createStringError(llvm::errc::not_supported, ++ "Version displayed"); ++ } ++ ++ if (!FrontendOpts.LLVMArgs.empty()) { ++ unsigned NumArgs = FrontendOpts.LLVMArgs.size(); ++ auto Args = std::make_unique(NumArgs + 2); ++ Args[0] = "clang-repl (LLVM option parsing)"; ++ for (unsigned i = 0; i != NumArgs; ++i) { ++ Args[i + 1] = FrontendOpts.LLVMArgs[i].c_str(); ++ // remove the leading '-' from the option name ++ if (Args[i + 1][0] == '-') { ++ auto *option = static_cast *>( ++ llvm::cl::getRegisteredOptions()[Args[i + 1] + 1]); ++ if (option) { ++ option->setInitialValue(true); ++ } else { ++ llvm::errs() << "Unknown LLVM option: " << Args[i + 1] << "\n"; ++ } ++ } ++ } ++ Args[NumArgs + 1] = nullptr; ++ llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get()); ++ } ++ ++ return llvm::Error::success(); ++} ++ + } // anonymous namespace + + namespace clang { +@@ -462,7 +504,12 @@ const char *const Runtimes = R"( + llvm::Expected> + Interpreter::create(std::unique_ptr CI, + std::unique_ptr JB) { +- llvm::Error Err = llvm::Error::success(); ++ ++ llvm::Error Err = HandleFrontendOptions(*CI); ++ if (Err) { ++ return std::move(Err); ++ } ++ + auto Interp = std::unique_ptr( + new Interpreter(std::move(CI), Err, JB ? std::move(JB) : nullptr)); + if (Err)