Skip to content

Commit 0e1e468

Browse files
tritaoyou74674
andauthored
Update to Clang 16 for MSVC 2022 support (#1724)
* support clang 15.0.7 * Fix Premake archive logic to work with official releases. * Try and upgrade CI to latest OS versions. * Try and fix LLD link call in parser. * CI fixes. * Enable VS 2019 and VS 2022 for LLVM windows workflow. * Update to a more recent LLVM revision. * More build fixes. * Use the system linker for linking symbols libraries outside Windows. Builtin lld is giving some weird linking errors when linking with the new LLVM version. We probably need to set some custom options. Using the system linker should be a better idea anyway, more robust and future proof. --------- Co-authored-by: you74674 <[email protected]>
1 parent e464da4 commit 0e1e468

File tree

19 files changed

+310
-70
lines changed

19 files changed

+310
-70
lines changed

.github/workflows/llvm-win.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ jobs:
99
fail-fast: false
1010
matrix:
1111
config:
12-
- { os: windows-2022, platform: x86, vs: 2022 }
13-
- { os: windows-2022, platform: x64, vs: 2022 }
12+
- { os: windows-2022, platform: x86, vs: "Program Files/Microsoft Visual Studio/2022" }
13+
- { os: windows-2022, platform: x64, vs: "Program Files/Microsoft Visual Studio/2022" }
1414

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

@@ -35,7 +35,7 @@ jobs:
3535
- name: Environment
3636
shell: cmd
3737
run: |
38-
call "C:\Program Files\Microsoft Visual Studio\%VS_VERSION%\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" %PLATFORM%
38+
call "C:\%VS_VERSION%\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" %PLATFORM%
3939
:: Loop over all environment variables and make them global using set-env.
4040
:: See: https://stackoverflow.com/a/39184941
4141
setlocal

.github/workflows/main.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ jobs:
99
fail-fast: false
1010
matrix:
1111
config:
12-
- { os: ubuntu-20.04, platform: x64, cxx: g++-10, cc: gcc-10 }
12+
- { os: ubuntu-22.04, platform: x64, cxx: g++-11, cc: gcc-11 }
1313
- { os: macos-11, platform: x64, cxx: clang++, cc: clang }
14-
- { os: windows-2019, platform: x64, vs: msvc }
14+
- { os: windows-2022, platform: x64, vs: "Program Files/Microsoft Visual Studio/2022" }
1515

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

1818
env:
1919
CC: ${{ matrix.config.cc }}
2020
CXX: ${{ matrix.config.cxx }}
21+
VS_VERSION: ${{ matrix.config.vs }}
2122
PLATFORM: ${{ matrix.config.platform }}
2223
DOTNET_NOLOGO: true
2324
DOTNET_CLI_TELEMETRY_OPTOUT: true
@@ -38,7 +39,7 @@ jobs:
3839
- name: Environment
3940
if: matrix.config.vs
4041
shell: bash
41-
run: echo "/c/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/MSBuild/Current/Bin" >> $GITHUB_PATH
42+
run: echo "/c/$VS_VERSION/Enterprise/MSBuild/Current/Bin" >> $GITHUB_PATH
4243

4344
- name: Setup
4445
shell: bash

Directory.Build.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
</PropertyGroup>
5353

5454
<Target Name="prepack" DependsOnTargets="Build" Condition="'$(IsPackable)' == 'true' AND '$(Platform)' == 'x64'">
55-
<Copy SourceFiles="$(TargetDir)ref\$(TargetFileName)" DestinationFolder="$(PackageDir)ref\$(GlobalTargetFramework)" Condition="'$(ProduceReferenceAssembly)' == 'true' AND '$(RID)' == 'win-x64'" />
5655
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(PackageDir)runtimes\$(RID)\lib\$(GlobalTargetFramework)" />
5756
</Target>
5857
</Project>

build/LLVM.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ function SetupLLVMIncludes()
4242
includedirs
4343
{
4444
path.join(LLVMRootDirDebug, "include"),
45+
path.join(LLVMRootDirDebug, "llvm/include"),
4546
path.join(LLVMRootDirDebug, "lld/include"),
4647
path.join(LLVMRootDirDebug, "clang/include"),
4748
path.join(LLVMRootDirDebug, "clang/lib"),
@@ -53,6 +54,7 @@ function SetupLLVMIncludes()
5354
includedirs
5455
{
5556
path.join(LLVMRootDirRelease, "include"),
57+
path.join(LLVMRootDirRelease, "llvm/include"),
5658
path.join(LLVMRootDirRelease, "lld/include"),
5759
path.join(LLVMRootDirRelease, "clang/include"),
5860
path.join(LLVMRootDirRelease, "clang/lib"),
@@ -64,6 +66,7 @@ function SetupLLVMIncludes()
6466
includedirs
6567
{
6668
path.join(LLVMRootDir, "include"),
69+
path.join(LLVMRootDir, "llvm/include"),
6770
path.join(LLVMRootDir, "lld/include"),
6871
path.join(LLVMRootDir, "clang/include"),
6972
path.join(LLVMRootDir, "clang/lib"),
@@ -144,18 +147,22 @@ function SetupLLVMLibs()
144147
"clangCodeGen",
145148
"clangParse",
146149
"clangSema",
150+
"clangSupport",
147151
"clangAnalysis",
148152
"clangEdit",
149153
"clangAST",
150154
"clangLex",
151155
"clangBasic",
152156
"clangIndex",
157+
"clangASTMatchers",
158+
"LLVMWindowsDriver",
153159
"LLVMWindowsManifest",
154160
"LLVMDebugInfoPDB",
155161
"LLVMLTO",
156162
"LLVMPasses",
157163
"LLVMObjCARCOpts",
158164
"LLVMLibDriver",
165+
"LLVMFrontendHLSL",
159166
"LLVMFrontendOpenMP",
160167
"LLVMOption",
161168
"LLVMCoverage",
@@ -170,6 +177,7 @@ function SetupLLVMLibs()
170177
"LLVMVectorize",
171178
"LLVMLinker",
172179
"LLVMIRReader",
180+
"LLVMIRPrinter",
173181
"LLVMAsmParser",
174182
"LLVMMCDisassembler",
175183
"LLVMCFGuard",
@@ -178,7 +186,9 @@ function SetupLLVMLibs()
178186
"LLVMAsmPrinter",
179187
"LLVMDebugInfoDWARF",
180188
"LLVMCodeGen",
189+
"LLVMCodeGenTypes",
181190
"LLVMTarget",
191+
"LLVMTargetParser",
182192
"LLVMScalarOpts",
183193
"LLVMInstCombine",
184194
"LLVMAggressiveInstCombine",
@@ -202,7 +212,8 @@ function SetupLLVMLibs()
202212
"lldCommon",
203213
"lldCOFF",
204214
"lldELF",
205-
"lldMachO"
215+
"lldMachO",
216+
"lldMinGW"
206217
}
207218

208219
filter(c)

build/build.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set -e
33
builddir=$(cd "$(dirname "$0")"; pwd)
44
platform=x64
5-
vs=vs2019
5+
vs=vs2022
66
configuration=Release
77
build_only=false
88
ci=false
@@ -104,18 +104,26 @@ download_premake()
104104
{
105105
premake_dir="$builddir/premake"
106106
premake_filename=premake5
107+
premake_archive_ext=tar.gz
107108
if [ $oshost = "windows" ]; then
108109
premake_filename=$premake_filename.exe
110+
premake_archive_ext=zip
109111
fi
110112
premake_path=$premake_dir/$premake_filename
111113

112114
if ! [ -f "$premake_path" ]; then
113115
echo "Downloading and unpacking Premake..."
114-
premake_url=https://github.com/InteropAlliance/premake-core/releases/download/latest/premake-$oshost-$platform.zip
116+
premake_version=5.0.0-beta2
117+
premake_archive=premake-$premake_version-$oshost.$premake_archive_ext
118+
premake_url=https://github.com/premake/premake-core/releases/download/v$premake_version/$premake_archive
115119
curl -L -O $premake_url
116-
unzip premake-$oshost-$platform.zip $premake_filename -d "$premake_dir"
120+
if [ $oshost = "windows" ]; then
121+
unzip $premake_archive $premake_filename -d "$premake_dir"
122+
else
123+
tar -xf $premake_archive -C "$premake_dir" ./$premake_filename
124+
fi
117125
chmod +x "$premake_path"
118-
rm premake-$oshost-$platform.zip
126+
rm $premake_archive
119127
fi
120128
}
121129

build/llvm/LLVM-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
791523bae6153b13bb41ba05c9fc89e502cc4a1a
1+
6eb36aed86ea276695697093eb8136554c29286b

build/llvm/LLVM.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ function cmake(gen, conf, builddir, options)
251251
.. ' -DLLVM_ENABLE_LIBXML2=false'
252252
.. ' -DLLVM_ENABLE_TERMINFO=false'
253253
.. ' -DLLVM_ENABLE_ZLIB=false'
254+
.. ' -DLLVM_ENABLE_ZSTD=false'
254255
.. ' -DLLVM_INCLUDE_DOCS=false'
255256
.. ' -DLLVM_INCLUDE_EXAMPLES=false'
256257
.. ' -DLLVM_TARGETS_TO_BUILD="X86"'
@@ -370,6 +371,8 @@ function cmake(gen, conf, builddir, options)
370371
.. ' -DCLANG_TOOL_CLANG_FUZZER_BUILD=false'
371372
.. ' -DCLANG_TOOL_CLANG_IMPORT_TEST_BUILD=false'
372373
.. ' -DCLANG_TOOL_CLANG_NVLINK_WRAPPER_BUILD=false'
374+
.. ' -DCLANG_TOOL_CLANG_LINKER_WRAPPER_BUILD=false'
375+
.. ' -DCLANG_TOOL_CLANG_OFFLOAD_PACKAGER_BUILD=false'
373376
.. ' -DCLANG_TOOL_CLANG_OFFLOAD_BUNDLER_BUILD=false'
374377
.. ' -DCLANG_TOOL_CLANG_OFFLOAD_WRAPPER_BUILD=false'
375378
.. ' -DCLANG_TOOL_CLANG_REFACTOR_BUILD=false'
@@ -456,7 +459,7 @@ function package_llvm(conf, llvm_base, llvm_build)
456459
if os.isdir(out) then os.rmdir(out) end
457460
os.mkdir(out)
458461

459-
os.copydir(llvm_base .. "/llvm/include", out .. "/include")
462+
os.copydir(llvm_base .. "/llvm/include", out .. "/llvm/include")
460463
os.copydir(llvm_base .. "/lld/include", out .. "/lld/include")
461464
os.copydir(llvm_build .. "/include", out .. "/build/include")
462465

@@ -483,12 +486,10 @@ function package_llvm(conf, llvm_base, llvm_build)
483486
local out_lib_dir = out .. "/build/lib"
484487
if os.ishost("windows") then
485488
os.rmfiles(out_lib_dir, "clang*ARC*.lib")
486-
os.rmfiles(out_lib_dir, "clang*Matchers*.lib")
487489
os.rmfiles(out_lib_dir, "clang*Rewrite*.lib")
488490
os.rmfiles(out_lib_dir, "clang*StaticAnalyzer*.lib")
489491
else
490492
os.rmfiles(out_lib_dir, "libclang*ARC*.a")
491-
os.rmfiles(out_lib_dir, "libclang*Matchers*.a")
492493
os.rmfiles(out_lib_dir, "libclang*Rewrite*.a")
493494
os.rmfiles(out_lib_dir, "libclang*StaticAnalyzer*.a")
494495
end

src/Core/Toolchains/MSVCToolchain.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public enum VisualStudioVersion
1616
VS2015 = 14,
1717
VS2017 = 15,
1818
VS2019 = 16,
19+
VS2022 = 17,
1920
Latest,
2021
}
2122

@@ -67,9 +68,12 @@ public static Version GetCLVersion(VisualStudioVersion vsVersion)
6768
clVersion = new Version { Major = 19, Minor = 10 };
6869
break;
6970
case VisualStudioVersion.VS2019:
70-
case VisualStudioVersion.Latest:
7171
clVersion = new Version { Major = 19, Minor = 20 };
7272
break;
73+
case VisualStudioVersion.VS2022:
74+
case VisualStudioVersion.Latest:
75+
clVersion = new Version { Major = 19, Minor = 30 };
76+
break;
7377
default:
7478
throw new Exception("Unknown Visual Studio version");
7579
}

src/CppParser/CppParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include "CppParser.h"
99
#include "Parser.h"
10-
#include <llvm/Support/Host.h>
10+
#include <llvm/TargetParser/Host.h>
1111
#include <clang/Basic/Version.inc>
1212

1313
namespace CppSharp { namespace CppParser {

src/CppParser/Link.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
#include <Driver/ToolChains/Linux.h>
1212
#include <lld/Common/Driver.h>
1313

14+
LLD_HAS_DRIVER(coff)
15+
LLD_HAS_DRIVER(elf)
16+
LLD_HAS_DRIVER(mingw)
17+
LLD_HAS_DRIVER(macho)
18+
1419
using namespace CppSharp::CppParser;
1520

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

7075
std::vector<std::string> LibraryPaths;
7176
LibraryPaths.push_back("-libpath:" + TC.getSubDirectoryPath(
72-
clang::driver::toolchains::MSVCToolChain::SubDirectoryType::Lib));
77+
llvm::SubDirectoryType::Lib));
7378
std::string CRTPath;
7479
if (TC.getUniversalCRTLibraryPath(Args, CRTPath))
7580
LibraryPaths.push_back("-libpath:" + CRTPath);
@@ -100,7 +105,7 @@ bool Parser::LinkWindows(const CppLinkerOptions* LinkerOptions,
100105
std::string Out("-out:" + std::string(Output));
101106
args.push_back(Out.data());
102107

103-
return lld::coff::link(args, false, outs(), errs());
108+
return lld::coff::link(args, outs(), errs(), /*exitEarly=*/false, /*disableOutput=*/false);
104109
#else
105110
return false;
106111
#endif
@@ -141,7 +146,7 @@ bool Parser::LinkELF(const CppLinkerOptions* LinkerOptions,
141146
std::string Out(Output);
142147
args.push_back(Out.data());
143148

144-
return lld::elf::link(args, false, outs(), errs());
149+
return lld::elf::link(args, outs(), errs(), /*exitEarly=*/false, /*disableOutput=*/false);
145150
#else
146151
return false;
147152
#endif
@@ -182,7 +187,7 @@ bool Parser::LinkMachO(const CppLinkerOptions* LinkerOptions,
182187
std::string Out(Output);
183188
args.push_back(Out.data());
184189

185-
return lld::macho::link(args, false, outs(), errs());
190+
return lld::macho::link(args, outs(), errs(), /*exitEarly=*/false, /*disableOutput=*/false);
186191
#else
187192
return false;
188193
#endif

0 commit comments

Comments
 (0)