Skip to content
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
af6b0fc
Make CppInterOp llvm 21 compatible
mcbarton Jul 15, 2025
3d74a26
Update Windows-emscripten-clang21-1-CrossCompile.patch
mcbarton Jul 15, 2025
aef6370
Update exports.ld
mcbarton Jul 16, 2025
2a280d1
Update exports.ld
mcbarton Jul 16, 2025
8c81b18
Merge branch 'main' into Add-llvm-21-support
mcbarton Aug 31, 2025
bbd2a48
Define Print_Canonical_Types for llvm 21 compatibility
mcbarton Sep 9, 2025
f8c7163
Merge branch 'main' into Add-llvm-21-support
mcbarton Sep 9, 2025
68a3695
Make CppInterOp llvm 21 compatible
mcbarton Jul 15, 2025
a6919e7
Update Windows-emscripten-clang21-1-CrossCompile.patch
mcbarton Jul 15, 2025
a4801b4
Update exports.ld
mcbarton Jul 16, 2025
113b7a6
Update exports.ld
mcbarton Jul 16, 2025
ed5b80c
Define Print_Canonical_Types for llvm 21 compatibility
mcbarton Sep 9, 2025
19e1951
fix instantiation of templated class
Vipul-Cariappa Sep 15, 2025
eaf352c
fix instantiation of templated class
Vipul-Cariappa Sep 15, 2025
71f02da
Merge branch 'Add-llvm-21-support' into mcbarton/Add-llvm-21-support
Vipul-Cariappa Sep 15, 2025
a884dee
Merge pull request #1 from Vipul-Cariappa/mcbarton/Add-llvm-21-support
mcbarton Sep 15, 2025
c6fb53f
Merge branch 'main' into Add-llvm-21-support
mcbarton Sep 15, 2025
bbbf6d0
Apply some PR comments
mcbarton Sep 15, 2025
c97eb37
Updat 1.x to 21.x readme.md
mcbarton Sep 15, 2025
541711e
Update rest of docs for llvm 21
mcbarton Sep 15, 2025
7e1bd6e
Merge branch 'main' into Add-llvm-21-support
mcbarton Sep 24, 2025
77ee1d0
Merge branch 'main' into Add-llvm-21-support
mcbarton Oct 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 58 additions & 1 deletion .github/workflows/emscripten.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,34 @@ jobs:
llvm_enable_projects: "clang;lld"
llvm_targets_to_build: "WebAssembly"
emsdk_ver: "3.1.73"
- name: ubu24-arm-clang-repl-21-emscripten
os: ubuntu-24.04-arm
clang-runtime: '21'
cling: Off
llvm_enable_projects: "clang;lld"
llvm_targets_to_build: "WebAssembly"
emsdk_ver: "3.1.73"
- name: osx15-arm-clang-repl-21-emscripten
os: macos-15
clang-runtime: '21'
cling: Off
llvm_enable_projects: "clang;lld"
llvm_targets_to_build: "WebAssembly"
emsdk_ver: "3.1.73"
- name: ubu24-x86-clang-repl-21-emscripten
os: ubuntu-24.04
clang-runtime: '21'
cling: Off
llvm_enable_projects: "clang;lld"
llvm_targets_to_build: "WebAssembly"
emsdk_ver: "3.1.73"
- name: win2025-x86-clang-repl-21-emscripten
os: windows-2025
clang-runtime: '21'
cling: Off
llvm_enable_projects: "clang;lld"
llvm_targets_to_build: "WebAssembly"
emsdk_ver: "3.1.73"

