aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/rosa/state.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/rosa/state.go')
-rw-r--r--internal/rosa/state.go50
1 files changed, 45 insertions, 5 deletions
diff --git a/internal/rosa/state.go b/internal/rosa/state.go
index 6d198d6b..18f9a6f3 100644
--- a/internal/rosa/state.go
+++ b/internal/rosa/state.go
@@ -202,6 +202,9 @@ type S struct {
// For initialising arch.
archOnce sync.Once
+ // Native state for tool acquisition.
+ native *S
+
// Built-in functions.
frame azalea.Frame
// For initialising frame.
@@ -219,9 +222,37 @@ type S struct {
gentooStage3 pkg.Artifact
}
+// ErrInvalidCross is panicked by [S.NewCross] attempting to derive a
+// crosscompiling state for the native architecture.
+var ErrInvalidCross = errors.New("invalid cross-compilation state")
+
+// NewCross returns a copy of s for cross-compilation. Testing is disabled in
+// the copy.
+func (s *S) NewCross(arch string) *S {
+ if s.native != nil && arch == s.native.Arch() {
+ panic(ErrInvalidCross)
+ }
+
+ p := s.Clone()
+ p.opts |= OptSkipCheck
+ p.native, p.arch = s, arch
+ return p
+}
+
+// cross returns whether s is a cross-compilation state.
+func (s *S) cross() bool { return s.native != nil }
+
+// native returns the equivalent toolchain for compilation host.
+func (t Toolchain) native() Toolchain {
+ if t.S.native != nil {
+ t.S = t.S.native
+ }
+ return t
+}
+
// Clone returns a copy of s.
func (s *S) Clone() *S {
- v := S{arch: s.arch, opts: s.opts}
+ v := S{arch: s.arch, opts: s.opts, native: s.native}
s.p.Range(func(key, value any) bool {
v.p.Store(key, value)
v.len.Add(1)
@@ -479,6 +510,11 @@ func (s *S) getFrame() azalea.Frame {
identDefault := k("default")
identArch := unique.Make(azalea.Ident(s.arch))
+ native := runtime.GOARCH
+ if s.cross() {
+ native = s.native.arch
+ }
+
const compressOffset = 1 << 8
enumCompress := map[unique.Handle[azalea.Ident]]any{
k("uncompressed"): 0,
@@ -491,9 +527,9 @@ func (s *S) getFrame() azalea.Frame {
s.frame.Val = map[unique.Handle[azalea.Ident]]any{
k("unversioned"): Unversioned,
- k("hostTriple"): triple(runtime.GOARCH),
- k("hostArch"): runtime.GOARCH,
- k("hostLinuxArch"): linuxArch(runtime.GOARCH),
+ k("hostTriple"): triple(native),
+ k("hostArch"): native,
+ k("hostLinuxArch"): linuxArch(native),
k("triple"): s.triple(),
k("arch"): s.arch,
@@ -820,6 +856,7 @@ func (s *S) getFrame() azalea.Frame {
chdir := true
if err = args.Apply(map[unique.Handle[azalea.Ident]]any{
k("chdir"): &chdir,
+ k("cross"): &attr.Cross,
k("build"): &attr.Build,
k("check"): &attr.Check,
k("install"): &attr.Install,
@@ -1063,7 +1100,7 @@ func (ctx *evalContext) pf(
overlay string
join bool
- tools, inputs, extra azalea.Array
+ tools, inputs, cross, extra azalea.Array
runtimes = azalea.Array{}
bootstrap = true
@@ -1096,6 +1133,7 @@ func (ctx *evalContext) pf(
k("source"): &source,
k("exec"): &helper,
k("inputs"): &inputs,
+ k("cross"): &cross,
k("tools"): &tools,
k("runtime"): &runtimes,
k("join"): &join,
@@ -1109,6 +1147,8 @@ func (ctx *evalContext) pf(
var inputsH, extraH P
if inputsH, err = toHandles(inputs); err != nil {
return
+ } else if attr.Cross, err = toHandles(cross); err != nil {
+ return
} else if attr.Tools, err = toHandles(tools); err != nil {
return
} else if extraH, err = toHandles(extra); err != nil {