Build flags: Difference between revisions
imported>Kquote03 updated to hostPlatform |
m fix typos and similar |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
=== Building a package for a specific CPU === | === Building a package for a specific CPU === | ||
By default, packages built for, say, x86_64 do not take advantage of the feature of more recent | By default, packages built for, say, x86_64 do not take advantage of the feature of more recent CPUs so that the executables you compile also work on older CPUs of the same architecture. This is essential because of the [[Binary Cache|binary cache]] feature of Nix: if a package is compiled on [[Hydra]] for a recent CPU, older systems using Hydra may download software that they can't run. | ||
However, you can build some package or even all your system to take advantage of the specific model of your | However, you can build some package or even all your system to take advantage of the specific model of your CPU. Note that you will not be able to take advantage of the binary cache (except for FODs) and thus must build everything locally from scratch. The first step is to determine the <code>-march</code> and <code>-mtune</code> arguments that you want to pass to gcc. In the following we want to target a skylake CPU so we use <code>-march=skylake -mtune=skylake</code>. | ||
==== Building a single package ==== | ==== Building a single package ==== | ||
Line 28: | Line 28: | ||
==== Adapting a derivation to specific plaforms ==== | ==== Adapting a derivation to specific plaforms ==== | ||
The technique above should pass the correct flags to gcc so that it uses the processor to its fullest. However, some build systems or configure scripts want to know whether to enable some processor-specific instructions, for example | The technique above should pass the correct flags to gcc so that it uses the processor to its fullest. However, some build systems or configure scripts want to know whether to enable some processor-specific instructions, for example SSE. One way to do so is to inspect the <code>stdenv.hostPlatform.*Support</code> predicates. Here is an example from g2o: | ||
<code> | <code> | ||
cmakeFlags = [ | cmakeFlags = [ "-DDISABLE_SSE3=${ if stdenv.hostPlatform.sse3Support then "OFF" else "ON"}" ] | ||
</code> | </code> | ||
Line 39: | Line 39: | ||
{ config, pkgs, lib, ... }: | { config, pkgs, lib, ... }: | ||
{ | { | ||
nixpkgs.hostPlatform = { | |||
gcc.arch = "skylake"; | |||
gcc.tune = "skylake"; | |||
system = "x86_64-linux"; | |||
}; | |||
} | } | ||
</nowiki>}} | </nowiki>}} | ||
Line 64: | Line 64: | ||
pkgs.openssl | pkgs.openssl | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Development]] | |||
[[Category:nix]] |