From 19227bc2a48a63d666aa46506d7c5d5acb54ecc1 Mon Sep 17 00:00:00 2001 From: Cyano Hao Date: Mon, 1 Apr 2024 11:00:20 +0800 Subject: [PATCH] update llvm compiler version in windows package (#360) --- .../{windows_domain.tl => windows_llvm.tl} | 133 ++++------------- addon/gen.sh | 2 +- packages/msys/build-llvm.sh | 3 +- packages/msys/compiler_hint.lua | 135 ++++-------------- .../windows/installer-scripts/redpanda.nsi | 4 + platform/windows/prepare_clang.sh | 77 ---------- 6 files changed, 57 insertions(+), 297 deletions(-) rename addon/compiler_hint/{windows_domain.tl => windows_llvm.tl} (74%) delete mode 100644 platform/windows/prepare_clang.sh diff --git a/addon/compiler_hint/windows_domain.tl b/addon/compiler_hint/windows_llvm.tl similarity index 74% rename from addon/compiler_hint/windows_domain.tl rename to addon/compiler_hint/windows_llvm.tl index fb6e00f8..021b8c5f 100644 --- a/addon/compiler_hint/windows_domain.tl +++ b/addon/compiler_hint/windows_llvm.tl @@ -33,27 +33,6 @@ local profileNameMap: {string:{string:string}} = { }, } -local function nameGeneratorMingwGcc(lang: string, arch: string, profile: string, isUtf8: boolean): string - local template: {string:string} = { - en_US = "MinGW GCC %1 in %2, %3", - pt_BR = "GCC MinGW %1 em %2, %3", - zh_CN = "%2 MinGW GCC %1,%3", - zh_TW = "%2 MinGW GCC %1,%3", - } - local systemCodePage: {string:string} = { - en_US = "system code page", - pt_Br = "página de código do sistema", - zh_CN = "系统代码页", - zh_TW = "系統代碼頁", - } - return C_Util.format( - template[lang] or template.en_US, - gnuArchMap[arch], - isUtf8 and "UTF-8" or systemCodePage[lang] or systemCodePage.en_US, - profileNameMap[profile][lang] or profileNameMap[profile].en_US - ) -end - local function nameGeneratorClang(lang: string, arch: string, profile: string, isMingw: boolean): string local template: {string:string} = { en_US = "%1 Clang %2, %3", @@ -169,75 +148,6 @@ global function main(): CompilerHint local noSearch = {} local preferCompiler = 0 - local function checkAndAddMingw(arch: string) - local binDir: string - local libDir: string - local excludeBinDir: string - if arch == "i386" then - binDir = libexecDir .. "/mingw32/bin" -- must match case because Windows filesystem can be case sensitive - libDir = libexecDir .. "/mingw32/i686-w64-mingw32/lib" - excludeBinDir = libexecDir .. "/MinGW32/bin" -- workaround for path check - elseif arch == "x86_64" then - binDir = libexecDir .. "/mingw64/bin" - libDir = libexecDir .. "/mingw64/x86_64-w64-mingw32/lib" - excludeBinDir = libexecDir .. "/MinGW64/bin" - else - return - end - - if not C_FileSystem.isExecutable(binDir .. "/gcc.exe") then - return - end - - local programs: Programs = { - cCompiler = binDir .. "/gcc.exe", - cxxCompiler = binDir .. "/g++.exe", - make = binDir .. "/mingw32-make.exe", - debugger = binDir .. "/gdb.exe", - debugServer = binDir .. "/gdbserver.exe", - resourceCompiler = binDir .. "/windres.exe", - binDirs = {binDir}, - } - - if C_FileSystem.exists(libDir .. "/libutf8.a") then - local release, debug_, _ = generateConfig( - function (arch_: string, profile: string): string - return nameGeneratorMingwGcc(lang, arch_, profile, true) - end, - programs, - { - arch = arch, - customLinkParams = {"-Wl,--whole-archive", "-lutf8", "-Wl,--no-whole-archive"}, - } - ) - table.insert(compilerList, release) - table.insert(compilerList, debug_) - if preferCompiler == 0 then - preferCompiler = 2 - end - end - - do - local release, debug_, _ = generateConfig( - function (arch_: string, profile: string): string - return nameGeneratorMingwGcc(lang, arch_, profile, false) - end, - programs, - { - arch = arch, - isAnsi = true, - } - ) - table.insert(compilerList, release) - table.insert(compilerList, debug_) - if preferCompiler == 0 then - preferCompiler = 2 - end - end - - table.insert(noSearch, excludeBinDir) - end - local function checkAndAddClang() if not C_FileSystem.isExecutable(libexecDir .. "/llvm-mingw/bin/clang.exe") then return @@ -247,6 +157,7 @@ global function main(): CompilerHint local appTriplet = gnuArchMap[appArch] .. "-w64-mingw32" local appDllDir = libexecDir .. "/llvm-mingw/" .. appTriplet .. "/bin" do + local libDir = libexecDir .. "/llvm-mingw/" .. appTriplet .. "/lib" -- appArch is always debuggable local programs: Programs = { cCompiler = binDir .. "/" .. appTriplet .. "-clang.exe", @@ -257,6 +168,10 @@ global function main(): CompilerHint resourceCompiler = binDir .. "/" .. appTriplet .. "-windres.exe", binDirs = {binDir, appDllDir}, } + local customLinkParams: {string} = nil + if C_FileSystem.exists(libDir .. "/utf8init.o") then + customLinkParams = {"-Wl,utf8init.o", "-Wl,utf8manifest.o"} + end local release, debug_, debugWithAsan = generateConfig( function (arch_: string, profile: string): string return nameGeneratorClang(lang, arch_, profile, true) @@ -264,6 +179,7 @@ global function main(): CompilerHint programs, { arch = appArch, + customLinkParams = customLinkParams, isClang = true, } ) @@ -286,6 +202,7 @@ global function main(): CompilerHint if foreignArch ~= appArch and gnuArch ~= nil then local foreignTriplet = gnuArch .. "-w64-mingw32" local foreignDllDir = libexecDir .. "/llvm-mingw/" .. foreignTriplet .. "/bin" + local libDir = libexecDir .. "/llvm-mingw/" .. foreignTriplet .. "/lib" local programs: Programs = { cCompiler = binDir .. "/" .. foreignTriplet .. "-clang.exe", cxxCompiler = binDir .. "/" .. foreignTriplet .. "-clang++.exe", @@ -295,6 +212,10 @@ global function main(): CompilerHint resourceCompiler = binDir .. "/" .. foreignTriplet .. "-windres.exe", binDirs = {binDir, foreignDllDir}, } + local customLinkParams: {string} = nil + if C_FileSystem.exists(libDir .. "/utf8init.o") then + customLinkParams = {"-Wl,utf8init.o", "-Wl,utf8manifest.o"} + end local release, _, _ = generateConfig( function (arch_: string, profile: string): string return nameGeneratorClang(lang, arch_, profile, true) @@ -302,6 +223,7 @@ global function main(): CompilerHint programs, { arch = foreignArch, + customLinkParams = customLinkParams, isClang = true, } ) @@ -330,6 +252,11 @@ global function main(): CompilerHint binDirs = {llvmOrgBinDir}, libDirs = {libDir}, } + local customLinkParams = {"-target", msvcTriplet} + if C_FileSystem.exists(libDir .. "/utf8init.o") then + table.insert(customLinkParams, "-Wl,utf8init.o") + table.insert(customLinkParams, "-Wl,utf8manifest.o") + end local release, debug_, _ = generateConfig( function (arch: string, profile: string): string return nameGeneratorClang(lang, arch, profile, false) @@ -343,9 +270,7 @@ global function main(): CompilerHint "-fms-compatibility", "-fdelayed-template-parsing", }, - customLinkParams = { - "-target", msvcTriplet, - }, + customLinkParams = customLinkParams; isClang = true, } ) @@ -369,6 +294,11 @@ global function main(): CompilerHint binDirs = {llvmOrgBinDir}, libDirs = {libDir}, } + local customLinkParams = {"-target", msvcTriplet} + if C_FileSystem.exists(libDir .. "/utf8init.o") then + table.insert(customLinkParams, "-Wl,utf8init.o") + table.insert(customLinkParams, "-Wl,utf8manifest.o") + end local release, _, _ = generateConfig( function (arch: string, profile: string): string return nameGeneratorClang(lang, arch, profile, false) @@ -382,9 +312,7 @@ global function main(): CompilerHint "-fms-compatibility", "-fdelayed-template-parsing", }, - customLinkParams = { - "-target", msvcTriplet, - }, + customLinkParams = customLinkParams, isClang = true, } ) @@ -394,18 +322,7 @@ global function main(): CompilerHint table.insert(noSearch, llvmOrgBinDir) end - if appArch == "x86_64" then - checkAndAddMingw("x86_64") - checkAndAddMingw("i386") - checkAndAddClang() - elseif appArch == "arm64" then - checkAndAddClang() - checkAndAddMingw("x86_64") - checkAndAddMingw("i386") - else - checkAndAddMingw("i386") - checkAndAddClang() - end + checkAndAddClang() local result = { compilerList = compilerList, diff --git a/addon/gen.sh b/addon/gen.sh index f7bd2b2d..3d9f4fed 100755 --- a/addon/gen.sh +++ b/addon/gen.sh @@ -25,6 +25,6 @@ function gen-compiler-hint() { tl gen --include-dir addon --global-env-def defs/compiler_hint --gen-compat off --gen-target 5.4 -o "$out" "$file" } -gen-compiler-hint addon/compiler_hint/windows_domain.tl packages/msys/domain/compiler_hint.lua +gen-compiler-hint addon/compiler_hint/windows_llvm.tl packages/msys/compiler_hint.lua gen-compiler-hint addon/compiler_hint/archlinux.tl packages/archlinux/compiler_hint.lua gen-compiler-hint addon/compiler_hint/debian.tl packages/debian/compiler_hint.lua diff --git a/packages/msys/build-llvm.sh b/packages/msys/build-llvm.sh index 4498b7d6..05721f3d 100644 --- a/packages/msys/build-llvm.sh +++ b/packages/msys/build-llvm.sh @@ -62,7 +62,7 @@ case $MSYSTEM in ;; esac -REDPANDA_LLVM_VERSION="17-r0" +REDPANDA_LLVM_VERSION="18-r0" WINDOWS_TERMINAL_VERSION="1.19.10821.0" _QMAKE="$MINGW_PREFIX/qt5-static/bin/qmake" @@ -184,6 +184,7 @@ function package() { -DREQUIRED_WINDOWS_NAME="Windows 10 v1903" -DHAVE_LLVM -DHAVE_OPENCONSOLE + -DHAVE_COMPILER_HINT ) "$_NSIS" "${nsis_flags[@]}" redpanda.nsi popd diff --git a/packages/msys/compiler_hint.lua b/packages/msys/compiler_hint.lua index 473d05fd..c8e49bec 100644 --- a/packages/msys/compiler_hint.lua +++ b/packages/msys/compiler_hint.lua @@ -33,27 +33,6 @@ local profileNameMap = { }, } -local function nameGeneratorMingwGcc(lang, arch, profile, isUtf8) - local template = { - en_US = "MinGW GCC %1 in %2, %3", - pt_BR = "GCC MinGW %1 em %2, %3", - zh_CN = "%2 MinGW GCC %1,%3", - zh_TW = "%2 MinGW GCC %1,%3", - } - local systemCodePage = { - en_US = "system code page", - pt_Br = "página de código do sistema", - zh_CN = "系统代码页", - zh_TW = "系統代碼頁", - } - return C_Util.format( - template[lang] or template.en_US, - gnuArchMap[arch], - isUtf8 and "UTF-8" or systemCodePage[lang] or systemCodePage.en_US, - profileNameMap[profile][lang] or profileNameMap[profile].en_US) - -end - local function nameGeneratorClang(lang, arch, profile, isMingw) local template = { en_US = "%1 Clang %2, %3", @@ -169,75 +148,6 @@ function main() local noSearch = {} local preferCompiler = 0 - local function checkAndAddMingw(arch) - local binDir - local libDir - local excludeBinDir - if arch == "i386" then - binDir = libexecDir .. "/mingw32/bin" - libDir = libexecDir .. "/mingw32/i686-w64-mingw32/lib" - excludeBinDir = libexecDir .. "/MinGW32/bin" - elseif arch == "x86_64" then - binDir = libexecDir .. "/mingw64/bin" - libDir = libexecDir .. "/mingw64/x86_64-w64-mingw32/lib" - excludeBinDir = libexecDir .. "/MinGW64/bin" - else - return - end - - if not C_FileSystem.isExecutable(binDir .. "/gcc.exe") then - return - end - - local programs = { - cCompiler = binDir .. "/gcc.exe", - cxxCompiler = binDir .. "/g++.exe", - make = binDir .. "/mingw32-make.exe", - debugger = binDir .. "/gdb.exe", - debugServer = binDir .. "/gdbserver.exe", - resourceCompiler = binDir .. "/windres.exe", - binDirs = { binDir }, - } - - if C_FileSystem.exists(libDir .. "/libutf8.a") then - local release, debug_, _ = generateConfig( - function(arch_, profile) - return nameGeneratorMingwGcc(lang, arch_, profile, true) - end, - programs, - { - arch = arch, - customLinkParams = { "-Wl,--whole-archive", "-lutf8", "-Wl,--no-whole-archive" }, - }) - - table.insert(compilerList, release) - table.insert(compilerList, debug_) - if preferCompiler == 0 then - preferCompiler = 2 - end - end - - do - local release, debug_, _ = generateConfig( - function(arch_, profile) - return nameGeneratorMingwGcc(lang, arch_, profile, false) - end, - programs, - { - arch = arch, - isAnsi = true, - }) - - table.insert(compilerList, release) - table.insert(compilerList, debug_) - if preferCompiler == 0 then - preferCompiler = 2 - end - end - - table.insert(noSearch, excludeBinDir) - end - local function checkAndAddClang() if not C_FileSystem.isExecutable(libexecDir .. "/llvm-mingw/bin/clang.exe") then return @@ -247,6 +157,7 @@ function main() local appTriplet = gnuArchMap[appArch] .. "-w64-mingw32" local appDllDir = libexecDir .. "/llvm-mingw/" .. appTriplet .. "/bin" do + local libDir = libexecDir .. "/llvm-mingw/" .. appTriplet .. "/lib" local programs = { cCompiler = binDir .. "/" .. appTriplet .. "-clang.exe", @@ -257,6 +168,10 @@ function main() resourceCompiler = binDir .. "/" .. appTriplet .. "-windres.exe", binDirs = { binDir, appDllDir }, } + local customLinkParams = nil + if C_FileSystem.exists(libDir .. "/utf8init.o") then + customLinkParams = { "-Wl,utf8init.o", "-Wl,utf8manifest.o" } + end local release, debug_, debugWithAsan = generateConfig( function(arch_, profile) return nameGeneratorClang(lang, arch_, profile, true) @@ -264,7 +179,7 @@ function main() programs, { arch = appArch, - customLinkParams = {}, + customLinkParams = customLinkParams, isClang = true, }) @@ -287,6 +202,7 @@ function main() if foreignArch ~= appArch and gnuArch ~= nil then local foreignTriplet = gnuArch .. "-w64-mingw32" local foreignDllDir = libexecDir .. "/llvm-mingw/" .. foreignTriplet .. "/bin" + local libDir = libexecDir .. "/llvm-mingw/" .. foreignTriplet .. "/lib" local programs = { cCompiler = binDir .. "/" .. foreignTriplet .. "-clang.exe", cxxCompiler = binDir .. "/" .. foreignTriplet .. "-clang++.exe", @@ -296,6 +212,10 @@ function main() resourceCompiler = binDir .. "/" .. foreignTriplet .. "-windres.exe", binDirs = { binDir, foreignDllDir }, } + local customLinkParams = nil + if C_FileSystem.exists(libDir .. "/utf8init.o") then + customLinkParams = { "-Wl,utf8init.o", "-Wl,utf8manifest.o" } + end local release, _, _ = generateConfig( function(arch_, profile) return nameGeneratorClang(lang, arch_, profile, true) @@ -303,7 +223,7 @@ function main() programs, { arch = foreignArch, - customLinkParams = {}, + customLinkParams = customLinkParams, isClang = true, }) @@ -332,6 +252,11 @@ function main() binDirs = { llvmOrgBinDir }, libDirs = { libDir }, } + local customLinkParams = { "-target", msvcTriplet } + if C_FileSystem.exists(libDir .. "/utf8init.o") then + table.insert(customLinkParams, "-Wl,utf8init.o") + table.insert(customLinkParams, "-Wl,utf8manifest.o") + end local release, debug_, _ = generateConfig( function(arch, profile) return nameGeneratorClang(lang, arch, profile, false) @@ -345,9 +270,7 @@ function main() "-fms-compatibility", "-fdelayed-template-parsing", }, - customLinkParams = { - "-target", msvcTriplet, - }, + customLinkParams = customLinkParams, isClang = true, }) @@ -371,6 +294,11 @@ function main() binDirs = { llvmOrgBinDir }, libDirs = { libDir }, } + local customLinkParams = { "-target", msvcTriplet } + if C_FileSystem.exists(libDir .. "/utf8init.o") then + table.insert(customLinkParams, "-Wl,utf8init.o") + table.insert(customLinkParams, "-Wl,utf8manifest.o") + end local release, _, _ = generateConfig( function(arch, profile) return nameGeneratorClang(lang, arch, profile, false) @@ -384,9 +312,7 @@ function main() "-fms-compatibility", "-fdelayed-template-parsing", }, - customLinkParams = { - "-target", msvcTriplet, - }, + customLinkParams = customLinkParams, isClang = true, }) @@ -396,18 +322,7 @@ function main() table.insert(noSearch, llvmOrgBinDir) end - if appArch == "x86_64" then - checkAndAddMingw("x86_64") - checkAndAddMingw("i386") - checkAndAddClang() - elseif appArch == "arm64" then - checkAndAddClang() - checkAndAddMingw("x86_64") - checkAndAddMingw("i386") - else - checkAndAddMingw("i386") - checkAndAddClang() - end + checkAndAddClang() local result = { compilerList = compilerList, diff --git a/platform/windows/installer-scripts/redpanda.nsi b/platform/windows/installer-scripts/redpanda.nsi index 47068d91..8ab06236 100644 --- a/platform/windows/installer-scripts/redpanda.nsi +++ b/platform/windows/installer-scripts/redpanda.nsi @@ -126,6 +126,9 @@ Section "$(SectionMainName)" SectionMain !ifdef HAVE_OPENCONSOLE File "OpenConsole.exe" !endif + !ifdef HAVE_COMPILER_HINT + File "compiler_hint.lua" + !endif ; Write required paths SetOutPath $INSTDIR\Templates @@ -435,6 +438,7 @@ Section "Uninstall" Delete "$INSTDIR\README.md" Delete "$INSTDIR\qt.conf" Delete "$INSTDIR\OpenConsole.exe" + Delete "$INSTDIR\compiler_hint.lua" RMDir /r "$INSTDIR\Lang" RMDir /r "$INSTDIR\Templates" diff --git a/platform/windows/prepare_clang.sh b/platform/windows/prepare_clang.sh deleted file mode 100644 index a560a39f..00000000 --- a/platform/windows/prepare_clang.sh +++ /dev/null @@ -1,77 +0,0 @@ -#!/bin/bash - -ORIGIN="/clang64" -TARGET="/tmp/clang64" - -echo "Copying folder..." -rm -rf $TARGET -cp -a $ORIGIN $TARGET - -#remove files not needed -pushd . -cd $TARGET -rm -rf bin/llvm-exegesis.exe -rm -rf bin/c-index-test.exe -rm -rf bin/obj2yaml.exe -rm -rf bin/yaml2obj.exe -rm -rf bin/ld.lld.exe -rm -rf bin/ld64.lld.exe -rm -rf bin/lld.exe -rm -rf bin/lld-link.exe -rm -rf bin/wasm-ld.exe -rm -rf bin/llvm-readelf.exe -rm -rf bin/llvm-readobj.exe -rm -rf bin/tcl86.dll -rm -rf bin/tk86.dll -rm -rf bin/llvm-objdump.exe -rm -rf bin/llvm-bitcode-strip.exe -rm -rf bin/llvm-install-name-tool.exe -rm -rf bin/llvm-objcopy.exe -rm -rf bin/llvm-strip.exe -rm -rf bin/sqlite3_analyzer.exe -rm -rf bin/sqldiff.exe -rm -rf bin/dbhash.exe -rm -rf bin/glewinfo.exe -rm -rf bin/diagtool.exe -rm -rf bin/FileCheck.exe -rm -rf bin/KillTheDoctor.exe - -rm -rf lib/libclang*.a -rm -rf lib/libLLVM*.a -rm -rf lib/libtcl*.a -rm -rf lib/libtk*.a -rm -rf lib/liblldELF.a -rm -rf lib/liblldCOFF.a -rm -rf lib/liblldMachO.a -rm -rf lib/libtdbc* -rm -rf lib/tcl8 -rm -rf lib/tcl8.6 -rm -rf lib/tk8.6 -rm -rf lib/tdbc* -rm -rf lib/terminfo - -rm -rf include/clang -rm -rf include/clang-c -rm -rf include/llvm -rm -rf include/llvm-c -rm -rf include/tcl8.6 -rm -rf include/tk8.6 -rm -rf include/lldb - -rm -rf share/doc -rm -rf share/info -rm -rf share/man -rm -rf share/sqlite -rm -rf share/locale -rm -rf share/gtk-doc -rm -rf share/terminfo - -rm -rf var - -find . -name "__pycache__" -exec rm -rf {} \; -popd - - - - -