Difference between revisions of "Makepkg-optimize"

From ArchWiki
Jump to: navigation, search
m (grammar)
m (sub-subsection links are a bit wonky...)
(3 intermediate revisions by the same user not shown)
Line 23: Line 23:
 
=== Configuration ===
 
=== Configuration ===
  
{{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 optimization that are disabled by default.
+
{{AUR|makepkg-optimize}} generates an additional [https://jlk.fjfi.cvut.cz/arch/manpages/man/makepkg.conf.5 configuration file], from your current [[makepkg]] configuration, with supplementary options for optimization that are disabled by default.
  
Edit this file and select your preferred optimizations for [[Makepkg#Building optimized binaries|{{ic|ARCHITECTURE, COMPILE FLAGS}}]], {{ic|BUILD ENVIRONMENT}}, {{ic|GLOBAL PACKAGE OPTIONS}} and {{ic|COMPRESSION DEFAULTS}}.
+
== Build an optimized package ==
 +
 
 +
Edit {{ic|/etc/makepkg-optimize.conf}} and select your preferred optimizations for [[Makepkg#Building optimized binaries|{{ic|ARCHITECTURE, COMPILE FLAGS}}]], {{ic|BUILD ENVIRONMENT}}, {{ic|GLOBAL PACKAGE OPTIONS}} and {{ic|COMPRESSION DEFAULTS}}.
  
== Build an optimized package ==
+
{{Warning|While many packages build with all optimizations enabled, some will not. It may take a few attempts to find which--if any--optimizations a package is compatible with. Some software may also experience runtime problems caused by over-optimization.}}
  
In a directory containing a PKGBUILD, call [[makepkg]] and specify the {{AUR|makepkg-optimize}} configuration file:
+
When [[Makepkg#Usage|building]], pass the {{AUR|makepkg-optimize}} configuration file to makepkg:
  
 
  $ makepkg --config /etc/makepkg-optimize.conf
 
  $ makepkg --config /etc/makepkg-optimize.conf
Line 35: Line 37:
 
{{Note|Building with [[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}} while the second moves the profiles to {{ic|$PROFDEST/$pkgbase.used}} and applies them to the software being packaged.}}
 
{{Note|Building with [[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}} while the second moves the profiles to {{ic|$PROFDEST/$pkgbase.used}} and applies them to the software being packaged.}}
  
{{Warning|While many packages build with all optimizations enabled, some will not. You may have to make a few attempts to find which--if any--optimizations a package is compatible with. Some software may also experience runtime problems caused by over-optimization.}}
+
== Build an optimized package in a [[DeveloperWiki:Building in a Clean Chroot|clean chroot]] ==
 
 
== Build an optimized package in a clean chroot ==
 
  
{{Note|Read [[DeveloperWiki:Building in a Clean Chroot#Classic Way|Building in a Clean Chroot]] and familiarize yourself with the "Classic" method.}}
+
{{Note|Read [[DeveloperWiki:Building in a Clean Chroot#Classic Way|Building in a Clean Chroot]] and familiarize yourself with the "Classic Way".}}
  
It is not necessary to install {{AUR|pacman-buildenv_ext-git}} or {{AUR|makepkg-optimize}} in your Archlinux installation. Alternatively, they can be used to build optimized packages within a [[DeveloperWiki:Building in a Clean Chroot|chroot]].
+
It is not necessary to install {{AUR|pacman-buildenv_ext-git}} or {{AUR|makepkg-optimize}} in your Archlinux installation. Alternatively, they can be used to build optimized packages within a [[chroot]].
  
 
=== Chroot Setup (First time only) ===
 
=== Chroot Setup (First time only) ===
  
After [[DeveloperWiki:Building in a Clean Chroot#Classic Way#Setting Up A Chroot|setting up a chroot]], a few additional steps are needed to build optimized packages.
+
After [[DeveloperWiki:Building in a Clean Chroot#Setting Up A Chroot|setting up a chroot]], a few additional steps are needed to build optimized packages.
  
Create a folder in the same place--both inside and outside of the chroot--to store [[Wikipedia:Profile-guided optimization|PGO]] profiles:
+
==== Install required packages ====
  
# mkdir -m 777 {"$CHROOT"/root,}/mnt/pgo
+
Install [[Git]] and some of the backends for {{AUR|makepkg-optimize}}'s macros in the chroot:
  
Edit {{ic|$CHROOT/root/etc/makepkg-optimize.conf}} and set {{ic|1=PROFDEST=/mnt/pgo}} under {{ic|PACKAGE OUTPUT}}.
+
$ arch-nspawn -M /etc/makepkg.conf "$CHROOT"/root pacman -S git graphite openmp upx optipng
  
{{Accuracy|No need to create separate users, in [[#Proceeding]] built packages can be installed to the container using {{ic|makechrootpkg -I}}. No clear indication this user has other purposes}}
+
Then [[Arch User Repository#Acquire build files|download]], [[DeveloperWiki:Building in a Clean Chroot#Building in the Chroot|build]] and [[DeveloperWiki:Building in a Clean Chroot#Manual package installation|install]] {{AUR|pacman-buildenv_ext-git}}, {{AUR|makepkg-optimize}}, and {{AUR|nodejs-svgo}}.
  
Create an unprivileged user inside the chroot:
+
==== Create a [[Wikipedia:Profile-guided optimization|Profile-guided Optimization]] cache ====
  
# systemd-nspawn -D "$CHROOT"/root useradd "$USER"
+
First, create a folder in the same place--both inside and outside of the chroot--to store profiles:
# systemd-nspawn -D "$CHROOT"/root passwd "$USER"
 
  
Install some of the backends for [[AUR|makepkg-optimize]]'s macros:
+
  # mkdir -m 777 {"$CHROOT"/root,}/mnt/pgo
 
 
  # systemd-nspawn -D "$CHROOT"/root pacman -S graphite openmp upx optipng
 
  
==== Proceeding ====
+
Then edit {{ic|$CHROOT/root/etc/makepkg-optimize.conf}} and set {{ic|1=PROFDEST=/mnt/pgo}} under {{ic|PACKAGE OUTPUT}}.
 
 
Install git in the chroot:
 
 
 
# systemd-nspawn -D "$CHROOT"/root pacman -S git
 
 
 
Log in to the chroot as an unprivileged user:
 
 
 
# arch-chroot -u "$USER" "$CHROOT"/root
 
 
 
Change to a permissive directory, such as {{ic|/home/$USER}} or {{ic|/tmp}} inside the chroot, then [[Arch User Repository#Acquire build files|clone]], [[Arch User Repository#Build and install the package|build and install]] {{AUR|pacman-buildenv_ext-git}}, {{AUR|makepkg-optimize}}, and {{AUR|nodejs-svgo}}.
 
  
 
=== Using the chroot ===
 
=== Using the chroot ===
  
==== Keep your chroot up-to-date ====
+
{{Note|When [[DeveloperWiki:Building in a Clean Chroot#Building in the Chroot|updating]] the chroot, [[Makepkg-optimize#Install required packages|AUR packages]] will have to be updated manually}}
 
 
[[makepkg-optimize#Proceeding without an AUR helper|update AUR packages individually]]:
 
 
 
$ arch-nspawn -M /etc/makepkg.conf "$CHROOT"/root -u "$USER" pacman -Syu
 
  
 
==== Build a package ====
 
==== Build a package ====
  
Edit {{ic|$CHROOT/root/etc/makepkg-optimize.conf}} and select your preferred optimizations for [[Makepkg#Building optimized binaries|{{ic|ARCHITECTURE, COMPILE FLAGS}}]], {{ic|BUILD ENVIRONMENT}}, {{ic|GLOBAL PACKAGE OPTIONS}} and {{ic|COMPRESSION DEFAULTS}}.
+
First, edit [[Makepkg-optimize#Configuration|{{ic|$CHROOT/root/etc/makepkg-optimize.conf}}]] and select your preferred optimizations for [[Makepkg#Building optimized binaries|{{ic|ARCHITECTURE, COMPILE FLAGS}}]], {{ic|BUILD ENVIRONMENT}}, {{ic|GLOBAL PACKAGE OPTIONS}} and {{ic|COMPRESSION DEFAULTS}}.
  
In a directory containing a PKGBUILD, call makechrootpkg with this configuration file:
+
When [[DeveloperWiki:Building in a Clean Chroot#Building in the Chroot|building]], pass the {{AUR|makepkg-optimize}} configuration file to makepkg:
  
 
  $ makechrootpkg -c -r "$CHROOT" -- --config /etc/makepkg-optimize.conf
 
  $ makechrootpkg -c -r "$CHROOT" -- --config /etc/makepkg-optimize.conf
  
===== When building with [[Wikipedia:Profile-guided optimization|Profile-guided optimization]] =====
+
===== Building with [[Wikipedia:Profile-guided optimization|Profile-guided optimization]] =====
  
Bind the PGO folder:
+
After the first building phase, bind the PGO folder:
  
 
  # mount -o bind {,"$CHROOT"/"$USER"}/mnt/pgo
 
  # mount -o bind {,"$CHROOT"/"$USER"}/mnt/pgo
  
Install the package and test run its executables.
+
Once the package is built and [[Pacman#Usage#Additional commands|installed]], test run its executables.
 +
 
 +
Then, for the second building phase, remove cruft but ''do not'' clean the chroot.
  
For the second phase, remove cruft and rebuild the package, but ''do not'' clean the chroot. If you have rebooted, be sure to rebind the PGO folder first:
+
{{Note|If you have rebooted, be sure to rebind the PGO folder!}}
  
 
  $ rm -rf *.pkg.tar.xz pkg src; makechrootpkg -r "$CHROOT" -- --config /etc/makepkg-optimize.conf
 
  $ rm -rf *.pkg.tar.xz pkg src; makechrootpkg -r "$CHROOT" -- --config /etc/makepkg-optimize.conf

Revision as of 16:00, 10 September 2018

Tango-go-next.pngThis article or section is a candidate for moving to [[]].Tango-go-next.png

Notes: AUR is not a code hosting platform and the wiki is not well suited for upstream documentation, in this case for a pacman fork. Propose to move the code and documentation to github or other suitable platform; it could then be linked from other articles where appropriate (Discuss in Talk:Makepkg-optimize#)

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

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, from your current makepkg configuration, with supplementary options for optimization that are disabled by default.

Build an optimized package

Edit /etc/makepkg-optimize.conf and select your preferred optimizations for ARCHITECTURE, COMPILE FLAGS, BUILD ENVIRONMENT, GLOBAL PACKAGE OPTIONS and COMPRESSION DEFAULTS.

Warning: While many packages build with all optimizations enabled, some will not. It may take a few attempts to find which--if any--optimizations a package is compatible with. Some software may also experience runtime problems caused by over-optimization.

When building, pass the makepkg-optimizeAUR configuration file to makepkg:

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

Build an optimized package in a clean chroot

Note: Read Building in a Clean Chroot and familiarize yourself with the "Classic Way".

It is not necessary to install pacman-buildenv_ext-gitAUR or makepkg-optimizeAUR in your Archlinux installation. Alternatively, they can be used to build optimized packages within a chroot.

Chroot Setup (First time only)

After setting up a chroot, a few additional steps are needed to build optimized packages.

Install required packages

Install Git and some of the backends for makepkg-optimizeAUR's macros in the chroot:

$ arch-nspawn -M /etc/makepkg.conf "$CHROOT"/root pacman -S git graphite openmp upx optipng

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

Create a Profile-guided Optimization cache

First, create a folder in the same place--both 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 under PACKAGE OUTPUT.

Using the chroot

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

Build a package

First, edit $CHROOT/root/etc/makepkg-optimize.conf and select your preferred optimizations for ARCHITECTURE, COMPILE FLAGS, BUILD ENVIRONMENT, GLOBAL PACKAGE OPTIONS and COMPRESSION DEFAULTS.

When building, pass the makepkg-optimizeAUR 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 folder:

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

Once the package is built and installed, test run its executables.

Then, for the second building phase, remove cruft but do not clean the chroot.

Note: If you have rebooted, be sure to rebind the PGO folder!
$ rm -rf *.pkg.tar.xz pkg src; makechrootpkg -r "$CHROOT" -- --config /etc/makepkg-optimize.conf