at 18.09-beta 3.7 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 Even if the libraries are linked using absolute paths and resolved via 52 their <literal>install_name</literal> correctly, tests can sometimes fail 53 to run binaries. This happens because the <varname>checkPhase</varname> 54 runs before the libraries are installed. 55 </para> 56 <para> 57 This can usually be solved by running the tests after the 58 <varname>installPhase</varname> or alternatively by using 59 <varname>DYLD_LIBRARY_PATH</varname>. More information about this variable 60 can be found in the <citerefentry> 61 <refentrytitle>dyld</refentrytitle> 62 <manvolnum>1</manvolnum></citerefentry> manpage. 63 </para> 64<programlisting> 65 dyld: Library not loaded: /nix/store/7hnmbscpayxzxrixrgxvvlifzlxdsdir-jq-1.5-lib/lib/libjq.1.dylib 66 Referenced from: /private/tmp/nix-build-jq-1.5.drv-0/jq-1.5/tests/../jq 67 Reason: image not found 68 ./tests/jqtest: line 5: 75779 Abort trap: 6 69 </programlisting> 70<programlisting> 71 stdenv.mkDerivation { 72 name = "libfoo-1.2.3"; 73 # ... 74 doInstallCheck = true; 75 installCheckTarget = "check"; 76 } 77 </programlisting> 78 </listitem> 79 <listitem> 80 <para> 81 Some packages assume xcode is available and use <command>xcrun</command> 82 to resolve build tools like <command>clang</command>, etc. This causes 83 errors like <code>xcode-select: error: no developer tools were found at 84 '/Applications/Xcode.app'</code> while the build doesn't actually depend 85 on xcode. 86 </para> 87<programlisting> 88 stdenv.mkDerivation { 89 name = "libfoo-1.2.3"; 90 # ... 91 prePatch = '' 92 substituteInPlace Makefile \ 93 --replace '/usr/bin/xcrun clang' clang 94 ''; 95 } 96 </programlisting> 97 <para> 98 The package <literal>xcbuild</literal> can be used to build projects that 99 really depend on Xcode, however projects that build some kind of graphical 100 interface won't work without using Xcode in an impure way. 101 </para> 102 </listitem> 103 </itemizedlist> 104 </section> 105</chapter>