Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at release-18.03 75 lines 2.5 kB view raw
1<chapter xmlns="http://docbook.org/ns/docbook" 2 xmlns:xlink="http://www.w3.org/1999/xlink" 3 xml:id="chap-platform-nodes"> 4 <title>Platform Notes</title> 5 <section xml:id="sec-darwin"> 6 <title>Darwin (macOS)</title> 7 8 <para> 9 Some common issues when packaging software for darwin: 10 </para> 11 12 <itemizedlist> 13 <listitem> 14 <para> 15 The darwin <literal>stdenv</literal> uses clang instead of gcc. When 16 referring to the compiler <varname>$CC</varname> or <command>cc</command> 17 will work in both cases. Some builds hardcode gcc/g++ in their build 18 scripts, that can usually be fixed with using something like 19 <literal>makeFlags = [ "CC=cc" ];</literal> or by patching the build 20 scripts. 21 </para> 22<programlisting> 23 stdenv.mkDerivation { 24 name = "libfoo-1.2.3"; 25 # ... 26 buildPhase = '' 27 $CC -o hello hello.c 28 ''; 29 } 30 </programlisting> 31 </listitem> 32 <listitem> 33 <para> 34 On darwin libraries are linked using absolute paths, libraries are 35 resolved by their <literal>install_name</literal> at link time. Sometimes 36 packages won't set this correctly causing the library lookups to fail at 37 runtime. This can be fixed by adding extra linker flags or by running 38 <command>install_name_tool -id</command> during the 39 <function>fixupPhase</function>. 40 </para> 41<programlisting> 42 stdenv.mkDerivation { 43 name = "libfoo-1.2.3"; 44 # ... 45 makeFlags = stdenv.lib.optional stdenv.isDarwin "LDFLAGS=-Wl,-install_name,$(out)/lib/libfoo.dylib"; 46 } 47 </programlisting> 48 </listitem> 49 <listitem> 50 <para> 51 Some packages assume xcode is available and use <command>xcrun</command> 52 to resolve build tools like <command>clang</command>, etc. This causes 53 errors like <code>xcode-select: error: no developer tools were found at 54 '/Applications/Xcode.app'</code> while the build doesn't actually depend 55 on xcode. 56 </para> 57<programlisting> 58 stdenv.mkDerivation { 59 name = "libfoo-1.2.3"; 60 # ... 61 prePatch = '' 62 substituteInPlace Makefile \ 63 --replace '/usr/bin/xcrun clang' clang 64 ''; 65 } 66 </programlisting> 67 <para> 68 The package <literal>xcbuild</literal> can be used to build projects that 69 really depend on Xcode, however projects that build some kind of graphical 70 interface won't work without using Xcode in an impure way. 71 </para> 72 </listitem> 73 </itemizedlist> 74 </section> 75</chapter>