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