Difference between revisions of "Makepkg-optimize"

From ArchWiki
Jump to navigation Jump to search
m (Building with PGO: specify 'program' exit(); minor formatting.)
(Header: link "comments" to User:Quequotion/Arch User Repository#Commenting on packages)
 
(23 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{Lowercase title}}
 
{{Lowercase title}}
 
[[Category:Package management]]
 
[[Category:Package management]]
 +
[[ja:Makepkg-optimize]]
 
{{Related articles start}}
 
{{Related articles start}}
 
{{Related|DeveloperWiki:Building in a clean chroot}}
 
{{Related|DeveloperWiki:Building in a clean chroot}}
Line 6: Line 7:
 
{{Related articles end}}
 
{{Related articles end}}
  
{{AUR|makepkg-optimize}} is a collection of supplemental [https://git.archlinux.org/pacman.git/commit/?id=508b4e3ec0cb3e365942f4dc0626edda4789932b buildenv] and [https://git.archlinux.org/pacman.git/commit/?id=295a3491adc4af5c8634ac82777212ed9c664457 tidy] scripts for {{AUR|pacman-git}} which provide macros for several kinds of optimization in the {{ic|build()}} and {{ic|package()}} stages.
+
{{AUR|makepkg-optimize}} is a collection of supplemental [https://git.archlinux.org/pacman.git/commit/?id=295a3491adc4af5c8634ac82777212ed9c664457 tidy], [https://git.archlinux.org/pacman.git/commit/?id=508b4e3ec0cb3e365942f4dc0626edda4789932b buildenv], and [https://git.archlinux.org/pacman.git/commit/?id=0bb04fa16a82db133dd010478c1256bc8500c5e7 executable] scripts for {{AUR|pacman-git}} which provide macros for several kinds of optimization in the {{ic|build()}} and {{ic|package()}} stages.
 +
 
 +
{{Note|As with any package in the [[Arch User Repository]], {{AUR|makepkg-optimize}} has no official support. You should read, and you may post [[User:Quequotion/Arch User Repository#Commenting on packages|comments]] on its AUR page.}}
  
 
== Installation ==
 
== Installation ==
  
Install {{AUR|makepkg-optimize}} from the [[AUR]] and, to make optimizations available, install their backends: {{Pkg|openmp}}, {{Pkg|upx}}, {{Pkg|optipng}}, and {{AUR|nodejs-svgo}}
+
Install {{AUR|makepkg-optimize}} and, to make optimizations available, install their backends: {{Pkg|openmp}}, {{Pkg|upx}}, {{Pkg|optipng}}, and {{AUR|svgo}}.
  
 
=== Configuration ===
 
=== Configuration ===
Line 16: Line 19:
 
{{AUR|makepkg-optimize}} generates a redundant [https://jlk.fjfi.cvut.cz/arch/manpages/man/makepkg.conf.5 configuration file], {{ic|/etc/makepkg-optimize.conf}}, from your current [[makepkg]] configuration.
 
{{AUR|makepkg-optimize}} generates a redundant [https://jlk.fjfi.cvut.cz/arch/manpages/man/makepkg.conf.5 configuration file], {{ic|/etc/makepkg-optimize.conf}}, from your current [[makepkg]] configuration.
  
This file lists the 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], all of which are disabled by default.
+
This file lists supplementary [[Makepkg#Building optimized binaries|COMPILE FLAGS]], [https://aur.archlinux.org/cgit/aur.git/tree/buildenv_ext.conf?h=makepkg-optimize BUILD ENVIRONMENT] options, [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] options, and [https://aur.archlinux.org/cgit/aur.git/tree/compress-param_max.conf?h=makepkg-optimize COMPRESSION DEFAULTS], all of which 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.}}
 
{{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.}}
Line 26: Line 29:
 
  $ makepkg --config /etc/makepkg-optimize.conf
 
  $ makepkg --config /etc/makepkg-optimize.conf
  
{{Note|[[Wikipedia:Profile-guided optimization|Profile-guided optimization]] requires that a package be built and installed ''twice''. The first phase initiates profile generation in {{ic|$PROFDEST/$pkgbase.gen}}; the second moves them to {{ic|$PROFDEST/$pkgbase.used}} and applies them.}}
+
{{Note|[[Wikipedia:Profile-guided optimization|Profile-guided optimization]] requires that a package be built and installed ''twice''. The first phase initiates profile generation in {{ic|$PROFDEST/''pkgbase''.gen}}; the second moves them to {{ic|$PROFDEST/''pkgbase''.used}} and applies them.}}
  
 
== Build an optimized package in a clean chroot ==
 
== Build an optimized package in a clean chroot ==
Line 42: Line 45:
 
  $ arch-nspawn "$CHROOT"/root pacman -S openmp upx optipng
 
  $ arch-nspawn "$CHROOT"/root pacman -S openmp upx optipng
  
Then [[Arch User Repository#Acquire build files|download]] and [[DeveloperWiki:Building in a clean chroot#Building in the chroot|build]] {{AUR|makepkg-optimize}} and {{AUR|nodejs-svgo}}.
+
Then [[Arch User Repository#Acquire build files|download]] and [[DeveloperWiki:Building in a clean chroot#Building in the chroot|build]] {{AUR|pacman-git}}, {{AUR|makepkg-optimize}} and {{AUR|svgo}}.
  
 
To install them in the base chroot, copy their package files into it and install them, e.g.:
 
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/
+
  # cp svgo-1.2.2-2-any.pkg.tar.xz "$CHROOT"/root/root/
  $ arch-nspawn "$CHROOT"/root pacman -U /root/nodejs-svgo-1.1.1-1-any.pkg.tar.xz
+
  $ arch-nspawn "$CHROOT"/root pacman -U /root/svgo-1.2.2-2-any.pkg.tar.xz
 +
{{Warning|This voids the warranty on your "clean" chroot!}}
  
 
==== Create a PGO cache ====
 
==== Create a PGO cache ====
Line 73: Line 77:
 
After the first building phase, bind the [[#Create a PGO cache|PGO cache]]:
 
After the first building phase, bind the [[#Create a PGO cache|PGO cache]]:
  
  # mount -o bind {,"$CHROOT"/"$USER"}/mnt/pgo
+
  # mount -o bind {,"$CHROOT"/root}/mnt/pgo
 +
# mount -o bind "$CHROOT"/{root,"$USER"}/mnt/pgo
  
{{Tip|Alternatively, use [[fstab]] to bind these folders persistently.}}
+
{{Tip|Use [[fstab]] to [https://serverfault.com/a/613184 bind] these folders at boot.}}
  
Once the package is [[Pacman#Additional commands|installed]], test-run its executables.
+
[[Pacman#Additional commands|Install]] the package and test-run its executables.
  
 
{{Note|Profiles are generated on program {{ic|exit()}}. Persistent daemons, such as [[systemd]], may require a reboot to produce profiles. If you have rebooted, be sure to rebind the PGO cache before rebuilding.}}
 
{{Note|Profiles are generated on program {{ic|exit()}}. Persistent daemons, such as [[systemd]], may require a reboot to produce profiles. If you have rebooted, be sure to rebind the PGO cache before rebuilding.}}
  
For the second building phase, do ''not'' pass {{ic|-c}} to {{ic|makechrootpkg}}, but clean {{ic|$srcdir}} and overwrite the previous package by passing {{ic|-Cf}} to {{ic|makepkg}}:
+
After thoroughly utilizing the software, [[#Build a package|rebuild]] and reinstall the package.
 
 
$ makechrootpkg -r "$CHROOT" -- -Cf --config /etc/makepkg-optimize.conf
 

Latest revision as of 11:58, 21 July 2019

makepkg-optimizeAUR is a collection of supplemental tidy, buildenv, and executable scripts for pacman-gitAUR which provide macros for several kinds of optimization in the build() and package() stages.

Note: As with any package in the Arch User Repository, makepkg-optimizeAUR has no official support. You should read, and you may post comments on its AUR page.

Installation

Install makepkg-optimizeAUR and, to make optimizations available, install their backends: openmp, upx, optipng, and svgoAUR.

Configuration

makepkg-optimizeAUR generates a redundant configuration file, /etc/makepkg-optimize.conf, from your current makepkg configuration.

This file lists supplementary COMPILE FLAGS, BUILD ENVIRONMENT options, GLOBAL PACKAGE OPTIONS, PACKAGE OUTPUT options, and COMPRESSION DEFAULTS, all of which 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

After selecting your preferred optimizations, pass the configuration file when building:

$ 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 moves them to $PROFDEST/pkgbase.used and applies them.

Build an optimized package in a clean chroot

Alternatively, makepkg-optimize 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 openmp upx optipng

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

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

# cp svgo-1.2.2-2-any.pkg.tar.xz "$CHROOT"/root/root/
$ arch-nspawn "$CHROOT"/root pacman -U /root/svgo-1.2.2-2-any.pkg.tar.xz
Warning: This voids the warranty on your "clean" chroot!

Create a PGO cache

To use PGO, 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 PGO

After the first building phase, bind the PGO cache:

# mount -o bind {,"$CHROOT"/root}/mnt/pgo
# mount -o bind "$CHROOT"/{root,"$USER"}/mnt/pgo
Tip: Use fstab to bind these folders at boot.

Install the package and test-run its executables.

Note: Profiles are generated on program exit(). Persistent daemons, such as systemd, may require a reboot to produce profiles. If you have rebooted, be sure to rebind the PGO cache before rebuilding.

After thoroughly utilizing the software, rebuild and reinstall the package.