steps:
- uses: actions/checkout@v5
Expand Down Expand Up @@ -201,7 +229,7 @@ jobs:
else
# Apply patches
llvm_vers=$(echo "${{ matrix.clang-runtime }}" | tr '[:lower:]' '[:upper:]')
if [[ "${llvm_vers}" == "19" || "${llvm_vers}" == "20" ]]; then
if [[ "${llvm_vers}" == "19" || "${llvm_vers}" == "20" || "${llvm_vers}" == "21" ]]; then
git apply -v ../patches/llvm/emscripten-clang${{ matrix.clang-runtime }}-*.patch
echo "Apply emscripten-clang${{ matrix.clang-runtime }}-*.patch patches:"
fi
Expand Down Expand Up @@ -327,6 +355,11 @@ jobs:
git apply -v emscripten-clang20-2-shift-temporary-files-to-tmp-dir.patch
git apply -v emscripten-clang20-3-enable_exception_handling.patch
}
elseif ( "${{ matrix.clang-runtime }}" -imatch "21" )
{
git apply -v Windows-emscripten-clang21-1-CrossCompile.patch
git apply -v emscripten-clang21-2-shift-temporary-files-to-tmp-dir.patch
}
cd build
echo "Apply clang${{ matrix.clang-runtime }}-*.patch patches:"
emcmake cmake -DCMAKE_BUILD_TYPE=Release `
Expand Down Expand Up @@ -439,6 +472,30 @@ jobs:
cling: Off
micromamba_shell_init: powershell
emsdk_ver: "3.1.73"
- name: ubu24-x86-clang-repl-21-emscripten_wasm
os: ubuntu-24.04
clang-runtime: '21'
cling: Off
micromamba_shell_init: bash
emsdk_ver: "3.1.73"
- name: osx15-arm-clang-repl-21-emscripten_wasm
os: macos-15
clang-runtime: '21'
cling: Off
micromamba_shell_init: bash
emsdk_ver: "3.1.73"
- name: ubu24-arm-clang-repl-21-emscripten_wasm
os: ubuntu-24.04-arm
clang-runtime: '21'
cling: Off
micromamba_shell_init: bash
emsdk_ver: "3.1.73"
- name: win2025-x86-clang-repl-21-emscripten
os: windows-2025
clang-runtime: '21'
cling: Off
micromamba_shell_init: powershell
emsdk_ver: "3.1.73"

steps:
- uses: actions/checkout@v5
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ jobs:
matrix:
include:
# Ubuntu Arm Jobs
- name: ubu24-arm-gcc12-clang-repl-21
os: ubuntu-24.04-arm
compiler: gcc-12
clang-runtime: '21'
cling: Off
cppyy: Off
llvm_enable_projects: "clang"
llvm_targets_to_build: "host;NVPTX"
- name: ubu22-arm-gcc12-clang-repl-20-coverage
os: ubuntu-22.04-arm
compiler: gcc-12
Expand Down Expand Up @@ -66,6 +74,14 @@ jobs:
llvm_enable_projects: "clang"
llvm_targets_to_build: "host;NVPTX"
# Ubuntu X86 Jobs
- name: ubu24-x86-gcc12-clang-repl-21
os: ubuntu-24.04
compiler: gcc-12
clang-runtime: '21'
cling: Off
cppyy: Off
llvm_enable_projects: "clang"
llvm_targets_to_build: "host;NVPTX"
- name: ubu24-x86-gcc12-clang-repl-20
os: ubuntu-24.04
compiler: gcc-12
Expand Down Expand Up @@ -100,6 +116,14 @@ jobs:
llvm_enable_projects: "clang"
llvm_targets_to_build: "host;NVPTX"
# MacOS Arm Jobs
- name: osx15-arm-clang-clang-repl-21
os: macos-15
compiler: clang
clang-runtime: '21'
cling: Off
cppyy: Off
llvm_enable_projects: "clang"
llvm_targets_to_build: "host"
- name: osx15-arm-clang-clang-repl-20
os: macos-15
compiler: clang
Expand Down Expand Up @@ -134,6 +158,14 @@ jobs:
llvm_enable_projects: "clang"
llvm_targets_to_build: "host;NVPTX"
# MacOS X86 Jobs
- name: osx13-x86-clang-clang-repl-21
os: macos-13
compiler: clang
clang-runtime: '21'
cling: Off
cppyy: Off
llvm_enable_projects: "clang"
llvm_targets_to_build: "host"
- name: osx13-x86-clang-clang-repl-20
os: macos-13
compiler: clang
Expand Down Expand Up @@ -168,6 +200,13 @@ jobs:
llvm_enable_projects: "clang"
llvm_targets_to_build: "host;NVPTX"
# Windows Arm Jobs
- name: win11-msvc-clang-repl-21
os: windows-11-arm
compiler: msvc
clang-runtime: '21'
cling: Off
llvm_enable_projects: "clang"
llvm_targets_to_build: "host;NVPTX"
- name: win11-msvc-clang-repl-20
os: windows-11-arm
compiler: msvc
Expand All @@ -184,6 +223,13 @@ jobs:
llvm_enable_projects: "clang"
llvm_targets_to_build: "host;NVPTX"
# Windows X86 Jobs
- name: win2025-msvc-clang-repl-21
os: windows-2025
compiler: msvc
clang-runtime: '21'
cling: Off
llvm_enable_projects: "clang"
llvm_targets_to_build: "host;NVPTX"
- name: win2025-msvc-clang-repl-20
os: windows-2025
compiler: msvc
Expand Down
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 22 additions & 2 deletions lib/CppInterOp/Compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -412,11 +429,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
}
Expand Down
8 changes: 4 additions & 4 deletions lib/CppInterOp/CppInterOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
if (item.first->getAllocator().identifyObject(D))
return *item.second;
}
llvm_unreachable(

Check warning on line 176 in lib/CppInterOp/CppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/CppInterOp/CppInterOp.cpp#L176

Added line #L176 was not covered by tests
"This pointer does not belong to any interpreter instance.\n");
}
static InterpreterInfo& getInterpInfo(compat::Interpreter* I) {
Expand All @@ -185,7 +185,7 @@
[&](const auto& item) { return item->Interpreter == I; });
if (res != sInterpreters->end())
return **res;
llvm_unreachable("Invalid State");

Check warning on line 188 in lib/CppInterOp/CppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/CppInterOp/CppInterOp.cpp#L188

Added line #L188 was not covered by tests
}

static compat::Interpreter& getInterp(const clang::Decl* D) {
Expand Down Expand Up @@ -885,7 +885,7 @@

LOCK(getInterpInfo(CXXRD));
if (CXXRD->getNumBases() <= ibase)
return nullptr;

Check warning on line 888 in lib/CppInterOp/CppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/CppInterOp/CppInterOp.cpp#L888

Added line #L888 was not covered by tests

auto type = (CXXRD->bases_begin() + ibase)->getType();
if (auto RT = type->getAs<RecordType>())
Expand Down Expand Up @@ -1307,16 +1307,16 @@
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);
Expand Down Expand Up @@ -2108,7 +2108,7 @@
PrintingPolicy Policy(Context.getPrintingPolicy());
Policy.SuppressTagKeyword = true;
Policy.SuppressUnwrittenScope = true;
Policy.PrintCanonicalTypes = true;
Policy.Print_Canonical_Types = true;
if (const TypeDecl* TD = dyn_cast<TypeDecl>(D)) {
// This is a class, struct, or union member.
QualType QT;
Expand Down Expand Up @@ -3707,11 +3707,11 @@
return compat::convertTo<intptr_t>(V);
}

std::string LookupLibrary(const char* lib_name, TInterp_t I /*=nullptr*/) {
auto* interp = static_cast<compat::Interpreter*>(I);
if (interp)
return interp->getDynamicLibraryManager()->lookupLibrary(lib_name);
return getInterp(NULLPTR).getDynamicLibraryManager()->lookupLibrary(lib_name);

Check warning on line 3714 in lib/CppInterOp/CppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/CppInterOp/CppInterOp.cpp#L3710-L3714

Added lines #L3710 - L3714 were not covered by tests
}

bool LoadLibrary(const char* lib_stem, bool lookup, TInterp_t I /*=nullptr*/) {
Expand Down Expand Up @@ -3836,9 +3836,9 @@
}

std::string ObjToString(const char* type, void* obj) {
LOCK(getInterpInfo(NULLPTR)); // FIXME: not enough information to lock the

Check warning on line 3839 in lib/CppInterOp/CppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/CppInterOp/CppInterOp.cpp#L3839

Added line #L3839 was not covered by tests
// current interpreter
return getInterp(NULLPTR).toString(type, obj);

Check warning on line 3841 in lib/CppInterOp/CppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/CppInterOp/CppInterOp.cpp#L3841

Added line #L3841 was not covered by tests
}

static Decl* InstantiateTemplate(TemplateDecl* TemplateD,
Expand Down
2 changes: 2 additions & 0 deletions lib/CppInterOp/exports.ld
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 20 additions & 0 deletions patches/llvm/Windows-emscripten-clang21-1-CrossCompile.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
diff --git a/llvm/cmake/modules/CrossCompile.cmake b/llvm/cmake/modules/CrossCompile.cmake
Copy link
Collaborator Author

@mcbarton mcbarton Sep 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch needs removing now since we no longer need it. The other llvm patch is one we have used for Emscripten builds for both llvm 19 and 20 (it isn't needed for functionality, but helps the xeus-cpp deployment have a clear folder when executing cells). I think we also need to add the exception handling patch to this PR too, so that the deployment will work correctly.

index 39b4abaa0..474ceddbb 100644
--- a/llvm/cmake/modules/CrossCompile.cmake
+++ b/llvm/cmake/modules/CrossCompile.cmake
@@ -74,10 +74,12 @@ function(llvm_create_cross_target project_name target_name toolchain buildtype)
endif()

add_custom_command(OUTPUT ${${project_name}_${target_name}_BUILD}/CMakeCache.txt
- COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}"
+ COMMAND ${CMAKE_COMMAND} -G Ninja
"-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}"
- "-DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}"
- "-DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}"
+ -DCMAKE_C_COMPILER="clang-cl"
+ -DCMAKE_CXX_COMPILER="clang-cl"
+ -DCMAKE_ASM_MASM_COMPILER=llvm-ml
+ -DCMAKE_ASM_MASM_FLAGS="-m64"
${CROSS_TOOLCHAIN_FLAGS_${target_name}} ${CMAKE_CURRENT_SOURCE_DIR}
${CROSS_TOOLCHAIN_FLAGS_${project_name}_${target_name}}
-DLLVM_TARGET_IS_CROSSCOMPILE_HOST=TRUE
Original file line number Diff line number Diff line change
@@ -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);
Loading