From 54aae9d72a12ae8af93ba35d00a3817e3105dcce Mon Sep 17 00:00:00 2001 From: Ophestra Date: Thu, 21 May 2026 17:51:23 +0900 Subject: [PATCH] internal/rosa/package: migrate llvm patches LLVM itself is unlikely to ever be migrated due to complexity of the bootstrap, so migrate patches instead. Signed-off-by: Ophestra --- internal/rosa/llvm.go | 20 ++++ .../rosa/package/llvm/add-rosa-vendor.patch | 32 +++++++ .../increase-stack-size-unconditional.patch | 13 +++ .../package/llvm/path-system-include.patch | 25 +++++ .../llvm/path-system-libraries.patch} | 96 +------------------ .../package/llvm/xfail-broken-tests.patch | 10 ++ 6 files changed, 101 insertions(+), 95 deletions(-) create mode 100644 internal/rosa/package/llvm/add-rosa-vendor.patch create mode 100644 internal/rosa/package/llvm/increase-stack-size-unconditional.patch create mode 100644 internal/rosa/package/llvm/path-system-include.patch rename internal/rosa/{llvm_patches.go => package/llvm/path-system-libraries.patch} (50%) create mode 100644 internal/rosa/package/llvm/xfail-broken-tests.patch diff --git a/internal/rosa/llvm.go b/internal/rosa/llvm.go index 11f8ad0b..c4d84988 100644 --- a/internal/rosa/llvm.go +++ b/internal/rosa/llvm.go @@ -1,9 +1,11 @@ package rosa import ( + "io/fs" "regexp" "slices" "strings" + "unsafe" "hakurei.app/internal/pkg" ) @@ -48,6 +50,24 @@ func litArgs(verbose bool, skipChecks ...string) string { } func init() { + var llvmPatches []KV + for _, name := range [...]string{ + "increase-stack-size-unconditional", + "add-rosa-vendor", + "xfail-broken-tests", + "path-system-include", + "path-system-libraries", + } { + p, err := fs.ReadFile(nativeB, "package/llvm/"+name+".patch") + if err != nil { + panic(err) + } + llvmPatches = append(llvmPatches, KV{ + name, + unsafe.String(unsafe.SliceData(p), len(p)), + }) + } + native.MustRegister("early-compiler-rt", func(t Toolchain) (*Metadata, pkg.Artifact) { meta := Metadata{ Name: "early-compiler-rt", diff --git a/internal/rosa/package/llvm/add-rosa-vendor.patch b/internal/rosa/package/llvm/add-rosa-vendor.patch new file mode 100644 index 00000000..919403a3 --- /dev/null +++ b/internal/rosa/package/llvm/add-rosa-vendor.patch @@ -0,0 +1,32 @@ +diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h +index 9c83abeeb3b1..5acfe5836a23 100644 +--- a/llvm/include/llvm/TargetParser/Triple.h ++++ b/llvm/include/llvm/TargetParser/Triple.h +@@ -190,6 +190,7 @@ public: + + Apple, + PC, ++ Rosa, + SCEI, + Freescale, + IBM, +diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp +index a4f9dd42c0fe..cb5a12387034 100644 +--- a/llvm/lib/TargetParser/Triple.cpp ++++ b/llvm/lib/TargetParser/Triple.cpp +@@ -279,6 +279,7 @@ StringRef Triple::getVendorTypeName(VendorType Kind) { + case NVIDIA: return "nvidia"; + case OpenEmbedded: return "oe"; + case PC: return "pc"; ++ case Rosa: return "rosa"; + case SCEI: return "scei"; + case SUSE: return "suse"; + case Meta: +@@ -689,6 +690,7 @@ static Triple::VendorType parseVendor(StringRef VendorName) { + return StringSwitch(VendorName) + .Case("apple", Triple::Apple) + .Case("pc", Triple::PC) ++ .Case("rosa", Triple::Rosa) + .Case("scei", Triple::SCEI) + .Case("sie", Triple::SCEI) + .Case("fsl", Triple::Freescale) diff --git a/internal/rosa/package/llvm/increase-stack-size-unconditional.patch b/internal/rosa/package/llvm/increase-stack-size-unconditional.patch new file mode 100644 index 00000000..20ffe579 --- /dev/null +++ b/internal/rosa/package/llvm/increase-stack-size-unconditional.patch @@ -0,0 +1,13 @@ +diff --git a/llvm/lib/Support/Threading.cpp b/llvm/lib/Support/Threading.cpp +index 9da357a7ebb9..b2931510c1ae 100644 +--- a/llvm/lib/Support/Threading.cpp ++++ b/llvm/lib/Support/Threading.cpp +@@ -80,7 +80,7 @@ unsigned llvm::ThreadPoolStrategy::compute_thread_count() const { + // keyword. + #include "llvm/Support/thread.h" + +-#if defined(__APPLE__) ++#if defined(__APPLE__) || 1 + // Darwin's default stack size for threads except the main one is only 512KB, + // which is not enough for some/many normal LLVM compilations. This implements + // the same interface as std::thread but requests the same stack size as the diff --git a/internal/rosa/package/llvm/path-system-include.patch b/internal/rosa/package/llvm/path-system-include.patch new file mode 100644 index 00000000..c442d641 --- /dev/null +++ b/internal/rosa/package/llvm/path-system-include.patch @@ -0,0 +1,25 @@ +diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp +index 8ac8d4eb9181..e46b04a898ca 100644 +--- a/clang/lib/Driver/ToolChains/Linux.cpp ++++ b/clang/lib/Driver/ToolChains/Linux.cpp +@@ -671,6 +671,12 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, + addExternCSystemInclude( + DriverArgs, CC1Args, + concat(SysRoot, "/usr/include", MultiarchIncludeDir)); ++ if (!MultiarchIncludeDir.empty() && ++ D.getVFS().exists(concat(SysRoot, "/system/include", MultiarchIncludeDir))) ++ addExternCSystemInclude( ++ DriverArgs, CC1Args, ++ concat(SysRoot, "/system/include", MultiarchIncludeDir)); ++ + + if (getTriple().getOS() == llvm::Triple::RTEMS) + return; +@@ -681,6 +687,7 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, + addExternCSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/include")); + + addExternCSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/usr/include")); ++ addExternCSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/system/include")); + + if (!DriverArgs.hasArg(options::OPT_nobuiltininc) && getTriple().isMusl()) + addSystemInclude(DriverArgs, CC1Args, ResourceDirInclude); diff --git a/internal/rosa/llvm_patches.go b/internal/rosa/package/llvm/path-system-libraries.patch similarity index 50% rename from internal/rosa/llvm_patches.go rename to internal/rosa/package/llvm/path-system-libraries.patch index fc2c78f2..fbe46def 100644 --- a/internal/rosa/llvm_patches.go +++ b/internal/rosa/package/llvm/path-system-libraries.patch @@ -1,96 +1,4 @@ -package rosa - -// llvmPatches are centralised patches against latest LLVM monorepo. -var llvmPatches = []KV{ - {"increase-stack-size-unconditional", `diff --git a/llvm/lib/Support/Threading.cpp b/llvm/lib/Support/Threading.cpp -index 9da357a7ebb9..b2931510c1ae 100644 ---- a/llvm/lib/Support/Threading.cpp -+++ b/llvm/lib/Support/Threading.cpp -@@ -80,7 +80,7 @@ unsigned llvm::ThreadPoolStrategy::compute_thread_count() const { - // keyword. - #include "llvm/Support/thread.h" - --#if defined(__APPLE__) -+#if defined(__APPLE__) || 1 - // Darwin's default stack size for threads except the main one is only 512KB, - // which is not enough for some/many normal LLVM compilations. This implements - // the same interface as std::thread but requests the same stack size as the -`}, - - {"add-rosa-vendor", `diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h -index 9c83abeeb3b1..5acfe5836a23 100644 ---- a/llvm/include/llvm/TargetParser/Triple.h -+++ b/llvm/include/llvm/TargetParser/Triple.h -@@ -190,6 +190,7 @@ public: - - Apple, - PC, -+ Rosa, - SCEI, - Freescale, - IBM, -diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp -index a4f9dd42c0fe..cb5a12387034 100644 ---- a/llvm/lib/TargetParser/Triple.cpp -+++ b/llvm/lib/TargetParser/Triple.cpp -@@ -279,6 +279,7 @@ StringRef Triple::getVendorTypeName(VendorType Kind) { - case NVIDIA: return "nvidia"; - case OpenEmbedded: return "oe"; - case PC: return "pc"; -+ case Rosa: return "rosa"; - case SCEI: return "scei"; - case SUSE: return "suse"; - case Meta: -@@ -689,6 +690,7 @@ static Triple::VendorType parseVendor(StringRef VendorName) { - return StringSwitch(VendorName) - .Case("apple", Triple::Apple) - .Case("pc", Triple::PC) -+ .Case("rosa", Triple::Rosa) - .Case("scei", Triple::SCEI) - .Case("sie", Triple::SCEI) - .Case("fsl", Triple::Freescale) -`}, - - {"xfail-broken-tests", `diff --git a/clang/test/Modules/timestamps.c b/clang/test/Modules/timestamps.c -index 50fdce630255..4b4465a75617 100644 ---- a/clang/test/Modules/timestamps.c -+++ b/clang/test/Modules/timestamps.c -@@ -1,3 +1,5 @@ -+// XFAIL: target={{.*-rosa-linux-musl}} -+ - /// Verify timestamps that gets embedded in the module - #include - -`}, - - {"path-system-include", `diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp -index 8ac8d4eb9181..e46b04a898ca 100644 ---- a/clang/lib/Driver/ToolChains/Linux.cpp -+++ b/clang/lib/Driver/ToolChains/Linux.cpp -@@ -671,6 +671,12 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, - addExternCSystemInclude( - DriverArgs, CC1Args, - concat(SysRoot, "/usr/include", MultiarchIncludeDir)); -+ if (!MultiarchIncludeDir.empty() && -+ D.getVFS().exists(concat(SysRoot, "/system/include", MultiarchIncludeDir))) -+ addExternCSystemInclude( -+ DriverArgs, CC1Args, -+ concat(SysRoot, "/system/include", MultiarchIncludeDir)); -+ - - if (getTriple().getOS() == llvm::Triple::RTEMS) - return; -@@ -681,6 +687,7 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, - addExternCSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/include")); - - addExternCSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/usr/include")); -+ addExternCSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/system/include")); - - if (!DriverArgs.hasArg(options::OPT_nobuiltininc) && getTriple().isMusl()) - addSystemInclude(DriverArgs, CC1Args, ResourceDirInclude); -`}, - - {"path-system-libraries", `diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp +diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index cb6a9b242421..b8d31690d1af 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -178,5 +86,3 @@ index d525b417b4ea..2b93f401733e 100644 std::string ArchName; bool IsArm = false; -`}, -} diff --git a/internal/rosa/package/llvm/xfail-broken-tests.patch b/internal/rosa/package/llvm/xfail-broken-tests.patch new file mode 100644 index 00000000..0bc9af76 --- /dev/null +++ b/internal/rosa/package/llvm/xfail-broken-tests.patch @@ -0,0 +1,10 @@ +diff --git a/clang/test/Modules/timestamps.c b/clang/test/Modules/timestamps.c +index 50fdce630255..4b4465a75617 100644 +--- a/clang/test/Modules/timestamps.c ++++ b/clang/test/Modules/timestamps.c +@@ -1,3 +1,5 @@ ++// XFAIL: target={{.*-rosa-linux-musl}} ++ + /// Verify timestamps that gets embedded in the module + #include +