v8: fixes build on darwin

v8 compilation on macOS was failing because of missing dependency and
wrong linker. The approach to make it work is similar to the nodejs
package.

+78 -6
+13 -6
pkgs/development/libraries/v8/default.nix
··· 1 1 { stdenv, lib, fetchgit, fetchFromGitHub, gyp, readline, python, which, icu 2 - , patchelf, coreutils 2 + , patchelf, coreutils, cctools 3 3 , doCheck ? false 4 4 , static ? false 5 5 }: ··· 126 126 127 127 # Patch based off of: 128 128 # https://github.com/cowboyd/libv8/tree/v5.1.281.67.0/patches 129 - patches = lib.optional (!doCheck) ./libv8-5.4.232.patch; 129 + patches = lib.optional (!doCheck) ./libv8-5.4.232.patch 130 + ++ stdenv.lib.optionals stdenv.isDarwin [ ./no-xcode.patch ]; 131 + 132 + prePatch = '' 133 + chmod +w tools/gyp/pylib/gyp 134 + chmod +w tools/gyp/pylib/gyp/xcode_emulation.py 135 + ''; 130 136 131 137 postPatch = '' 132 138 sed -i 's,#!/usr/bin/env python,#!${python}/bin/python,' gypfiles/gyp_v8 ··· 152 158 ''; 153 159 154 160 nativeBuildInputs = [ which ]; 155 - buildInputs = [ readline python icu patchelf ]; 161 + buildInputs = [ readline python icu patchelf ] 162 + ++ stdenv.lib.optionals stdenv.isDarwin [ cctools ]; 156 163 157 164 NIX_CFLAGS_COMPILE = "-Wno-error=strict-overflow"; 158 165 159 166 buildFlags = [ 160 - "LINK=g++" 167 + "LINK=c++" 161 168 "-C out" 162 169 "builddir=$(CURDIR)/Release" 163 170 "BUILDTYPE=Release" ··· 174 181 install -vD out/Release/mksnapshot "$out/bin/mksnapshot" 175 182 ${if static then "" 176 183 else if stdenv.isDarwin then '' 177 - install -vD out/Release/lib.target/libv8.dylib "$out/lib/libv8.dylib" 184 + install -vD out/Release/libv8.dylib "$out/lib/libv8.dylib" 178 185 install_name_tool -change /usr/local/lib/libv8.dylib $out/lib/libv8.dylib -change /usr/lib/libgcc_s.1.dylib ${stdenv.cc.cc.lib}/lib/libgcc_s.1.dylib $out/bin/d8 179 186 install_name_tool -id $out/lib/libv8.dylib -change /usr/lib/libgcc_s.1.dylib ${stdenv.cc.cc.lib}/lib/libgcc_s.1.dylib $out/lib/libv8.dylib 180 187 '' else '' ··· 190 197 meta = with lib; { 191 198 description = "Google's open source JavaScript engine"; 192 199 maintainers = with maintainers; [ cstrahan proglodyte ]; 193 - platforms = platforms.linux; 200 + platforms = platforms.linux ++ platforms.darwin; 194 201 license = licenses.bsd3; 195 202 }; 196 203 }
+64
pkgs/development/libraries/v8/no-xcode.patch
··· 1 + --- a/tools/gyp/pylib/gyp/xcode_emulation.py 2 + +++ a/tools/gyp/pylib/gyp/xcode_emulation.py 3 + @@ -473,10 +473,16 @@ 4 + 5 + def _XcodeSdkPath(self, sdk_root): 6 + if sdk_root not in XcodeSettings._sdk_path_cache: 7 + - sdk_path = self._GetSdkVersionInfoItem(sdk_root, '--show-sdk-path') 8 + - XcodeSettings._sdk_path_cache[sdk_root] = sdk_path 9 + - if sdk_root: 10 + - XcodeSettings._sdk_root_cache[sdk_path] = sdk_root 11 + + try: 12 + + sdk_path = self._GetSdkVersionInfoItem(sdk_root, '--show-sdk-path') 13 + + XcodeSettings._sdk_path_cache[sdk_root] = sdk_path 14 + + if sdk_root: 15 + + XcodeSettings._sdk_root_cache[sdk_path] = sdk_root 16 + + except: 17 + + # if this fails it's because xcodebuild failed, which means 18 + + # the user is probably on a CLT-only system, where there 19 + + # is no valid SDK root 20 + + XcodeSettings._sdk_path_cache[sdk_root] = None 21 + return XcodeSettings._sdk_path_cache[sdk_root] 22 + 23 + def _AppendPlatformVersionMinFlags(self, lst): 24 + @@ -606,10 +612,11 @@ 25 + framework_root = sdk_root 26 + else: 27 + framework_root = '' 28 + - config = self.spec['configurations'][self.configname] 29 + - framework_dirs = config.get('mac_framework_dirs', []) 30 + - for directory in framework_dirs: 31 + - cflags.append('-F' + directory.replace('$(SDKROOT)', framework_root)) 32 + + if 'SDKROOT' in self._Settings(): 33 + + config = self.spec['configurations'][self.configname] 34 + + framework_dirs = config.get('mac_framework_dirs', []) 35 + + for directory in framework_dirs: 36 + + cflags.append('-F' + directory.replace('$(SDKROOT)', framework_root)) 37 + 38 + self.configname = None 39 + return cflags 40 + @@ -861,10 +868,11 @@ 41 + sdk_root = self._SdkPath() 42 + if not sdk_root: 43 + sdk_root = '' 44 + - config = self.spec['configurations'][self.configname] 45 + - framework_dirs = config.get('mac_framework_dirs', []) 46 + - for directory in framework_dirs: 47 + - ldflags.append('-F' + directory.replace('$(SDKROOT)', sdk_root)) 48 + + if 'SDKROOT' in self._Settings(): 49 + + config = self.spec['configurations'][self.configname] 50 + + framework_dirs = config.get('mac_framework_dirs', []) 51 + + for directory in framework_dirs: 52 + + ldflags.append('-F' + directory.replace('$(SDKROOT)', sdk_root)) 53 + 54 + platform_root = self._XcodePlatformPath(configname) 55 + if sdk_root and platform_root and self._IsXCTest(): 56 + @@ -1358,7 +1366,7 @@ 57 + if version: 58 + version = re.match(r'(\d\.\d\.?\d*)', version).groups()[0] 59 + else: 60 + - raise GypError("No Xcode or CLT version detected!") 61 + + version = "7.0.0" 62 + # The CLT has no build information, so we return an empty string. 63 + version_list = [version, ''] 64 + version = version_list[0]
+1
pkgs/top-level/all-packages.nix
··· 10198 10198 10199 10199 v8 = callPackage ../development/libraries/v8 { 10200 10200 inherit (python2Packages) python gyp; 10201 + cctools = darwin.cctools; 10201 10202 }; 10202 10203 10203 10204 v8_static = lowPrio (self.v8.override { static = true; });