nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at devShellTools-shell 214 lines 7.0 kB view raw
1{ 2 lib, 3 bootstrapStdenv, 4 buildPackages, 5 fetchpatch2, 6 mkAppleDerivation, 7 python3, 8 testers, 9}: 10 11# Based on: 12# - ../../../development/libraries/icu/make-icu.nix 13# - https://github.com/apple-oss-distributions/ICU/blob/main/makefile 14let 15 stdenv = bootstrapStdenv; 16 withStatic = stdenv.hostPlatform.isStatic; 17 18 # Cross-compiled icu4c requires a build-root of a native compile 19 nativeBuildRoot = buildPackages.darwin.ICU.buildRootOnly; 20 21 baseAttrs = finalAttrs: { 22 releaseName = "ICU"; 23 24 sourceRoot = "${finalAttrs.src.name}/icu/icu4c/source"; 25 26 patches = [ 27 # Skip MessageFormatTest test, which is known to crash sometimes and should be suppressed if it does. 28 ./patches/suppress-icu-check-crash.patch 29 30 # Python 3.13 compatibility 31 (fetchpatch2 { 32 url = "https://github.com/unicode-org/icu/commit/60d6bd71efc0cde8f861b109ff87dbbf9fc96586.patch?full_index=1"; 33 hash = "sha256-aJBSVvKidPUjD956jLjyRk8fewUZ9f+Ip4ka6rjevzU="; 34 stripLen = 2; 35 }) 36 ]; 37 38 preConfigure = '' 39 sed -i -e "s|/bin/sh|${stdenv.shell}|" configure 40 patchShebangs --build . 41 # $(includedir) is different from $(prefix)/include due to multiple outputs 42 sed -i -e 's|^\(CPPFLAGS = .*\) -I\$(prefix)/include|\1 -I$(includedir)|' config/Makefile.inc.in 43 ''; 44 45 dontDisableStatic = withStatic; 46 47 configureFlags = [ 48 (lib.enableFeature false "debug") 49 (lib.enableFeature false "renaming") 50 (lib.enableFeature false "extras") 51 (lib.enableFeature false "layout") 52 (lib.enableFeature false "samples") 53 ] 54 ++ lib.optionals (stdenv.hostPlatform.isFreeBSD || stdenv.hostPlatform.isDarwin) [ 55 (lib.enableFeature true "rpath") 56 ] 57 ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ 58 (lib.withFeatureAs true "cross-build" nativeBuildRoot) 59 ] 60 ++ lib.optionals withStatic [ (lib.enableFeature true "static") ]; 61 62 nativeBuildInputs = [ python3 ]; 63 64 enableParallelBuilding = true; 65 66 # Per the source-release makefile, these are enabled. 67 env.NIX_CFLAGS_COMPILE = toString [ 68 "-DU_SHOW_CPLUSPLUS_API=1" 69 "-DU_SHOW_INTERNAL_API=1" 70 ]; 71 72 passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage; 73 passthru.buildRootOnly = mkWithAttrs buildRootOnlyAttrs; 74 75 meta = { 76 description = "Unicode and globalization support library with Apple customizations"; 77 license = [ lib.licenses.icu ]; 78 teams = [ lib.teams.darwin ]; 79 platforms = lib.platforms.darwin; 80 pkgConfigModules = [ 81 "icu-i18n" 82 "icu-io" 83 "icu-uc" 84 ]; 85 }; 86 }; 87 88 realAttrs = self: super: { 89 outputs = [ 90 "out" 91 "dev" 92 ] 93 ++ lib.optional withStatic "static"; 94 outputBin = "dev"; 95 96 postPatch = lib.optionalString self.finalPackage.doCheck '' 97 # Skip test for missing encodingSamples data. 98 substituteInPlace test/cintltst/ucsdetst.c \ 99 --replace-fail "&TestMailFilterCSS" "NULL" 100 101 # Disable failing tests 102 substituteInPlace test/cintltst/cloctst.c \ 103 --replace-fail 'TESTCASE(TestCanonicalForm);' "" 104 105 substituteInPlace test/intltest/rbbitst.cpp \ 106 --replace-fail 'TESTCASE_AUTO(TestExternalBreakEngineWithFakeYue);' "" 107 108 # Otherwise `make install` is broken. 109 substituteInPlace Makefile.in \ 110 --replace-fail '$(top_srcdir)/../LICENSE' "$NIX_BUILD_TOP/source/icu/LICENSE" 111 substituteInPlace config/dist-data.sh \ 112 --replace-fail "\''${top_srcdir}/../LICENSE" "$NIX_BUILD_TOP/source/icu/LICENSE" 113 ''; 114 115 # remove dependency on bootstrap-tools in early stdenv build 116 postInstall = 117 lib.optionalString withStatic '' 118 mkdir -p $static/lib 119 mv -v lib/*.a $static/lib 120 '' 121 + lib.optionalString stdenv.hostPlatform.isDarwin '' 122 sed -i 's/INSTALL_CMD=.*install/INSTALL_CMD=install/' $out/lib/icu/*/pkgdata.inc 123 '' 124 + ( 125 let 126 replacements = [ 127 { 128 from = "\${prefix}/include"; 129 to = "${placeholder "dev"}/include"; 130 } # --cppflags-searchpath 131 { 132 from = "\${pkglibdir}/Makefile.inc"; 133 to = "${placeholder "dev"}/lib/icu/Makefile.inc"; 134 } # --incfile 135 { 136 from = "\${pkglibdir}/pkgdata.inc"; 137 to = "${placeholder "dev"}/lib/icu/pkgdata.inc"; 138 } # --incpkgdatafile 139 ]; 140 in 141 '' 142 rm $out/share/icu/*/install-sh $out/share/icu/*/mkinstalldirs # Avoid having a runtime dependency on bash 143 144 substituteInPlace "$dev/bin/icu-config" \ 145 ${lib.concatMapStringsSep " " (r: "--replace-fail '${r.from}' '${r.to}'") replacements} 146 '' 147 # Create library with everything reexported to provide the same ABI as the system ICU. 148 + lib.optionalString stdenv.hostPlatform.isDarwin ( 149 if stdenv.hostPlatform.isStatic then 150 '' 151 ${stdenv.cc.targetPrefix}ar qL "$out/lib/libicucore.a" \ 152 "$out/lib/libicuuc.a" \ 153 "$out/lib/libicudata.a" \ 154 "$out/lib/libicui18n.a" \ 155 "$out/lib/libicuio.a" 156 '' 157 else 158 '' 159 icuVersion=$(basename "$out/share/icu/"*) 160 ${stdenv.cc.targetPrefix}clang -dynamiclib \ 161 -L "$out/lib" \ 162 -Wl,-reexport-licuuc \ 163 -Wl,-reexport-licudata \ 164 -Wl,-reexport-licui18n \ 165 -Wl,-reexport-licuio \ 166 -compatibility_version 1 \ 167 -current_version "$icuVersion" \ 168 -install_name "$out/lib/libicucore.A.dylib" \ 169 -o "$out/lib/libicucore.A.dylib" 170 ln -s libicucore.A.dylib "$out/lib/libicucore.dylib" 171 '' 172 ) 173 ); 174 175 postFixup = ''moveToOutput lib/icu "$dev" ''; 176 177 doCheck = stdenv.buildPlatform.canExecute stdenv.hostPlatform; 178 179 nativeCheckInputs = [ python3 ]; 180 181 # Some tests use `log(name)`, which clang identifies as potentially insecure. 182 checkFlags = [ 183 "CFLAGS+=-Wno-format-security" 184 "CXXFLAGS+=-Wno-format-security" 185 ]; 186 checkTarget = "check"; 187 }; 188 189 buildRootOnlyAttrs = self: super: { 190 pname = "ICU-build-root"; 191 192 preConfigure = super.preConfigure + '' 193 mkdir build 194 cd build 195 configureScript=../configure 196 197 # Apples customizations require building and linking additional files, which are handled via `Makefile.local`. 198 # These need copied into the build environment to avoid link errors from not building them. 199 mkdir common i18n 200 cp ../common/Makefile.local common/Makefile.local 201 cp ../i18n/Makefile.local i18n/Makefile.local 202 ''; 203 204 postBuild = '' 205 cd .. 206 mv build $out 207 echo "Doing build-root only, exiting now" >&2 208 exit 0 209 ''; 210 }; 211 212 mkWithAttrs = attrs: mkAppleDerivation (lib.extends attrs baseAttrs); 213in 214mkWithAttrs realAttrs