summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndrew Childs <lorne@cons.org.nz>2020-11-19 17:21:44 +0900
committerAndrew Childs <lorne@cons.org.nz>2021-05-17 00:27:00 +0900
commitcbe172fa678615c903dce18dd8680c1cc2038cd8 (patch)
tree049ef330cefe08b34524b0589311b96339372e75
parentaa3361326b8823e5726df90b495d96772b3c0702 (diff)
downloadnixpkgs-cbe172fa678615c903dce18dd8680c1cc2038cd8.tar
nixpkgs-cbe172fa678615c903dce18dd8680c1cc2038cd8.tar.gz
nixpkgs-cbe172fa678615c903dce18dd8680c1cc2038cd8.tar.bz2
nixpkgs-cbe172fa678615c903dce18dd8680c1cc2038cd8.tar.lz
nixpkgs-cbe172fa678615c903dce18dd8680c1cc2038cd8.tar.xz
nixpkgs-cbe172fa678615c903dce18dd8680c1cc2038cd8.tar.zst
nixpkgs-cbe172fa678615c903dce18dd8680c1cc2038cd8.zip
darwin.ICU: cross compilation
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/ICU/default.nix36
1 files changed, 33 insertions, 3 deletions
diff --git a/pkgs/os-specific/darwin/apple-source-releases/ICU/default.nix b/pkgs/os-specific/darwin/apple-source-releases/ICU/default.nix
index 032b1447463..f2dd63cf2de 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/ICU/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/ICU/default.nix
@@ -1,8 +1,20 @@
-{ appleDerivation, python3 }:
+{ appleDerivation, lib, stdenv, buildPackages, python3 }:
+
+let
+  formatVersionNumeric = version:
+    let
+      versionParts = lib.versions.splitVersion version;
+      major = lib.toInt (lib.elemAt versionParts 0);
+      minor = lib.toInt (lib.elemAt versionParts 1);
+      patch = if lib.length versionParts > 2 then lib.toInt (lib.elemAt versionParts 2) else 0;
+    in toString (major * 10000 + minor * 100 + patch);
+in
 
 appleDerivation {
   nativeBuildInputs = [ python3 ];
 
+  depsBuildBuild = lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) [ buildPackages.stdenv.cc ];
+
   postPatch = ''
     substituteInPlace makefile \
       --replace "/usr/bin/" "" \
@@ -26,6 +38,13 @@ appleDerivation {
       --replace "&TestMailFilterCSS" "NULL"
 
     patchShebangs icuSources
+  '' + lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) ''
+
+    # This looks like a bug in the makefile. It defines ENV_BUILDHOST to
+    # propagate the correct value of CC, CXX, etc, but has the following double
+    # expansion that results in the empty string.
+    substituteInPlace makefile \
+      --replace '$($(ENV_BUILDHOST))' '$(ENV_BUILDHOST)'
   '';
 
   # APPLE is using makefile to save its default configuration and call ./configure, so we hack makeFlags
@@ -42,8 +61,19 @@ appleDerivation {
     "DATA_LOOKUP_DIR=$(DSTROOT)$(DATA_INSTALL_DIR)"
 
     # hack to use our lower macos version
-    "MAC_OS_X_VERSION_MIN_REQUIRED=__MAC_OS_X_VERSION_MIN_REQUIRED"
-    "OSX_HOST_VERSION_MIN_STRING=$(MACOSX_DEPLOYMENT_TARGET)"
+    "MAC_OS_X_VERSION_MIN_REQUIRED=${formatVersionNumeric stdenv.hostPlatform.darwinMinVersion}"
+    "ICU_TARGET_VERSION=-m${stdenv.hostPlatform.darwinPlatform}-version-min=${stdenv.hostPlatform.darwinMinVersion}"
+  ]
+  ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
+    "CROSS_BUILD=YES"
+    "BUILD_TYPE="
+    "RC_ARCHS=${stdenv.hostPlatform.darwinArch}"
+    "HOSTCC=cc"
+    "HOSTCXX=c++"
+    "CC=${stdenv.cc.targetPrefix}cc"
+    "CXX=${stdenv.cc.targetPrefix}c++"
+    "HOSTISYSROOT="
+    "OSX_HOST_VERSION_MIN_STRING=${stdenv.buildPlatform.darwinMinVersion}"
   ];
 
   doCheck = true;