| 
									
										
										
										
											2017-10-29 17:15:43 +01:00
										 |  |  | <chapter xmlns="http://docbook.org/ns/docbook" | 
					
						
							|  |  |  |          xmlns:xlink="http://www.w3.org/1999/xlink" | 
					
						
							|  |  |  |          xml:id="chap-platform-nodes"> | 
					
						
							| 
									
										
										
										
											2018-05-01 19:54:21 -04:00
										 |  |  |  <title>Platform Notes</title> | 
					
						
							|  |  |  |  <section xml:id="sec-darwin"> | 
					
						
							|  |  |  |   <title>Darwin (macOS)</title> | 
					
						
							| 
									
										
										
										
											2017-10-29 17:15:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-01 19:54:21 -04:00
										 |  |  |   <para> | 
					
						
							| 
									
										
										
										
											2018-11-18 23:10:39 -06:00
										 |  |  |    Some common issues when packaging software for Darwin: | 
					
						
							| 
									
										
										
										
											2018-05-01 19:54:21 -04:00
										 |  |  |   </para> | 
					
						
							| 
									
										
										
										
											2017-10-29 17:15:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-01 19:54:21 -04:00
										 |  |  |   <itemizedlist> | 
					
						
							|  |  |  |    <listitem> | 
					
						
							| 
									
										
										
										
											2017-10-29 17:15:43 +01:00
										 |  |  |     <para> | 
					
						
							| 
									
										
										
										
											2018-11-18 23:10:39 -06:00
										 |  |  |      The Darwin <literal>stdenv</literal> uses clang instead of gcc. When | 
					
						
							| 
									
										
										
										
											2018-05-01 19:54:21 -04:00
										 |  |  |      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. | 
					
						
							| 
									
										
										
										
											2017-10-29 17:15:43 +01:00
										 |  |  |     </para> | 
					
						
							| 
									
										
										
										
											2018-05-01 19:54:21 -04:00
										 |  |  | <programlisting> | 
					
						
							| 
									
										
										
										
											2017-10-29 17:15:43 +01:00
										 |  |  |       stdenv.mkDerivation { | 
					
						
							|  |  |  |         name = "libfoo-1.2.3"; | 
					
						
							|  |  |  |         # ... | 
					
						
							|  |  |  |         buildPhase = '' | 
					
						
							|  |  |  |           $CC -o hello hello.c | 
					
						
							|  |  |  |         ''; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     </programlisting> | 
					
						
							| 
									
										
										
										
											2018-05-01 19:54:21 -04:00
										 |  |  |    </listitem> | 
					
						
							|  |  |  |    <listitem> | 
					
						
							| 
									
										
										
										
											2017-10-29 17:15:43 +01:00
										 |  |  |     <para> | 
					
						
							| 
									
										
										
										
											2018-11-18 23:10:39 -06:00
										 |  |  |      On Darwin, libraries are linked using absolute paths, libraries are | 
					
						
							| 
									
										
										
										
											2018-05-01 19:54:21 -04:00
										 |  |  |      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>. | 
					
						
							| 
									
										
										
										
											2017-10-29 17:15:43 +01:00
										 |  |  |     </para> | 
					
						
							| 
									
										
										
										
											2018-05-01 19:54:21 -04:00
										 |  |  | <programlisting> | 
					
						
							| 
									
										
										
										
											2017-10-29 17:15:43 +01:00
										 |  |  |       stdenv.mkDerivation { | 
					
						
							|  |  |  |         name = "libfoo-1.2.3"; | 
					
						
							|  |  |  |         # ... | 
					
						
							|  |  |  |         makeFlags = stdenv.lib.optional stdenv.isDarwin "LDFLAGS=-Wl,-install_name,$(out)/lib/libfoo.dylib"; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     </programlisting> | 
					
						
							| 
									
										
										
										
											2018-05-01 19:54:21 -04:00
										 |  |  |    </listitem> | 
					
						
							| 
									
										
										
										
											2018-07-30 23:25:33 +02:00
										 |  |  |    <listitem> | 
					
						
							|  |  |  |     <para> | 
					
						
							|  |  |  |      Even if the libraries are linked using absolute paths and resolved via | 
					
						
							|  |  |  |      their <literal>install_name</literal> correctly, tests can sometimes fail | 
					
						
							| 
									
										
										
										
											2018-08-27 19:54:41 -04:00
										 |  |  |      to run binaries. This happens because the <varname>checkPhase</varname> | 
					
						
							| 
									
										
										
										
											2018-07-30 23:25:33 +02:00
										 |  |  |      runs before the libraries are installed. | 
					
						
							|  |  |  |     </para> | 
					
						
							|  |  |  |     <para> | 
					
						
							|  |  |  |      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 | 
					
						
							| 
									
										
										
										
											2018-08-27 19:54:41 -04:00
										 |  |  |      can be found in the <citerefentry> | 
					
						
							|  |  |  |      <refentrytitle>dyld</refentrytitle> | 
					
						
							| 
									
										
										
										
											2018-07-30 23:25:33 +02:00
										 |  |  |      <manvolnum>1</manvolnum></citerefentry> manpage. | 
					
						
							|  |  |  |     </para> | 
					
						
							|  |  |  | <programlisting> | 
					
						
							|  |  |  |       dyld: Library not loaded: /nix/store/7hnmbscpayxzxrixrgxvvlifzlxdsdir-jq-1.5-lib/lib/libjq.1.dylib | 
					
						
							|  |  |  |       Referenced from: /private/tmp/nix-build-jq-1.5.drv-0/jq-1.5/tests/../jq | 
					
						
							|  |  |  |       Reason: image not found | 
					
						
							|  |  |  |       ./tests/jqtest: line 5: 75779 Abort trap: 6 | 
					
						
							|  |  |  |     </programlisting> | 
					
						
							|  |  |  | <programlisting> | 
					
						
							|  |  |  |       stdenv.mkDerivation { | 
					
						
							|  |  |  |         name = "libfoo-1.2.3"; | 
					
						
							|  |  |  |         # ... | 
					
						
							|  |  |  |         doInstallCheck = true; | 
					
						
							|  |  |  |         installCheckTarget = "check"; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     </programlisting> | 
					
						
							|  |  |  |    </listitem> | 
					
						
							| 
									
										
										
										
											2018-05-01 19:54:21 -04:00
										 |  |  |    <listitem> | 
					
						
							| 
									
										
										
										
											2017-10-29 17:15:43 +01:00
										 |  |  |     <para> | 
					
						
							| 
									
										
										
										
											2018-05-01 19:54:21 -04:00
										 |  |  |      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. | 
					
						
							| 
									
										
										
										
											2017-10-29 17:15:43 +01:00
										 |  |  |     </para> | 
					
						
							| 
									
										
										
										
											2018-05-01 19:54:21 -04:00
										 |  |  | <programlisting> | 
					
						
							| 
									
										
										
										
											2017-10-29 17:15:43 +01:00
										 |  |  |       stdenv.mkDerivation { | 
					
						
							|  |  |  |         name = "libfoo-1.2.3"; | 
					
						
							|  |  |  |         # ... | 
					
						
							|  |  |  |         prePatch = '' | 
					
						
							|  |  |  |           substituteInPlace Makefile \ | 
					
						
							|  |  |  |               --replace '/usr/bin/xcrun clang' clang | 
					
						
							|  |  |  |         ''; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     </programlisting> | 
					
						
							|  |  |  |     <para> | 
					
						
							| 
									
										
										
										
											2018-05-01 19:54:21 -04:00
										 |  |  |      The package <literal>xcbuild</literal> can be used to build projects that | 
					
						
							| 
									
										
										
										
											2018-11-18 23:20:47 -06:00
										 |  |  |      really depend on Xcode. However, this replacement is not 100% | 
					
						
							|  |  |  |      compatible with Xcode and can occasionally cause issues. | 
					
						
							| 
									
										
										
										
											2017-10-29 17:15:43 +01:00
										 |  |  |     </para> | 
					
						
							| 
									
										
										
										
											2018-05-01 19:54:21 -04:00
										 |  |  |    </listitem> | 
					
						
							|  |  |  |   </itemizedlist> | 
					
						
							|  |  |  |  </section> | 
					
						
							| 
									
										
										
										
											2017-10-29 17:15:43 +01:00
										 |  |  | </chapter> |