Difference between revisions of "Makepkg-optimize"

From ArchWiki
Jump to: navigation, search
(drop Category:DeveloperWiki, the article does not appear to fit)
m (Configuration: Attempt to make warning more clear.)
 
Line 20: Line 20:
 
{{AUR|makepkg-optimize}} generates an additional [https://jlk.fjfi.cvut.cz/arch/manpages/man/makepkg.conf.5 configuration file], {{ic|/etc/makepkg-optimize.conf}}, from your current [[makepkg]] configuration with supplementary options for  [[Makepkg#Building optimized binaries|COMPILE FLAGS]], [https://aur.archlinux.org/cgit/aur.git/tree/buildenv_ext.conf?h=makepkg-optimize BUILD ENVIRONMENT], [https://aur.archlinux.org/cgit/aur.git/tree/pkgopts_ext.conf?h=makepkg-optimize GLOBAL PACKAGE OPTIONS], [https://aur.archlinux.org/cgit/aur.git/tree/destdirs_ext.conf?h=makepkg-optimize PACKAGE OUTPUT], and [https://aur.archlinux.org/cgit/aur.git/tree/compress-param_max.conf?h=makepkg-optimize COMPRESSION DEFAULTS] that are disabled by default.
 
{{AUR|makepkg-optimize}} generates an additional [https://jlk.fjfi.cvut.cz/arch/manpages/man/makepkg.conf.5 configuration file], {{ic|/etc/makepkg-optimize.conf}}, from your current [[makepkg]] configuration with supplementary options for  [[Makepkg#Building optimized binaries|COMPILE FLAGS]], [https://aur.archlinux.org/cgit/aur.git/tree/buildenv_ext.conf?h=makepkg-optimize BUILD ENVIRONMENT], [https://aur.archlinux.org/cgit/aur.git/tree/pkgopts_ext.conf?h=makepkg-optimize GLOBAL PACKAGE OPTIONS], [https://aur.archlinux.org/cgit/aur.git/tree/destdirs_ext.conf?h=makepkg-optimize PACKAGE OUTPUT], and [https://aur.archlinux.org/cgit/aur.git/tree/compress-param_max.conf?h=makepkg-optimize COMPRESSION DEFAULTS] that are disabled by default.
  
{{Warning|Some packages may fail to build with certain optimizations and some software may experience runtime problems caused by over-optimization--even decreased performance.}}
+
{{Warning|Some packages may fail to build with certain optimizations and over-optimization may cause problems for some programs--such as decreased performance and segmentation faults.}}
  
 
== Build an optimized package ==
 
== Build an optimized package ==

Latest revision as of 17:45, 10 November 2018

makepkg-optimizeAUR is a collection of supplemental build_env and tidy scripts for pacman-buildenv_ext-gitAUR. They provide macros to makepkg for several kinds of optimization in build() and package() stages, both in response to the simplification of makepkg and as a proposal for a future version of pacman.

Warning: Arch Linux only has official support for pacman from core. When using an alternate version, please mention so in support requests.

Installation

Install pacman-buildenv_ext-gitAUR and makepkg-optimizeAUR from the AUR.

To make optimizations available, install their backends: graphite, openmp, upx, optipng, and nodejs-svgoAUR

Configuration

makepkg-optimizeAUR generates an additional configuration file, /etc/makepkg-optimize.conf, from your current makepkg configuration with supplementary options for COMPILE FLAGS, BUILD ENVIRONMENT, GLOBAL PACKAGE OPTIONS, PACKAGE OUTPUT, and COMPRESSION DEFAULTS that are disabled by default.

Warning: Some packages may fail to build with certain optimizations and over-optimization may cause problems for some programs--such as decreased performance and segmentation faults.

Build an optimized package

First, edit the configuration file and select your preferred optimizations.

When building, pass the configuration file:

$ makepkg --config /etc/makepkg-optimize.conf
Note: Profile-guided optimization requires that a package be built and installed twice. The first phase initiates profile generation in $PROFDEST/$pkgbase.gen; the second applies them and moves them to $PROFDEST/$pkgbase.used.

Build an optimized package in a clean chroot

Alternatively, pacman-buildenv_ext-gitAUR or makepkg-optimizeAUR can be used to build optimized packages within a chroot.

Chroot setup

After setting up a chroot, a few additional steps are needed.

Install makepkg-optimize and backends

First, install some of the backends for the optimization macros to the base chroot:

$ arch-nspawn "$CHROOT"/root pacman -S graphite openmp upx optipng

Then download and build pacman-buildenv_ext-gitAUR, makepkg-optimizeAUR, and nodejs-svgoAUR.

To install them in the base chroot, copy their package files into it and install them, e.g.:

# cp nodejs-svgo-1.1.1-1-any.pkg.tar.xz "$CHROOT"/root/root/
$ arch-nspawn "$CHROOT"/root pacman -U /root/nodejs-svgo-1.1.1-1-any.pkg.tar.xz

Create a profile-guided optimization cache

First, create a folder in the same place, inside and outside of the chroot, to store profiles:

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

Then edit $CHROOT/root/etc/makepkg-optimize.conf and set PROFDEST=/mnt/pgo.

Using the chroot

Note: When updating the chroot, AUR packages have to be updated manually.

Build a package

First, edit $CHROOT/root/etc/makepkg-optimize.conf and select your preferred optimizations.

When building, pass the configuration file to makepkg:

$ makechrootpkg -c -r "$CHROOT" -- --config /etc/makepkg-optimize.conf
Building with profile-guided optimization

After the first building phase, bind the PGO cache:

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

Once the package is installed, test-run its executables.

For the second building phase, do not pass -c to makechrootpkg, but clean $srcdir and overwrite the previous package by passing -Cf to makepkg:

Note: If you have rebooted, be sure to rebind the PGO cache before rebuilding. Alternatively, use fstab to bind these folders persistently.
$ makechrootpkg -r "$CHROOT" -- -Cf --config /etc/makepkg-optimize.conf