diff options
Diffstat (limited to 'internal/rosa/llvm.go')
| -rw-r--r-- | internal/rosa/llvm.go | 161 |
1 files changed, 84 insertions, 77 deletions
diff --git a/internal/rosa/llvm.go b/internal/rosa/llvm.go index 18db52a2..74d0cdc9 100644 --- a/internal/rosa/llvm.go +++ b/internal/rosa/llvm.go @@ -3,7 +3,6 @@ package rosa import ( "runtime" "slices" - "sync" "hakurei.app/internal/pkg" ) @@ -130,40 +129,26 @@ func init() { Name: "llvm-compiler-rt", Description: "LLVM runtime: compiler-rt", Website: "https://llvm.org/", - } -} - -// newLLVM returns LLVM toolchain across multiple [pkg.Artifact]. -func (t Toolchain) newLLVM() (runtimes, clang pkg.Artifact) { - target := "'AArch64;RISCV;X86'" - if t.isStage0() { - switch runtime.GOARCH { - case "386", "amd64": - target = "X86" - case "arm64": - target = "AArch64" - case "riscv64": - target = "RISCV" - default: - panic("unsupported target " + runtime.GOARCH) - } - } - - minimalDeps := []KV{ - {"LLVM_ENABLE_ZLIB", "OFF"}, - {"LLVM_ENABLE_ZSTD", "OFF"}, - {"LLVM_ENABLE_LIBXML2", "OFF"}, + Dependencies: P{ + Musl, + }, } +} - compilerRT := t.Load(LLVMCompilerRT) - musl := t.Load(Musl) - - runtimes = t.newLLVMVariant("runtimes", &llvmAttr{ - env: stage0ExclConcat(t, []string{}, +func (t Toolchain) newLLVMRuntimes() (pkg.Artifact, string) { + return t.NewPackage("llvm", llvmVersion, llvmSource, &PackageAttr{ + Patches: llvmPatches, + NonStage0: t.AppendPresets(nil, LLVMCompilerRT), + Env: stage0ExclConcat(t, []string{}, "LDFLAGS="+earlyLDFLAGS(false), ), - cmake: slices.Concat([]KV{ + Flag: TExclusive, + }, &CMakeHelper{ + Variant: "runtimes", + Append: []string{"runtimes"}, + + Cache: []KV{ {"CMAKE_BUILD_TYPE", "Release"}, {"LLVM_HOST_TRIPLE", `"${ROSA_TRIPLE}"`}, @@ -181,21 +166,61 @@ func (t Toolchain) newLLVM() (runtimes, clang pkg.Artifact) { {"LIBCXX_HAS_ATOMIC_LIB", "OFF"}, {"LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL", "OFF"}, - }, minimalDeps), - append: []string{"runtimes"}, - nonStage0: []pkg.Artifact{ - compilerRT, - musl, + + {"LLVM_ENABLE_ZLIB", "OFF"}, + {"LLVM_ENABLE_ZSTD", "OFF"}, + {"LLVM_ENABLE_LIBXML2", "OFF"}, }, - }) + }, + Python, + + KernelHeaders, + ), llvmVersion +} +func init() { + artifactsM[LLVMRuntimes] = Metadata{ + f: Toolchain.newLLVMRuntimes, - clang = t.newLLVMVariant("clang", &llvmAttr{ - env: stage0ExclConcat(t, []string{}, + Name: "llvm-runtimes", + Description: "LLVM runtimes: libunwind, libcxx, libcxxabi", + Website: "https://llvm.org/", + + Dependencies: P{ + LLVMCompilerRT, + }, + } +} + +func (t Toolchain) newLLVMClang() (pkg.Artifact, string) { + target := "'AArch64;RISCV;X86'" + if t.isStage0() { + switch runtime.GOARCH { + case "386", "amd64": + target = "X86" + case "arm64": + target = "AArch64" + case "riscv64": + target = "RISCV" + + default: + panic("unsupported target " + runtime.GOARCH) + } + } + + return t.NewPackage("llvm", llvmVersion, llvmSource, &PackageAttr{ + Patches: llvmPatches, + NonStage0: t.AppendPresets(nil, LLVMRuntimes), + Env: stage0ExclConcat(t, []string{}, "CFLAGS="+earlyCFLAGS, "CXXFLAGS="+earlyCXXFLAGS(), "LDFLAGS="+earlyLDFLAGS(false), ), - cmake: slices.Concat([]KV{ + Flag: TExclusive, + }, &CMakeHelper{ + Variant: "clang", + Append: []string{"llvm"}, + + Cache: []KV{ {"CMAKE_BUILD_TYPE", "Release"}, {"LLVM_HOST_TRIPLE", `"${ROSA_TRIPLE}"`}, @@ -218,13 +243,12 @@ func (t Toolchain) newLLVM() (runtimes, clang pkg.Artifact) { {"LLVM_TARGETS_TO_BUILD", target}, {"CMAKE_CROSSCOMPILING", "OFF"}, {"CXX_SUPPORTS_CUSTOM_LINKER", "ON"}, - }, minimalDeps), - nonStage0: []pkg.Artifact{ - musl, - compilerRT, - runtimes, + + {"LLVM_ENABLE_ZLIB", "OFF"}, + {"LLVM_ENABLE_ZSTD", "OFF"}, + {"LLVM_ENABLE_LIBXML2", "OFF"}, }, - script: ` + Script: ` ln -s ld.lld /work/system/bin/ld ln -s clang /work/system/bin/cc @@ -232,32 +256,30 @@ ln -s clang++ /work/system/bin/c++ ninja check-all `, - }) + }, + Python, + Perl, + Diffutils, + Bash, + Gawk, + Coreutils, + Findutils, - return + KernelHeaders, + ), llvmVersion } func init() { - artifactsM[LLVMRuntimes] = Metadata{ - f: func(t Toolchain) (pkg.Artifact, string) { - runtimes, _ := t.newLLVM() - return runtimes, llvmVersion - }, - - Name: "llvm-runtimes", - Description: "LLVM runtimes: libunwind, libcxx, libcxxabi", - Website: "https://llvm.org/", - } - artifactsM[LLVMClang] = Metadata{ - f: func(t Toolchain) (pkg.Artifact, string) { - _, clang := t.newLLVM() - return clang, llvmVersion - }, + f: Toolchain.newLLVMClang, Name: "clang", Description: `an "LLVM native" C/C++/Objective-C compiler`, Website: "https://llvm.org/", + Dependencies: P{ + LLVMRuntimes, + }, + ID: 1830, } @@ -282,18 +304,3 @@ func init() { Website: "https://libclc.llvm.org/", } } - -var ( - // llvm stores the result of Toolchain.newLLVM. - llvm [_toolchainEnd][2]pkg.Artifact - // llvmOnce is for lazy initialisation of llvm. - llvmOnce [_toolchainEnd]sync.Once -) - -// NewLLVM returns LLVM toolchain across multiple [pkg.Artifact]. -func (t Toolchain) NewLLVM() (runtimes, clang pkg.Artifact) { - llvmOnce[t].Do(func() { - llvm[t][0], llvm[t][1] = t.newLLVM() - }) - return llvm[t][0], llvm[t][1] -} |
