Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Clang 16 for MSVC 2022 support #1724

Merged
merged 9 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions .github/workflows/llvm-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jobs:
fail-fast: false
matrix:
config:
- { os: windows-2022, platform: x86, vs: 2022 }
- { os: windows-2022, platform: x64, vs: 2022 }
- { os: windows-2022, platform: x86, vs: "Program Files/Microsoft Visual Studio/2022" }
- { os: windows-2022, platform: x64, vs: "Program Files/Microsoft Visual Studio/2022" }

runs-on: ${{ matrix.config.os }}

Expand All @@ -35,7 +35,7 @@ jobs:
- name: Environment
shell: cmd
run: |
call "C:\Program Files\Microsoft Visual Studio\%VS_VERSION%\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" %PLATFORM%
call "C:\%VS_VERSION%\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" %PLATFORM%
:: Loop over all environment variables and make them global using set-env.
:: See: https://stackoverflow.com/a/39184941
setlocal
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ jobs:
fail-fast: false
matrix:
config:
- { os: ubuntu-20.04, platform: x64, cxx: g++-10, cc: gcc-10 }
- { os: ubuntu-22.04, platform: x64, cxx: g++-11, cc: gcc-11 }
- { os: macos-11, platform: x64, cxx: clang++, cc: clang }
- { os: windows-2019, platform: x64, vs: msvc }
- { os: windows-2022, platform: x64, vs: "Program Files/Microsoft Visual Studio/2022" }

runs-on: ${{ matrix.config.os }}

env:
CC: ${{ matrix.config.cc }}
CXX: ${{ matrix.config.cxx }}
VS_VERSION: ${{ matrix.config.vs }}
PLATFORM: ${{ matrix.config.platform }}
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
Expand All @@ -38,7 +39,7 @@ jobs:
- name: Environment
if: matrix.config.vs
shell: bash
run: echo "/c/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/MSBuild/Current/Bin" >> $GITHUB_PATH
run: echo "/c/$VS_VERSION/Enterprise/MSBuild/Current/Bin" >> $GITHUB_PATH

- name: Setup
shell: bash
Expand Down
1 change: 0 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
</PropertyGroup>

