diff --git a/.github/workflows/ci-slang-build.yml b/.github/workflows/ci-slang-build.yml index efb4fe4a4b2..22477833b38 100644 --- a/.github/workflows/ci-slang-build.yml +++ b/.github/workflows/ci-slang-build.yml @@ -34,7 +34,7 @@ on: jobs: build: runs-on: ${{ fromJSON(inputs.runs-on) }} - timeout-minutes: 60 + timeout-minutes: 120 defaults: run: diff --git a/cmake/LLVM.cmake b/cmake/LLVM.cmake index b9ce73a6e12..9a9754684a8 100644 --- a/cmake/LLVM.cmake +++ b/cmake/LLVM.cmake @@ -1,42 +1,20 @@ -# A convenience on top of the llvm package's cmake files, this creates a target -# to pass to target_link_libraries which correctly pulls in the llvm include -# dir and other compile dependencies -function(llvm_target_from_components target_name) - set(components ${ARGN}) - llvm_map_components_to_libnames(llvm_libs - ${components} - ) - add_library(${target_name} INTERFACE) - target_link_libraries(${target_name} INTERFACE ${llvm_libs}) - target_include_directories( - ${target_name} - SYSTEM - INTERFACE ${LLVM_INCLUDE_DIRS} - ) - target_compile_definitions(${target_name} INTERFACE ${LLVM_DEFINITIONS}) - if(NOT LLVM_ENABLE_RTTI) - # Make sure that we don't disable rtti if this library wasn't compiled with - # support - add_supported_cxx_flags(${target_name} INTERFACE -fno-rtti /GR-) - endif() -endfunction() - # The same for clang function(clang_target_from_libs target_name) set(clang_libs ${ARGN}) add_library(${target_name} INTERFACE) - target_link_libraries(${target_name} INTERFACE ${clang_libs}) + # Check if we have the individual modules or not. + if(TARGET clangBasic) + target_link_libraries(${target_name} INTERFACE ${clang_libs}) + else() + # If not, we can still link to the catch-all clang-cpp. + target_link_libraries(${target_name} INTERFACE clang-cpp) + endif() target_include_directories( ${target_name} SYSTEM INTERFACE ${CLANG_INCLUDE_DIRS} ) target_compile_definitions(${target_name} INTERFACE ${CLANG_DEFINITIONS}) - if(NOT LLVM_ENABLE_RTTI) - # Make sure that we don't disable rtti if this library wasn't compiled with - # support - add_supported_cxx_flags(${target_name} INTERFACE -fno-rtti /GR-) - endif() endfunction() function(fetch_or_build_slang_llvm) @@ -60,10 +38,13 @@ function(fetch_or_build_slang_llvm) endif() endif() elseif(SLANG_SLANG_LLVM_FLAVOR STREQUAL "USE_SYSTEM_LLVM") - find_package(LLVM 14.0 REQUIRED CONFIG) + find_package(LLVM 21.1 REQUIRED CONFIG) find_package(Clang REQUIRED CONFIG) - llvm_target_from_components(llvm-dep filecheck native orcjit) + if(LLVM_LINK_LLVM_DYLIB) + set(LLVM_LINK_TYPE USE_SHARED) + endif() + clang_target_from_libs( clang-dep clangBasic @@ -76,7 +57,7 @@ function(fetch_or_build_slang_llvm) slang_add_target( source/slang-llvm MODULE - LINK_WITH_PRIVATE core compiler-core llvm-dep clang-dep + LINK_WITH_PRIVATE core compiler-core clang-dep # We include slang.h, but don't need to link with it INCLUDE_FROM_PRIVATE slang # We include tools/slang-test/filecheck.h, but don't need to link @@ -90,6 +71,9 @@ function(fetch_or_build_slang_llvm) INSTALL_COMPONENT slang-llvm EXPORT_SET_NAME SlangTargets ) + + llvm_config(slang-llvm ${LLVM_LINK_TYPE} filecheck native orcjit) + # If we don't include this, then the symbols in the LLVM linked here may # conflict with those of other LLVMs linked at runtime, for instance in mesa. set_target_properties( @@ -104,11 +88,17 @@ function(fetch_or_build_slang_llvm) # The LLVM headers need a warning disabling, which somehow slips through \external if(MSVC) - target_compile_options(slang-llvm PRIVATE -wd4244) + target_compile_options(slang-llvm PRIVATE -wd4244 /Zc:preprocessor) + endif() + + if(NOT LLVM_ENABLE_RTTI) + # Make sure that we don't disable rtti if this library wasn't compiled with + # support + add_supported_cxx_flags(slang-llvm PRIVATE -fno-rtti /GR-) endif() # TODO: Put a check here that libslang-llvm.so doesn't have a 'NEEDED' - # directive for libLLVM-14.so, it's almost certainly going to break at + # directive for libLLVM-21.so, it's almost certainly going to break at # runtime in surprising ways when linked alongside Mesa (or anything else # pulling in libLLVM.so) endif() diff --git a/docs/building.md b/docs/building.md index bcf366d5189..dbedaa737c7 100644 --- a/docs/building.md +++ b/docs/building.md @@ -213,13 +213,13 @@ There are several options for getting llvm-support: containing such a file - If this isn't set then the build system tries to download it from the release on github matching the current tag. If such a tag doesn't exist - or doesn't have the correct os*arch combination then the latest release + or doesn't have the correct os\*arch combination then the latest release will be tried. - If `SLANG_SLANG_LLVM_BINARY_URL` is `FETCH_BINARY_IF_POSSIBLE` then in the case that a prebuilt binary can't be found then the build will proceed as though `DISABLE` was chosen - Use a system supplied LLVM: `-DSLANG_SLANG_LLVM_FLAVOR=USE_SYSTEM_LLVM`, you - must have llvm-14.0 and a matching libclang installed. It's important that + must have llvm-21.1 and a matching libclang installed. It's important that either: - You don't end up linking to a dynamic libllvm.so, this will almost certainly cause multiple versions of LLVM to be loaded at runtime, diff --git a/external/build-llvm.ps1 b/external/build-llvm.ps1 index f403e6ae21f..8ede7cafedf 100644 --- a/external/build-llvm.ps1 +++ b/external/build-llvm.ps1 @@ -55,7 +55,7 @@ $null = Register-EngineEvent PowerShell.Exiting -Action $cleanup # Default values $repo = "https://github.com/llvm/llvm-project" -$branch = "llvmorg-14.0.6" +$branch = "llvmorg-21.1.2" $sourceDir = $tempDir.FullName $installPrefix = "" $config = "Release" @@ -123,6 +123,7 @@ $cmakeArgumentsForSlang = @( "-DLLVM_INCLUDE_EXAMPLES=0" "-DLLVM_INCLUDE_TESTS=0" "-DLLVM_ENABLE_TERMINFO=0" + "-DLLVM_ENABLE_DIA_SDK=0" "-DCLANG_BUILD_TOOLS=0" "-DCLANG_ENABLE_STATIC_ANALYZER=0" "-DCLANG_ENABLE_ARCMT=0" diff --git a/external/build-llvm.sh b/external/build-llvm.sh index b556bae7953..91bc56560a7 100755 --- a/external/build-llvm.sh +++ b/external/build-llvm.sh @@ -54,7 +54,7 @@ trap cleanup EXIT SIGHUP SIGINT SIGTERM # Options and parsing # repo=https://github.com/llvm/llvm-project -branch=llvmorg-14.0.6 +branch=llvmorg-21.1.2 source_dir=$temp_dir install_prefix= config=Release @@ -122,6 +122,9 @@ cmake_arguments_for_slang=( -DLLVM_INCLUDE_EXAMPLES=0 -DLLVM_INCLUDE_TESTS=0 -DLLVM_ENABLE_TERMINFO=0 + -DLLVM_FORCE_VC_REVISION=0 + -DLLVM_FORCE_VC_REPOSITORY="https://github.com/llvm/llvm-project" + -DLLVM_ENABLE_DIA_SDK=0 -DCLANG_BUILD_TOOLS=0 -DCLANG_ENABLE_STATIC_ANALYZER=0 -DCLANG_ENABLE_ARCMT=0 diff --git a/source/slang-llvm/slang-llvm-filecheck.cpp b/source/slang-llvm/slang-llvm-filecheck.cpp index 492b0e0d419..c1a19ce9d41 100644 --- a/source/slang-llvm/slang-llvm-filecheck.cpp +++ b/source/slang-llvm/slang-llvm-filecheck.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -126,8 +127,7 @@ TestResult LLVMFileCheck::performTest( TestMessageType::RunError}; sourceManager.setDiagHandler(fileCheckDiagHandler, static_cast(&reporterData)); - auto checkPrefix = fc.buildCheckPrefixRegex(); - if (fc.readCheckFile(sourceManager, rulesStringRef, checkPrefix)) + if (fc.readCheckFile(sourceManager, rulesStringRef)) { // FileCheck failed to find or understand any FileCheck rules in // the input file, automatic fail, and reported to the diag handler . diff --git a/source/slang-llvm/slang-llvm.cpp b/source/slang-llvm/slang-llvm.cpp index 81d7a9cf600..56e12ec7ac9 100644 --- a/source/slang-llvm/slang-llvm.cpp +++ b/source/slang-llvm/slang-llvm.cpp @@ -2,7 +2,7 @@ #include "clang/Basic/TargetOptions.h" #include "clang/Basic/Version.h" #include "clang/CodeGen/CodeGenAction.h" -#include "clang/CodeGen/ObjectFilePCHContainerOperations.h" +#include "clang/CodeGen/ObjectFilePCHContainerWriter.h" #include "clang/Config/config.h" #include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/Options.h" @@ -15,6 +15,7 @@ #include "clang/Frontend/Utils.h" #include "clang/FrontendTool/Utils.h" #include "clang/Lex/PreprocessorOptions.h" +#include "clang/Serialization/ObjectFilePCHContainerReader.h" #include "llvm/ADT/Statistic.h" #include "llvm/Config/llvm-config.h" #include "llvm/LinkAllPasses.h" @@ -226,13 +227,8 @@ void* LLVMJITSharedLibrary::castAs(const Guid& guid) void* LLVMJITSharedLibrary::findSymbolAddressByName(char const* name) { - auto fnExpected = m_jit->lookup(name); - if (fnExpected) - { - auto fn = std::move(*fnExpected); - return (void*)fn.getAddress(); - } - return nullptr; + auto fn = m_jit->lookup(name); + return fn ? (void*)fn.get().getValue() : nullptr; } @@ -653,7 +649,7 @@ SlangResult LLVMDownstreamCompiler::compile( pchOps->registerWriter(std::make_unique()); pchOps->registerReader(std::make_unique()); - IntrusiveRefCntPtr diagOpts = new DiagnosticOptions(); + DiagnosticOptions diagOpts; ComPtr diagnostics(new ArtifactDiagnostics); @@ -721,8 +717,6 @@ SlangResult LLVMDownstreamCompiler::compile( } } - const InputKind inputKind(language, InputKind::Format::Source); - { auto& opts = invocation.getFrontendOpts(); @@ -732,7 +726,7 @@ SlangResult LLVMDownstreamCompiler::compile( // input is a memory buffer. For Slang usage, this probably isn't an issue, because it's // *output* typically holds #line directives. { - + const InputKind inputKind(language, InputKind::Format::Source); FrontendInputFile inputFile(*sourceBuffer, inputKind); opts.Inputs.push_back(inputFile); } @@ -776,7 +770,7 @@ SlangResult LLVMDownstreamCompiler::compile( } { - auto opts = invocation.getLangOpts(); + auto& opts = invocation.getLangOpts(); std::vector includes; for (const auto& includePath : options.includePaths) @@ -784,16 +778,11 @@ SlangResult LLVMDownstreamCompiler::compile( includes.push_back(includePath.begin()); } - clang::CompilerInvocation::setLangDefaults( - *opts, - inputKind, - targetTriple, - includes, - langStd); + clang::LangOptions::setLangDefaults(opts, language, targetTriple, includes, langStd); if (options.floatingPointMode == DownstreamCompileOptions::FloatingPointMode::Fast) { - opts->FastMath = true; + opts.FastMath = true; } } @@ -853,7 +842,7 @@ SlangResult LLVMDownstreamCompiler::compile( #endif // Create the actual diagnostics engine. - clang->createDiagnostics(); + clang->createDiagnostics(*llvm::vfs::getRealFileSystem()); clang->setDiagnostics(diags.get()); if (!clang->hasDiagnostics()) @@ -1037,36 +1026,33 @@ SlangResult LLVMDownstreamCompiler::compile( // Add all the symbolmap SymbolMap symbolMap; - // symbolMap.insert(std::make_pair(mangler("sin"), - // JITEvaluatedSymbol::fromPointer(static_cast(&sin)))); - { static const NameAndFunc funcs[] = {SLANG_LLVM_FUNCS( SLANG_LLVM_FUNC) SLANG_PLATFORM_FUNCS(SLANG_LLVM_FUNC)}; for (auto& func : funcs) { - symbolMap.insert(std::make_pair( - mangler(func.name), - JITEvaluatedSymbol::fromPointer(func.func))); + symbolMap[mangler(func.name)] = { + ExecutorAddr::fromPtr(func.func), + JITSymbolFlags::Callable}; } } #if SLANG_PTR_IS_32 && SLANG_VC { // https://docs.microsoft.com/en-us/windows/win32/devnotes/-win32-alldiv - symbolMap.insert(std::make_pair( - mangler("_alldiv"), - JITEvaluatedSymbol::fromPointer(WinSpecific::_alldiv))); - symbolMap.insert(std::make_pair( - mangler("_allrem"), - JITEvaluatedSymbol::fromPointer(WinSpecific::_allrem))); - symbolMap.insert(std::make_pair( - mangler("_aullrem"), - JITEvaluatedSymbol::fromPointer(WinSpecific::_aullrem))); - symbolMap.insert(std::make_pair( - mangler("_aulldiv"), - JITEvaluatedSymbol::fromPointer(WinSpecific::_aulldiv))); + symbolMap[mangler("_alldiv")] = { + ExecutorAddr::fromPtr(WinSpecific::_alldiv), + JITSymbolFlags::Callable}; + symbolMap[mangler("_allrem")] = { + ExecutorAddr::fromPtr(WinSpecific::_allrem), + JITSymbolFlags::Callable}; + symbolMap[mangler("_aulldiv")] = { + ExecutorAddr::fromPtr(WinSpecific::_aulldiv), + JITSymbolFlags::Callable}; + symbolMap[mangler("_aullrem")] = { + ExecutorAddr::fromPtr(WinSpecific::_aullrem), + JITSymbolFlags::Callable}; } #endif @@ -1076,7 +1062,9 @@ SlangResult LLVMDownstreamCompiler::compile( } // Required or the symbols won't be found - jit->getMainJITDylib().addToLinkOrder(stdcLib); + jit->getMainJITDylib().addToLinkOrder( + stdcLib, + JITDylibLookupFlags::MatchAllSymbols); } }