summary refs log tree commit diff
path: root/doc/platform-notes.xml
blob: b2c20c2d35c09f5fea4f6334df944c9e7ee01e29 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<chapter xmlns="http://docbook.org/ns/docbook"
         xmlns:xlink="http://www.w3.org/1999/xlink"
         xml:id="chap-platform-nodes">
 <title>Platform Notes</title>
 <section xml:id="sec-darwin">
  <title>Darwin (macOS)</title>

  <para>
   Some common issues when packaging software for darwin:
  </para>

  <itemizedlist>
   <listitem>
    <para>
     The darwin <literal>stdenv</literal> uses clang instead of gcc. When
     referring to the compiler <varname>$CC</varname> or <command>cc</command>
     will work in both cases. Some builds hardcode gcc/g++ in their build
     scripts, that can usually be fixed with using something like
     <literal>makeFlags = [ "CC=cc" ];</literal> or by patching the build
     scripts.
    </para>
<programlisting>
      stdenv.mkDerivation {
        name = "libfoo-1.2.3";
        # ...
        buildPhase = ''
          $CC -o hello hello.c
        '';
      }
    </programlisting>
   </listitem>
   <listitem>
    <para>
     On darwin libraries are linked using absolute paths, libraries are
     resolved by their <literal>install_name</literal> at link time. Sometimes
     packages won't set this correctly causing the library lookups to fail at
     runtime. This can be fixed by adding extra linker flags or by running
     <command>install_name_tool -id</command> during the
     <function>fixupPhase</function>.
    </para>
<programlisting>
      stdenv.mkDerivation {
        name = "libfoo-1.2.3";
        # ...
        makeFlags = stdenv.lib.optional stdenv.isDarwin "LDFLAGS=-Wl,-install_name,$(out)/lib/libfoo.dylib";
      }
    </programlisting>
   </listitem>
   <listitem>
    <para>
     Some packages assume xcode is available and use <command>xcrun</command>
     to resolve build tools like <command>clang</command>, etc. This causes
     errors like <code>xcode-select: error: no developer tools were found at
     '/Applications/Xcode.app'</code> while the build doesn't actually depend
     on xcode.
    </para>
<programlisting>
      stdenv.mkDerivation {
        name = "libfoo-1.2.3";
        # ...
        prePatch = ''
          substituteInPlace Makefile \
              --replace '/usr/bin/xcrun clang' clang
        '';
      }
    </programlisting>
    <para>
     The package <literal>xcbuild</literal> can be used to build projects that
     really depend on Xcode, however projects that build some kind of graphical
     interface won't work without using Xcode in an impure way.
    </para>
   </listitem>
  </itemizedlist>
 </section>
</chapter>