<Target Name="prepack" DependsOnTargets="Build" Condition="'$(IsPackable)' == 'true' AND '$(Platform)' == 'x64'">
<Copy SourceFiles="$(TargetDir)ref\$(TargetFileName)" DestinationFolder="$(PackageDir)ref\$(GlobalTargetFramework)" Condition="'$(ProduceReferenceAssembly)' == 'true' AND '$(RID)' == 'win-x64'" />
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(PackageDir)runtimes\$(RID)\lib\$(GlobalTargetFramework)" />
</Target>
</Project>
13 changes: 12 additions & 1 deletion build/LLVM.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function SetupLLVMIncludes()
includedirs
{
path.join(LLVMRootDirDebug, "include"),
path.join(LLVMRootDirDebug, "llvm/include"),
path.join(LLVMRootDirDebug, "lld/include"),
path.join(LLVMRootDirDebug, "clang/include"),
path.join(LLVMRootDirDebug, "clang/lib"),
Expand All @@ -53,6 +54,7 @@ function SetupLLVMIncludes()
includedirs
{
path.join(LLVMRootDirRelease, "include"),
path.join(LLVMRootDirRelease, "llvm/include"),
path.join(LLVMRootDirRelease, "lld/include"),
path.join(LLVMRootDirRelease, "clang/include"),
path.join(LLVMRootDirRelease, "clang/lib"),
Expand All @@ -64,6 +66,7 @@ function SetupLLVMIncludes()
includedirs
{
path.join(LLVMRootDir, "include"),
path.join(LLVMRootDir, "llvm/include"),
path.join(LLVMRootDir, "lld/include"),
path.join(LLVMRootDir, "clang/include"),
path.join(LLVMRootDir, "clang/lib"),
Expand Down Expand Up @@ -144,18 +147,22 @@ function SetupLLVMLibs()
"clangCodeGen",
"clangParse",
"clangSema",
"clangSupport",
"clangAnalysis",
"clangEdit",
"clangAST",
"clangLex",
"clangBasic",
"clangIndex",
"clangASTMatchers",
"LLVMWindowsDriver",
"LLVMWindowsManifest",
"LLVMDebugInfoPDB",
"LLVMLTO",
"LLVMPasses",
"LLVMObjCARCOpts",
"LLVMLibDriver",
"LLVMFrontendHLSL",
"LLVMFrontendOpenMP",
"LLVMOption",
"LLVMCoverage",
Expand All @@ -170,6 +177,7 @@ function SetupLLVMLibs()
"LLVMVectorize",
"LLVMLinker",
"LLVMIRReader",
"LLVMIRPrinter",
"LLVMAsmParser",
"LLVMMCDisassembler",
"LLVMCFGuard",
Expand All @@ -178,7 +186,9 @@ function SetupLLVMLibs()
"LLVMAsmPrinter",
"LLVMDebugInfoDWARF",
"LLVMCodeGen",
"LLVMCodeGenTypes",
"LLVMTarget",
"LLVMTargetParser",
"LLVMScalarOpts",
"LLVMInstCombine",
"LLVMAggressiveInstCombine",
Expand All @@ -202,7 +212,8 @@ function SetupLLVMLibs()
"lldCommon",
"lldCOFF",
"lldELF",
"lldMachO"
"lldMachO",
"lldMinGW"
}

filter(c)
Expand Down
16 changes: 12 additions & 4 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -e
builddir=$(cd "$(dirname "$0")"; pwd)
platform=x64
vs=vs2019
vs=vs2022
configuration=Release
build_only=false
ci=false
Expand Down Expand Up @@ -104,18 +104,26 @@ download_premake()
{
premake_dir="$builddir/premake"
premake_filename=premake5
premake_archive_ext=tar.gz
if [ $oshost = "windows" ]; then
premake_filename=$premake_filename.exe
premake_archive_ext=zip
fi
premake_path=$premake_dir/$premake_filename

if ! [ -f "$premake_path" ]; then
echo "Downloading and unpacking Premake..."
premake_url=https://github.com/InteropAlliance/premake-core/releases/download/latest/premake-$oshost-$platform.zip
premake_version=5.0.0-beta2
premake_archive=premake-$premake_version-$oshost.$premake_archive_ext
premake_url=https://github.com/premake/premake-core/releases/download/v$premake_version/$premake_archive
curl -L -O $premake_url
unzip premake-$oshost-$platform.zip $premake_filename -d "$premake_dir"
if [ $oshost = "windows" ]; then
unzip $premake_archive $premake_filename -d "$premake_dir"
else
tar -xf $premake_archive -C "$premake_dir" ./$premake_filename
fi
chmod +x "$premake_path"
rm premake-$oshost-$platform.zip
rm $premake_archive
fi
}

Expand Down
2 changes: 1 addition & 1 deletion build/llvm/LLVM-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
791523bae6153b13bb41ba05c9fc89e502cc4a1a
6eb36aed86ea276695697093eb8136554c29286b
7 changes: 4 additions & 3 deletions build/llvm/LLVM.lua
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ function cmake(gen, conf, builddir, options)
.. ' -DLLVM_ENABLE_LIBXML2=false'
.. ' -DLLVM_ENABLE_TERMINFO=false'
.. ' -DLLVM_ENABLE_ZLIB=false'
.. ' -DLLVM_ENABLE_ZSTD=false'
.. ' -DLLVM_INCLUDE_DOCS=false'
.. ' -DLLVM_INCLUDE_EXAMPLES=false'
.. ' -DLLVM_TARGETS_TO_BUILD="X86"'
Expand Down Expand Up @@ -370,6 +371,8 @@ function cmake(gen, conf, builddir, options)
.. ' -DCLANG_TOOL_CLANG_FUZZER_BUILD=false'
.. ' -DCLANG_TOOL_CLANG_IMPORT_TEST_BUILD=false'
.. ' -DCLANG_TOOL_CLANG_NVLINK_WRAPPER_BUILD=false'
.. ' -DCLANG_TOOL_CLANG_LINKER_WRAPPER_BUILD=false'
.. ' -DCLANG_TOOL_CLANG_OFFLOAD_PACKAGER_BUILD=false'
.. ' -DCLANG_TOOL_CLANG_OFFLOAD_BUNDLER_BUILD=false'
.. ' -DCLANG_TOOL_CLANG_OFFLOAD_WRAPPER_BUILD=false'
.. ' -DCLANG_TOOL_CLANG_REFACTOR_BUILD=false'
Expand Down Expand Up @@ -456,7 +459,7 @@ function package_llvm(conf, llvm_base, llvm_build)
if os.isdir(out) then os.rmdir(out) end
os.mkdir(out)

os.copydir(llvm_base .. "/llvm/include", out .. "/include")
os.copydir(llvm_base .. "/llvm/include", out .. "/llvm/include")
os.copydir(llvm_base .. "/lld/include", out .. "/lld/include")
os.copydir(llvm_build .. "/include", out .. "/build/include")

Expand All @@ -483,12 +486,10 @@ function package_llvm(conf, llvm_base, llvm_build)
local out_lib_dir = out .. "/build/lib"
if os.ishost("windows") then
os.rmfiles(out_lib_dir, "clang*ARC*.lib")
os.rmfiles(out_lib_dir, "clang*Matchers*.lib")
os.rmfiles(out_lib_dir, "clang*Rewrite*.lib")
os.rmfiles(out_lib_dir, "clang*StaticAnalyzer*.lib")
else
os.rmfiles(out_lib_dir, "libclang*ARC*.a")
os.rmfiles(out_lib_dir, "libclang*Matchers*.a")
os.rmfiles(out_lib_dir, "libclang*Rewrite*.a")
os.rmfiles(out_lib_dir, "libclang*StaticAnalyzer*.a")
end
Expand Down
6 changes: 5 additions & 1 deletion src/Core/Toolchains/MSVCToolchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public enum VisualStudioVersion
VS2015 = 14,
VS2017 = 15,
VS2019 = 16,
VS2022 = 17,
Latest,
}

Expand Down Expand Up @@ -67,9 +68,12 @@ public static Version GetCLVersion(VisualStudioVersion vsVersion)
clVersion = new Version { Major = 19, Minor = 10 };
break;
case VisualStudioVersion.VS2019:
case VisualStudioVersion.Latest:
clVersion = new Version { Major = 19, Minor = 20 };
break;
case VisualStudioVersion.VS2022:
case VisualStudioVersion.Latest:
clVersion = new Version { Major = 19, Minor = 30 };
break;
default:
throw new Exception("Unknown Visual Studio version");
}
Expand Down
2 changes: 1 addition & 1 deletion src/CppParser/CppParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "CppParser.h"
#include "Parser.h"
#include <llvm/Support/Host.h>
#include <llvm/TargetParser/Host.h>
#include <clang/Basic/Version.inc>

