No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

84 líneas
3.3 KiB

  1. <chapter xmlns="http://docbook.org/ns/docbook"
  2. xmlns:xlink="http://www.w3.org/1999/xlink"
  3. xml:id="chap-platform-notes">
  4. <title>Platform Notes</title>
  5. <section xml:id="sec-darwin">
  6. <title>Darwin (macOS)</title>
  7. <para>
  8. Some common issues when packaging software for Darwin:
  9. </para>
  10. <itemizedlist>
  11. <listitem>
  12. <para>
  13. 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.
  14. </para>
  15. <programlisting>
  16. stdenv.mkDerivation {
  17. name = "libfoo-1.2.3";
  18. # ...
  19. buildPhase = ''
  20. $CC -o hello hello.c
  21. '';
  22. }
  23. </programlisting>
  24. </listitem>
  25. <listitem>
  26. <para>
  27. 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>.
  28. </para>
  29. <programlisting>
  30. stdenv.mkDerivation {
  31. name = "libfoo-1.2.3";
  32. # ...
  33. makeFlags = stdenv.lib.optional stdenv.isDarwin "LDFLAGS=-Wl,-install_name,$(out)/lib/libfoo.dylib";
  34. }
  35. </programlisting>
  36. </listitem>
  37. <listitem>
  38. <para>
  39. Even if the libraries are linked using absolute paths and resolved via their <literal>install_name</literal> correctly, tests can sometimes fail to run binaries. This happens because the <varname>checkPhase</varname> runs before the libraries are installed.
  40. </para>
  41. <para>
  42. This can usually be solved by running the tests after the <varname>installPhase</varname> or alternatively by using <varname>DYLD_LIBRARY_PATH</varname>. More information about this variable can be found in the <citerefentry>
  43. <refentrytitle>dyld</refentrytitle>
  44. <manvolnum>1</manvolnum></citerefentry> manpage.
  45. </para>
  46. <programlisting>
  47. dyld: Library not loaded: /nix/store/7hnmbscpayxzxrixrgxvvlifzlxdsdir-jq-1.5-lib/lib/libjq.1.dylib
  48. Referenced from: /private/tmp/nix-build-jq-1.5.drv-0/jq-1.5/tests/../jq
  49. Reason: image not found
  50. ./tests/jqtest: line 5: 75779 Abort trap: 6
  51. </programlisting>
  52. <programlisting>
  53. stdenv.mkDerivation {
  54. name = "libfoo-1.2.3";
  55. # ...
  56. doInstallCheck = true;
  57. installCheckTarget = "check";
  58. }
  59. </programlisting>
  60. </listitem>
  61. <listitem>
  62. <para>
  63. 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.
  64. </para>
  65. <programlisting>
  66. stdenv.mkDerivation {
  67. name = "libfoo-1.2.3";
  68. # ...
  69. prePatch = ''
  70. substituteInPlace Makefile \
  71. --replace '/usr/bin/xcrun clang' clang
  72. '';
  73. }
  74. </programlisting>
  75. <para>
  76. The package <literal>xcbuild</literal> can be used to build projects that really depend on Xcode. However, this replacement is not 100% compatible with Xcode and can occasionally cause issues.
  77. </para>
  78. </listitem>
  79. </itemizedlist>
  80. </section>
  81. </chapter>