joeylib2/installer/components/haikuGcc.sh
2026-10-13 14:01:46 -05:00

78 lines
3.3 KiB
Bash

# Part of JoeyLib, Copyright (c) 2026 Scott Duensing, under the MIT License.
# See LICENSE.md for license information.
# SPDX-License-Identifier: MIT
#
# The Haiku x86_64 cross compiler (make haiku): gcc 13.3.0 and binutils for
# x86_64-unknown-haiku, Linux-hosted, as Haiku's own CI builds them from its
# buildtools (the toolchain layer of Haiku's published cross-compiler image,
# ghcr.io/haiku/cross-compiler:x86_64-r1beta5, pinned by its digest; the
# compiler is the same 13.3.0 2023_08_10 that R1/beta6 ships). Its sysroot
# is R1/beta6's: the system libraries out of the release image, haiku_devel
# from the release's repository and the compiler's runtime from HaikuPorts.
# Into toolchains/opt/haikuGcc: cross/ (the compiler) and sysroot/.
compDescription="haiku: gcc 13.3 cross compiler + R1/beta6 sysroot (Haiku x86_64)"
compGroups="toolchain:haiku"
compRequires="haikuTools"
compHostDeps="curl tar python3"
ociRepository="haiku/cross-compiler"
ociToolchainLayer="f6c3231b856d16aac56bf2ffe89a93c315a7bf03e6f62de3859ec2d899d5e815"
haikuArch="x86_64"
systemPackages="haiku-r1~beta6_hrev59866_79-1-x86_64.hpkg gcc_syslibs-13.3.0_2023_08_10-6-x86_64.hpkg"
develPackage="haiku_devel-r1~beta6_hrev59866_79-1-x86_64.hpkg"
develSha256="22fca2d887d394edf6f2af38b8a59d68fc693f41c759cad30576d2b48018a14f"
runtimeDevelPackage="gcc_syslibs_devel-13.3.0_2023_08_10-6-x86_64.hpkg"
runtimeDevelSha256="3db3465b7e390eb7f559690a83fa9244683582ba91322bc186d9b6f4d518ed2d"
compPin="$ociToolchainLayer:$develSha256:$runtimeDevelSha256"
# shellcheck source=installer/lib/haiku.sh
source "$JOEY_INSTALLER/lib/haiku.sh"
compInstall() {
local layer
local src
local package
local packages=()
layer="$(fetchOciBlob "$ociRepository" "$ociToolchainLayer" "haiku-cross-x86_64-r1beta5.tar.gz")"
src="$(freshBuildDir "$compId")"
tar -xzf "$layer" -C "$src" tools/cross-tools-x86_64
for package in $systemPackages; do
haikuIsoPackage "$haikuArch" "$package" "$src/$package"
packages+=("$src/$package")
done
packages+=("$(haikuRepoPackage "$HAIKU_REPO_BASE" "$haikuArch" "$HAIKU_REVISION" "$develPackage" "$develSha256")")
packages+=("$(haikuRepoPackage "$HAIKU_PORTS_BASE" "$haikuArch" current "$runtimeDevelPackage" "$runtimeDevelSha256")")
rm -rf "$compDir"
mkdir -p "$compDir"
mv "$src/tools/cross-tools-x86_64" "$compDir/cross"
# The image's own sysroot is an empty one from its build.
rm -rf "$compDir/cross/sysroot"
haikuSysroot "$compDir/sysroot" "${packages[@]}"
dropBuildDir "$compId"
}
compInstalled() {
[ -x "$compDir/cross/bin/x86_64-unknown-haiku-g++" ] && [ -e "$compDir/sysroot/boot/system/develop/lib/libbe.so" ]
}
# Link a C++ program against the Be API (libbe.so) as make/haiku.mk does.
compVerify() {
local tmp
local status=1
tmp="$(mktemp -d)"
printf '#include <Application.h>\nint main(void) { BApplication app("application/x-vnd.JoeyLib-check"); return app.InitCheck() == B_OK ? 0 : 1; }\n' > "$tmp/t.cpp"
if "$compDir/cross/bin/x86_64-unknown-haiku-g++" --sysroot="$compDir/sysroot" "$tmp/t.cpp" -o "$tmp/t" -lbe && [ -s "$tmp/t" ]; then
status=0
fi
rm -rf "$tmp"
return $status
}
compEnv() {
envVar HAIKU_CROSS "$compDir/cross/bin/x86_64-unknown-haiku-"
envVar HAIKU_SYSROOT "$compDir/sysroot"
}