namespace CppSharp { namespace CppParser {
Expand Down
13 changes: 9 additions & 4 deletions src/CppParser/Link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
#include <Driver/ToolChains/Linux.h>
#include <lld/Common/Driver.h>

LLD_HAS_DRIVER(coff)
LLD_HAS_DRIVER(elf)
LLD_HAS_DRIVER(mingw)
LLD_HAS_DRIVER(macho)

using namespace CppSharp::CppParser;

bool Parser::Link(const std::string& File, const CppLinkerOptions* LinkerOptions)
Expand Down Expand Up @@ -69,7 +74,7 @@ bool Parser::LinkWindows(const CppLinkerOptions* LinkerOptions,

std::vector<std::string> LibraryPaths;
LibraryPaths.push_back("-libpath:" + TC.getSubDirectoryPath(
clang::driver::toolchains::MSVCToolChain::SubDirectoryType::Lib));
llvm::SubDirectoryType::Lib));
std::string CRTPath;
if (TC.getUniversalCRTLibraryPath(Args, CRTPath))
LibraryPaths.push_back("-libpath:" + CRTPath);
Expand Down Expand Up @@ -100,7 +105,7 @@ bool Parser::LinkWindows(const CppLinkerOptions* LinkerOptions,
std::string Out("-out:" + std::string(Output));
args.push_back(Out.data());

return lld::coff::link(args, false, outs(), errs());
return lld::coff::link(args, outs(), errs(), /*exitEarly=*/false, /*disableOutput=*/false);
#else
return false;
#endif
Expand Down Expand Up @@ -141,7 +146,7 @@ bool Parser::LinkELF(const CppLinkerOptions* LinkerOptions,
std::string Out(Output);
args.push_back(Out.data());

return lld::elf::link(args, false, outs(), errs());
return lld::elf::link(args, outs(), errs(), /*exitEarly=*/false, /*disableOutput=*/false);
#else
return false;
#endif
Expand Down Expand Up @@ -182,7 +187,7 @@ bool Parser::LinkMachO(const CppLinkerOptions* LinkerOptions,
std::string Out(Output);
args.push_back(Out.data());

return lld::macho::link(args, false, outs(), errs());
return lld::macho::link(args, outs(), errs(), /*exitEarly=*/false, /*disableOutput=*/false);
#else
return false;
#endif
Expand Down
14 changes: 7 additions & 7 deletions src/CppParser/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ AST::Expr* Parser::WalkExpression(const clang::Expr* Expr)
_S->length = S->getLength();
_S->charByteWidth = S->getCharByteWidth();
_S->kind = (StringLiteral::StringKind) S->getKind();
_S->isAscii = S->isAscii();
_S->isAscii = S->isOrdinary();
_S->isWide = S->isWide();
_S->isUTF8 = S->isUTF8();
_S->isUTF16 = S->isUTF16();
Expand Down Expand Up @@ -400,7 +400,7 @@ AST::Expr* Parser::WalkExpression(const clang::Expr* Expr)
_S->calleeDecl = static_cast<AST::Declaration*>(WalkDeclaration(S->getCalleeDecl()));
_S->directCallee = static_cast<AST::Function*>(WalkDeclaration(S->getDirectCallee()));
_S->numArgs = S->getNumArgs();
_S->numCommas = S->getNumCommas();
_S->numCommas = 0; // Removed from Clang
_S->builtinCallee = S->getBuiltinCallee();
_S->isCallToStdMove = S->isCallToStdMove();
for (auto _E : S->arguments())
Expand Down Expand Up @@ -1172,7 +1172,7 @@ AST::Expr* Parser::WalkExpression(const clang::Expr* Expr)
_S->calleeDecl = static_cast<AST::Declaration*>(WalkDeclaration(S->getCalleeDecl()));
_S->directCallee = static_cast<AST::Function*>(WalkDeclaration(S->getDirectCallee()));
_S->numArgs = S->getNumArgs();
_S->numCommas = S->getNumCommas();
_S->numCommas = 0; // Removed from Clang
_S->builtinCallee = S->getBuiltinCallee();
_S->isCallToStdMove = S->isCallToStdMove();
for (auto _E : S->arguments())
Expand Down Expand Up @@ -1207,7 +1207,7 @@ AST::Expr* Parser::WalkExpression(const clang::Expr* Expr)
_S->calleeDecl = static_cast<AST::Declaration*>(WalkDeclaration(S->getCalleeDecl()));
_S->directCallee = static_cast<AST::Function*>(WalkDeclaration(S->getDirectCallee()));
_S->numArgs = S->getNumArgs();
_S->numCommas = S->getNumCommas();
_S->numCommas = 0; // Removed from Clang
_S->builtinCallee = S->getBuiltinCallee();
_S->isCallToStdMove = S->isCallToStdMove();
for (auto _E : S->arguments())
Expand Down Expand Up @@ -1241,7 +1241,7 @@ AST::Expr* Parser::WalkExpression(const clang::Expr* Expr)
_S->calleeDecl = static_cast<AST::Declaration*>(WalkDeclaration(S->getCalleeDecl()));
_S->directCallee = static_cast<AST::Function*>(WalkDeclaration(S->getDirectCallee()));
_S->numArgs = S->getNumArgs();
_S->numCommas = S->getNumCommas();
_S->numCommas = 0; // Removed from Clang
_S->builtinCallee = S->getBuiltinCallee();
_S->isCallToStdMove = S->isCallToStdMove();
for (auto _E : S->arguments())
Expand Down Expand Up @@ -1391,7 +1391,7 @@ AST::Expr* Parser::WalkExpression(const clang::Expr* Expr)
_S->calleeDecl = static_cast<AST::Declaration*>(WalkDeclaration(S->getCalleeDecl()));
_S->directCallee = static_cast<AST::Function*>(WalkDeclaration(S->getDirectCallee()));
_S->numArgs = S->getNumArgs();
_S->numCommas = S->getNumCommas();
_S->numCommas = 0; // Removed from Clang
_S->builtinCallee = S->getBuiltinCallee();
_S->isCallToStdMove = S->isCallToStdMove();
for (auto _E : S->arguments())
Expand Down Expand Up @@ -1850,7 +1850,7 @@ AST::Expr* Parser::WalkExpression(const clang::Expr* Expr)
_S->operatorDelete = static_cast<AST::Function*>(WalkDeclaration(S->getOperatorDelete()));
_S->allocatedType = GetQualifiedType(S->getAllocatedType());
_S->isArray = S->isArray();
_S->arraySize = static_cast<AST::Expr*>(WalkExpression(S->getArraySize().getValue()));
_S->arraySize = static_cast<AST::Expr*>(WalkExpression(S->getArraySize().value()));
_S->numPlacementArgs = S->getNumPlacementArgs();
_S->isParenTypeId = S->isParenTypeId();
_S->isGlobalNew = S->isGlobalNew();
Expand Down
2 changes: 1 addition & 1 deletion src/CppParser/ParseStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ AST::Stmt* Parser::WalkStatement(const clang::Stmt* Stmt)
_S->allocate = static_cast<AST::Expr*>(WalkExpression(S->getAllocate()));
_S->deallocate = static_cast<AST::Expr*>(WalkExpression(S->getDeallocate()));
_S->returnValueInit = static_cast<AST::Expr*>(WalkExpression(S->getReturnValueInit()));
_S->resultDecl = static_cast<AST::Stmt*>(WalkStatement(S->getResultDecl()));
_S->resultDecl = static_cast<AST::Stmt*>(WalkStatement(S->getReturnValue()));
_S->returnStmt = static_cast<AST::Stmt*>(WalkStatement(S->getReturnStmt()));
_S->returnStmtOnAllocFailure = static_cast<AST::Stmt*>(WalkStatement(S->getReturnStmtOnAllocFailure()));
_Stmt = _S;
Expand Down
Loading
Loading