forked from Mirror/pmbootstrap
build: add pmb:cross-native2 (MR 2474)
Set things up so that we can run abuild on the native chroot and use it's cross compilation features rather than running it and the build system through QEMU. This massively speeds up building when it works. cross-native used to be quite limited in functionality and didn't integrate into abuild itself, this commit fixes that. Packages can opt-in to this by adding pmb:cross-native2 to their options and configuring makedepends_host and makedepends_build. This also speeds up building packages like postmarketos-initramfs since it entirely avoids running commands through QEMU (usually abuild itself would be run through QEMU). Lastly, we preserve the old pmb:cross-kernel options, this can be used to enable the old cross compiler behaviour which is used for cross compiling kernels in pmaports. This allows them to keep being supporting while we adapt them to the new cross-native2. Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
parent
5a00964943
commit
2ee916f5d6
5 changed files with 106 additions and 35 deletions
|
@ -193,7 +193,7 @@ def run_abuild(
|
|||
strict: bool = False,
|
||||
force: bool = False,
|
||||
cross: CrossCompileType = None,
|
||||
suffix: Chroot = Chroot.native(),
|
||||
hostchroot: Chroot = Chroot.native(),
|
||||
src: str | None = None,
|
||||
bootstrap_stage: int = BootstrapStage.NONE,
|
||||
) -> None:
|
||||
|
@ -217,6 +217,14 @@ def run_abuild(
|
|||
" cross-compiling in the native chroot. This will"
|
||||
" probably fail!"
|
||||
)
|
||||
|
||||
# For cross-native2 compilation, bindmount the "host" rootfs to /mnt/sysroot
|
||||
# it will be used as the "sysroot"
|
||||
if cross == "native":
|
||||
pmb.mount.bind(hostchroot.path, Chroot.native() / "/mnt/sysroot", umount=True)
|
||||
|
||||
chroot = Chroot.native() if cross == "native" else hostchroot
|
||||
|
||||
pkgdir = context.config.work / "packages" / channel
|
||||
if not pkgdir.exists():
|
||||
pmb.helpers.run.root(["mkdir", "-p", pkgdir])
|
||||
|
@ -235,17 +243,28 @@ def run_abuild(
|
|||
["rm", "-f", "/home/pmos/packages/pmos"],
|
||||
["ln", "-sf", f"/mnt/pmbootstrap/packages/{channel}", "/home/pmos/packages/pmos"],
|
||||
],
|
||||
suffix,
|
||||
chroot,
|
||||
)
|
||||
|
||||
# Environment variables
|
||||
env: Env = {"CARCH": str(arch), "SUDO_APK": "abuild-apk --no-progress"}
|
||||
if cross == "native":
|
||||
env: Env = {"SUDO_APK": "abuild-apk --no-progress"}
|
||||
if cross == "kernel":
|
||||
hostspec = arch.alpine_triple()
|
||||
env["CROSS_COMPILE"] = hostspec + "-"
|
||||
env["CC"] = hostspec + "-gcc"
|
||||
if cross == "crossdirect":
|
||||
if cross == "native":
|
||||
env["CHOST"] = str(arch)
|
||||
env["CBUILDROOT"] = "/mnt/sysroot"
|
||||
env["CFLAGS"] = "-Wl,-rpath-link=/mnt/sysroot/usr/lib"
|
||||
try:
|
||||
env["GOARCH"] = arch.go()
|
||||
except ValueError:
|
||||
logging.debug(f"Not setting $GOARCH for {arch}")
|
||||
|
||||
elif cross == "crossdirect":
|
||||
env["PATH"] = ":".join([f"/native/usr/lib/crossdirect/{arch}", pmb.config.chroot_path])
|
||||
else:
|
||||
env["CARCH"] = str(arch)
|
||||
if not context.ccache:
|
||||
env["CCACHE_DISABLE"] = "1"
|
||||
|
||||
|
@ -269,15 +288,10 @@ def run_abuild(
|
|||
env["BOOTSTRAP"] = str(bootstrap_stage)
|
||||
|
||||
# Build the abuild command
|
||||
cmd = ["abuild", "-D", "postmarketOS"]
|
||||
if strict or "pmb:strict" in apkbuild["options"]:
|
||||
if not strict:
|
||||
logging.debug(
|
||||
apkbuild["pkgname"] + ": 'pmb:strict' found in options, building in strict mode"
|
||||
)
|
||||
cmd += ["-r"] # install depends with abuild
|
||||
else:
|
||||
cmd += ["-d"] # do not install depends with abuild
|
||||
# Since we install dependencies with pmb, disable dependency handling in abuild.
|
||||
# This is also required so that abuild doesn't try to install base-build-$ARCH packages
|
||||
# which don't exist
|
||||
cmd = ["abuild", "-d", "-D", "postmarketOS"]
|
||||
if force:
|
||||
cmd += ["-f"]
|
||||
if src:
|
||||
|
@ -286,14 +300,16 @@ def run_abuild(
|
|||
cmd += ["-K"]
|
||||
|
||||
# Copy the aport to the chroot and build it
|
||||
pmb.build.copy_to_buildpath(apkbuild["pkgname"], suffix, no_override=strict)
|
||||
pmb.build.copy_to_buildpath(apkbuild["pkgname"], chroot, no_override=strict)
|
||||
if src and strict:
|
||||
logging.debug(f"({suffix}) Ensuring previous build artifacts are removed")
|
||||
pmb.chroot.root(["rm", "-rf", "/tmp/pmbootstrap-local-source-copy"], suffix)
|
||||
override_source(apkbuild, pkgver, src, suffix)
|
||||
link_to_git_dir(suffix)
|
||||
logging.debug(f"({chroot}) Ensuring previous build artifacts are removed")
|
||||
pmb.chroot.root(["rm", "-rf", "/tmp/pmbootstrap-local-source-copy"], chroot)
|
||||
override_source(apkbuild, pkgver, src, chroot)
|
||||
link_to_git_dir(chroot)
|
||||
|
||||
try:
|
||||
pmb.chroot.user(cmd, suffix, Path("/home/pmos/build"), env=env)
|
||||
pmb.chroot.user(cmd, chroot, Path("/home/pmos/build"), env=env)
|
||||
finally:
|
||||
handle_csum_failure(apkbuild, suffix)
|
||||
handle_csum_failure(apkbuild, chroot)
|
||||
|
||||
pmb.helpers.run.root(["umount", Chroot.native() / "/mnt/sysroot"], output="null", check=False)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue