diff options
| author | Ophestra <cat@gensokyo.uk> | 2026-11-11 21:59:18 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2026-11-12 12:44:39 +0900 |
| commit | ac4cec1625da50d6abd9fca40446e7f75aa5bd37 (patch) | |
| tree | 22b3789634008a43277952abea766be4f278e4f7 | |
| parent | e28bac0fe480c065e653b847d1b54f3e3d712156 (diff) | |
internal/rosa: set common cross-compile environment
This change avoids duplicating this piece of code all over the place.
Signed-off-by: Ophestra <cat@gensokyo.uk>
| -rw-r--r-- | internal/rosa/doc.go | 11 | ||||
| -rw-r--r-- | internal/rosa/make.go | 16 | ||||
| -rw-r--r-- | internal/rosa/package/hakurei.az | 21 | ||||
| -rw-r--r-- | internal/rosa/rosa.go | 14 | ||||
| -rw-r--r-- | internal/rosa/state.go | 3 |
5 files changed, 27 insertions, 38 deletions
diff --git a/internal/rosa/doc.go b/internal/rosa/doc.go index 9c61a751..313d4f17 100644 --- a/internal/rosa/doc.go +++ b/internal/rosa/doc.go @@ -163,16 +163,15 @@ declared at the top level: // whether to replace /usr/bin/ with a symlink to /bin/ populateUsrBin = false; + // whether to set common cross-compilation environment variables + ccommon = true; + // build system helper, see section "Build system helpers" exec = generic { chdir = false; cross = ` export HAKUREI_ARCH='`+arch+`' export HAKUREI_SYSROOT='`+prefix+`/`+arch+`' - - export PKG_CONFIG_SYSROOT_DIR='`+prefix+`/`+arch+`' - export PKG_CONFIG_LIBDIR='`+prefix+`/`+arch+prefix+`/lib/pkgconfig:`+ - prefix+`/`+arch+``+prefix+`/share/pkgconfig' `; build = ` NAME=make`; @@ -399,10 +398,6 @@ scripts too specific to fit into any other [Helper] implementation. cross = ` export HAKUREI_ARCH='`+arch+`' export HAKUREI_SYSROOT='`+prefix+`/`+arch+`' - - export PKG_CONFIG_SYSROOT_DIR='`+prefix+`/`+arch+`' - export PKG_CONFIG_LIBDIR='`+prefix+`/`+arch+prefix+`/lib/pkgconfig:`+ - prefix+`/`+arch+``+prefix+`/share/pkgconfig' `; // runs first, or after cross if cross-compiling diff --git a/internal/rosa/make.go b/internal/rosa/make.go index 6f3d7526..8672dac8 100644 --- a/internal/rosa/make.go +++ b/internal/rosa/make.go @@ -120,19 +120,7 @@ func (attr *MakeHelper) script(t Toolchain, name string) string { attr = new(MakeHelper) } cross, arch := t.cross(), t.Arch() - sysroot := Prefix + "/" + arch - - var configure string - target := t.triple() - if cross { - configure += ` -export CC='clang --target=` + target + ` --sysroot=` + sysroot + `' -export CXX='clang++ --target=` + target + ` --sysroot=` + sysroot + `' -export PKG_CONFIG_SYSROOT_DIR='` + sysroot + `' -export PKG_CONFIG_LIBDIR='` + sysroot + Prefix + `/lib/pkgconfig:` + sysroot + Prefix + `/share/pkgconfig' -` - } - configure += attr.ScriptConfigureEarly + configure := attr.ScriptConfigureEarly if !attr.SkipConfigure { if attr.ConfigureName == "" { @@ -143,7 +131,7 @@ export PKG_CONFIG_LIBDIR='` + sysroot + Prefix + `/lib/pkgconfig:` + sysroot + P if attr.ForceAutoconf || attr.ConfigureName == "" { configure += ` \ --prefix=` + Prefix - host := target + host := t.triple() build := host if cross { build = triple(t.native().Arch()) diff --git a/internal/rosa/package/hakurei.az b/internal/rosa/package/hakurei.az index 8041d380..7e71ae72 100644 --- a/internal/rosa/package/hakurei.az +++ b/internal/rosa/package/hakurei.az @@ -19,6 +19,7 @@ package hakurei { enterSource = true; writable = true; chmod = true; + ccommon = true; env = [ "CGO_ENABLED=1", @@ -28,12 +29,7 @@ package hakurei { exec = generic { chdir = false; - cross = ` -export CC='clang --target=`+triple+` --sysroot=`+prefix+`/`+arch+`' -export CXX='clang++ --target=`+triple+` --sysroot=`+prefix+`/`+arch+`' -export PKG_CONFIG_SYSROOT_DIR='`+prefix+`/`+arch+`' -export PKG_CONFIG_LIBDIR='`+prefix+`/`+arch+prefix+`/lib/pkgconfig:`+prefix+`/`+arch+prefix+`/share/pkgconfig' -`; + cross = "\x00"; build = ` mkdir -p /work`+prefix+`/bin/ @@ -57,8 +53,7 @@ GOARCH='`+arch+`' CGO_ENABLED=0 go build -trimpath -tags=rosa -o /work`+prefix+` default = ` echo echo '##### Testing hakurei.' -go test -ldflags='-buildid= -linkmode external -extldflags=-static' ./... -echo`; +go test -ldflags='-buildid= -linkmode external -extldflags=-static' ./...`; cross = unset; }; install = ` @@ -97,6 +92,7 @@ package hakurei-dist { enterSource = true; writable = true; chmod = true; + ccommon = true; env = [ "CGO_ENABLED=1", @@ -107,11 +103,9 @@ package hakurei-dist { exec = generic { chdir = false; cross = ` +unset CC CXX export HAKUREI_ARCH='`+arch+`' export HAKUREI_SYSROOT='`+prefix+`/`+arch+`' - -export PKG_CONFIG_SYSROOT_DIR='`+prefix+`/`+arch+`' -export PKG_CONFIG_LIBDIR='`+prefix+`/`+arch+prefix+`/lib/pkgconfig:`+prefix+`/`+arch+``+prefix+`/share/pkgconfig' `; build = ` NAME=make`; @@ -201,6 +195,7 @@ package earlyinit { enterSource = true; writable = true; chmod = true; + ccommon = true; env = [ "CGO_ENABLED=1", @@ -212,10 +207,6 @@ package earlyinit { chdir = false; cross = ` export GOARCH='`+arch+`' -export CC='clang --target=`+triple+` --sysroot=`+prefix+`/`+arch+`' -export CXX='clang++ --target=`+triple+` --sysroot=`+prefix+`/`+arch+`' -export PKG_CONFIG_SYSROOT_DIR='`+prefix+`/`+arch+`' -export PKG_CONFIG_LIBDIR='`+prefix+`/`+arch+prefix+`/lib/pkgconfig:`+prefix+`/`+arch+prefix+`/share/pkgconfig' `; build = ` go build -trimpath -o /work/ -ldflags="-s -w diff --git a/internal/rosa/rosa.go b/internal/rosa/rosa.go index c50a7efe..845919bf 100644 --- a/internal/rosa/rosa.go +++ b/internal/rosa/rosa.go @@ -377,6 +377,8 @@ type PackageAttr struct { CrossTools P // Native utilities used by the build process. Tools P + // Whether to set common cross-compilation environment variables. + CrossCommon bool // Unregistered extras. Extra []pkg.Artifact // Passed through to [Toolchain.New], before source. @@ -654,6 +656,18 @@ ln -s ../bin /usr/` } arch := t.Arch() + if _, ok := helper.(*MakeHelper); cross && (attr.CrossCommon || ok) { + sysroot := Prefix + "/" + arch + target := t.triple() + scriptEarly += ` +export \ + CC='clang --target=` + target + ` --sysroot=` + sysroot + `' \ + CXX='clang++ --target=` + target + ` --sysroot=` + sysroot + `' \ + PKG_CONFIG_SYSROOT_DIR='` + sysroot + `' \ + PKG_CONFIG_LIBDIR='` + sysroot + Prefix + `/lib/pkgconfig:` + sysroot + Prefix + `/share/pkgconfig' +` + } + sys := []pkg.ExecPath{pkg.Path( fhs.AbsRoot, true, root..., diff --git a/internal/rosa/state.go b/internal/rosa/state.go index f8cffce7..9d13cab2 100644 --- a/internal/rosa/state.go +++ b/internal/rosa/state.go @@ -134,7 +134,7 @@ func (UnpopulatedIDError) Error() string { return "Anitya ID is not populated" } type Versions struct { // The latest version for the project, as determined by the version sorting algorithm. Latest string `json:"latest_version"` - // List of all versions that aren’t flagged as pre-release. + // List of all versions that aren't flagged as pre-release. Stable []string `json:"stable_versions"` // List of all versions stored, sorted from newest to oldest. All []string `json:"versions"` @@ -1157,6 +1157,7 @@ func (ctx *evalContext) pf( k("cross"): &cross, k("native"): &native, k("tools"): &tools, + k("ccommon"): &attr.CrossCommon, k("runtime"): &runtimes, k("join"): &join, k("unlikely"): &meta.Unlikely, |
