Makepkg-optimize

From ArchWiki
Revision as of 18:52, 1 September 2018 by Quequotion (talk | contribs) (work in progress)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

makepkg-optimizeAUR is a collection of supplemental build_env and tidy scripts for pacman-build_env-ext-gitAUR. Their purpose is to provide macros to makepkg for several kinds of optimization in build and packaging stages.

Installation

Install pacman-build_env-ext-gitAUR and makepkg-optimizeAUR from the AUR. makepkg-optimizeAUR generates an additional configuration file, /etc/makepkg-optimize.conf, from /etc/makepkg.conf, with additions for the supplementary macros and other optimizations.

Note: pacman-build_env-ext-gitAUR does nothing differently from pacman-gitAUR without makepkg-optimizeAUR. In addition, makepkg will build standard packages unless the configuration file generated by makepkg-optimizeAUR has been specified.

Build an optimized package

Edit /etc/makepkg-optimize.conf. Select your preferred optimizations for BUILD ENVIRONMENT, GLOBAL PACKAGE OPTIONS and COMPRESSION DEFAULTS. Call makepkg with this configuration file in a directory containing a PKGBUILD:

$ makepkg --config /etc/makepkg-optimize.conf

Build an optimized package in a clean chroot

Note: It is highly recommended that you read Building in a Clean Chroot before attempting this. It is important to understand that clean chroot building is considered the only supported method of building a package from source, and that it is a complicated procedure to begin with.

Prep work

Install the "devtools" package:

# pacman -S devtools

Configure /etc/pacman.conf and /etc/makepkg.conf

= First time only: Chroot Setup

Create a folder for "clean" chroot building and assign it to CHROOT:

$ mkdir ~/path/to/buildchroot && CHROOT=~/path/to/buildchroot
$ printf "export CHROOT=~/path/to/buildchroot" >> ~/.bashrc

Transfer your pacman.conf and makepkg.conf; install some basics (graphite, openmp, upx, and optipng are optional).

# mkarchroot -C /etc/pacman.conf -M /etc/makepkg.conf "$CHROOT"/root base-devel graphite openmp upx optipng

Build pikaur locally*, then copy the package into the chroot (to root's home directory)

  1. pacman -S --needed base-devel git

$ git clone https://aur.archlinux.org/pikaur.git $ cd pikaur $ makepkg -fsri

  1. cp pikaur-1.2.23-1-any.pkg.tar.xz $CHROOT/root/root/

Install pikaur in the chroot:

  1. systemd-nspawn -D "$CHROOT"/root pacman -U /root/pikaur-1.2.23-1-any.pkg.tar.xz

AUR helper needs an unprivileged user:

  1. systemd-nspawn -D "$CHROOT"/root useradd "$USER"
  2. systemd-nspawn -D "$CHROOT"/root passwd "$USER"

Set up sudo for that user**:

  1. echo "$USER ALL=(root) NOPASSWD: /usr/bin/pacman" >> "$CHROOT"/root/etc/sudoers"

Install AUR packages (nodejs-svgo is optional): $ arch-nspawn -M /etc/makepkg.conf "$CHROOT"/root -u $USER pikaur -S nodejs-svgo pacman-buildenv_ext-git makepkg-optimize Create a location that will exist on both sides to store profiles:

  1. mkdir -m 777 {"$CHROOT"/root,}/mnt/pgo

Edit $CHROOT/root/etc/makepkg-optimize.conf: Set PROFDEST=/mnt/pgo under "PACKAGE OUTPUT".

Using the chroot: Keep your chroot up-to-date: $ arch-nspawn -M /etc/makepkg.conf "$CHROOT"/root -u $USER pikaur -Syua Edit $CHROOT/root/etc/makepkg-optimize.conf: Select your preferred optimizations under "BUILD ENVIRONMENT" (pgo, lto, graphite) and "GLOBAL PACKAGE OPTIONS" (upx, optipng, svgo). Build the package (in the directory containing its PKGBUILD): $ makechrootpkg -c -r "$CHROOT" -- --config /etc/makepkg-optimize.conf

If you are building a package with PGO: Bind the pgo folder across the chroot:***

  1. mount -o bind {,"$CHROOT"/"$USER"}/mnt/pgo

Install the package and test-run its executables; try to use every function! Remove cruft and rebuild the package, but do not clean the chroot (in the directory containing its PKGBUILD): $ rm -rf *.pkg.tar.xz pkg src; makechrootpkg -r "$CHROOT" -- --config /etc/makepkg-optimize.conf