aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-01-19 00:44:16 +0900
committerOphestra <cat@gensokyo.uk>2026-01-19 00:51:49 +0900
commitd258dea0bf999f9123c891b7a35e3e74f5dc7bd8 (patch)
tree6fb0d06e5607acd0252b668fd4d536950cc8eeaa /internal
parentdc963021114a4e2ffa874d4838382a1ad67a4f53 (diff)
internal/rosa: bootstrap on gentoo stage3
This contains a fully working musl+llvm toolchain and many build systems in a pretty small package. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal')
-rw-r--r--internal/rosa/rosa.go84
1 files changed, 84 insertions, 0 deletions
diff --git a/internal/rosa/rosa.go b/internal/rosa/rosa.go
index d7a61059..ebad8101 100644
--- a/internal/rosa/rosa.go
+++ b/internal/rosa/rosa.go
@@ -55,6 +55,51 @@ func linuxArch() string {
}
}
+// triplet returns the Rosa OS host triple corresponding to [runtime.GOARCH].
+func triplet() string {
+ return linuxArch() + "-rosa-linux-musl"
+}
+
+const (
+ // EnvTriplet holds the return value of triplet.
+ EnvTriplet = "ROSA_TRIPLE"
+ // EnvRefCFLAGS holds toolchain-specific reference CFLAGS.
+ EnvRefCFLAGS = "ROSA_CFLAGS"
+ // EnvRefCXXFLAGS holds toolchain-specific reference CXXFLAGS.
+ EnvRefCXXFLAGS = "ROSA_CXXFLAGS"
+)
+
+// ldflags returns LDFLAGS corresponding to triplet.
+func ldflags(static bool) string {
+ s := "LDFLAGS=" +
+ "-fuse-ld=lld " +
+ "-L/system/lib -Wl,-rpath=/system/lib " +
+ "-L/system/lib/" + triplet() + " " +
+ "-Wl,-rpath=/system/lib/" + triplet() + " " +
+ "-rtlib=compiler-rt " +
+ "-unwindlib=libunwind " +
+ "-Wl,--as-needed"
+ if !static {
+ s += " -Wl,--dynamic-linker=/system/lib/ld-musl-x86_64.so.1"
+ }
+ return s
+}
+
+// cflags is reference CFLAGS for the Rosa OS toolchain.
+const cflags = "-Qunused-arguments " +
+ "-isystem/system/include"
+
+// cxxflags returns reference CXXFLAGS for the Rosa OS toolchain corresponding
+// to [runtime.GOARCH].
+func cxxflags() string {
+ return "--start-no-unused-arguments " +
+ "-stdlib=libc++ " +
+ "--end-no-unused-arguments " +
+ "-isystem/system/include/c++/v1 " +
+ "-isystem/system/include/" + triplet() + "/c++/v1 " +
+ "-isystem/system/include "
+}
+
// Toolchain denotes the infrastructure to compile a [pkg.Artifact] on.
type Toolchain uintptr
@@ -62,6 +107,10 @@ const (
// toolchainBusybox denotes a busybox installation from the busyboxBin
// binary distribution. This is for decompressing unsupported formats.
toolchainBusybox Toolchain = iota
+
+ // toolchainStage3 denotes the Gentoo stage3 toolchain. Special care must be
+ // taken to compile correctly against this toolchain.
+ toolchainStage3
)
// lastIndexFunc is like [strings.LastIndexFunc] but for [slices].
@@ -109,6 +158,8 @@ func (t Toolchain) New(
paths ...pkg.ExecPath,
) pkg.Artifact {
+ const lcMessages = "LC_MESSAGES=C.UTF-8"
+
var (
path = AbsSystem.Append("bin", "busybox")
args = []string{"hush", absCureScript.String()}
@@ -119,6 +170,39 @@ func (t Toolchain) New(
support = slices.Concat([]pkg.Artifact{newBusyboxBin()}, extra)
env = fixupEnviron(env, nil, "/system/bin")
+ case toolchainStage3:
+ const (
+ version = "20260111T160052Z"
+ checksum = "c5_FwMnRN8RZpTdBLGYkL4RR8ampdaZN2JbkgrFLe8-QHQAVQy08APVvIL6eT7KW"
+ )
+ path = fhs.AbsRoot.Append("bin", "bash")
+ args[0] = "bash"
+ support = slices.Concat([]pkg.Artifact{
+ cureEtc{},
+ toolchainBusybox.New("stage3-"+version, nil, nil, nil, `
+tar -C /work -xf /usr/src/stage3.tar.xz
+rm -rf /work/dev/ /work/proc/
+ln -vs ../usr/bin /work/bin
+`, pkg.Path(AbsUsrSrc.Append("stage3.tar.xz"), false,
+ pkg.NewHTTPGet(
+ nil, "https://distfiles.gentoo.org/releases/"+
+ runtime.GOARCH+"/autobuilds/"+version+
+ "/stage3-"+runtime.GOARCH+"-musl-llvm-"+version+".tar.xz",
+ mustDecode(checksum),
+ ),
+ )),
+ }, extra)
+ env = fixupEnviron(env, []string{
+ EnvTriplet + "=" + triplet(),
+ lcMessages,
+
+ EnvRefCFLAGS + "=" + cflags,
+ EnvRefCXXFLAGS + "=" + cxxflags(),
+ ldflags(true),
+ }, "/system/bin",
+ "/usr/bin",
+ "/usr/lib/llvm/21/bin",
+ )
default:
panic("unsupported toolchain " + strconv.Itoa(int(t)))
}