nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix

python311: fix cross to/from musl (#260641)

The situation:

Python <3.11: under Linux the abi string is always -gnu*

Python 3.11-3.12: musl is treated as its own abi in the python build system, but when cross-compiling the build host's libc is used for the target abi string. Cross compiling from glibc to musl gives a -gnu* target abi string and vice versa.

Python >=3.13: musl is treated as its own abi, and when cross-compiling the target libc is used for the target abi string

We backport the fix for python 3.11-3.12, since the intermediate state is almost impossible to model in the nix expression

authored by

Yureka and committed by
GitHub
ef60280d 108f00ea

+299 -1
+4 -1
pkgs/development/interpreters/python/cpython/default.nix
··· 302 302 ./3.8/0001-On-all-posix-systems-not-just-Darwin-set-LDSHARED-if.patch 303 303 # Use sysconfigdata to find headers. Fixes cross-compilation of extension modules. 304 304 ./3.7/fix-finding-headers-when-cross-compiling.patch 305 - ] ++ optionals stdenv.hostPlatform.isLoongArch64 [ 305 + ] ++ optionals (pythonOlder "3.12") [ 306 306 # https://github.com/python/cpython/issues/90656 307 307 ./loongarch-support.patch 308 + ] ++ optionals (pythonAtLeast "3.11" && pythonOlder "3.13") [ 309 + # backport fix for https://github.com/python/cpython/issues/95855 310 + ./platform-triplet-detection.patch 308 311 ] ++ optionals (stdenv.hostPlatform.isMinGW) (let 309 312 # https://src.fedoraproject.org/rpms/mingw-python3 310 313 mingw-patch = fetchgit {
+295
pkgs/development/interpreters/python/cpython/platform-triplet-detection.patch
··· 1 + diff --git a/configure.ac b/configure.ac 2 + index ba768aea93..621ac166bd 100644 3 + --- a/configure.ac 4 + +++ b/configure.ac 5 + @@ -936,125 +936,192 @@ cat > conftest.c <<EOF 6 + #if defined(__ANDROID__) 7 + # Android is not a multiarch system. 8 + #elif defined(__linux__) 9 + +# include <features.h> 10 + +# if defined(__UCLIBC__) 11 + +# error uclibc not supported 12 + +# elif defined(__dietlibc__) 13 + +# error dietlibc not supported 14 + +# elif defined(__GLIBC__) 15 + +# define LIBC gnu 16 + +# define LIBC_X32 gnux32 17 + +# if defined(__ARM_PCS_VFP) 18 + +# define LIBC_ARM gnueabihf 19 + +# else 20 + +# define LIBC_ARM gnueabi 21 + +# endif 22 + +# if defined(__loongarch__) 23 + +# if defined(__loongarch_soft_float) 24 + +# define LIBC_LA gnusf 25 + +# elif defined(__loongarch_single_float) 26 + +# define LIBC_LA gnuf32 27 + +# elif defined(__loongarch_double_float) 28 + +# define LIBC_LA gnu 29 + +# else 30 + +# error unknown loongarch floating-point base abi 31 + +# endif 32 + +# endif 33 + +# if defined(_MIPS_SIM) 34 + +# if defined(__mips_hard_float) 35 + +# if _MIPS_SIM == _ABIO32 36 + +# define LIBC_MIPS gnu 37 + +# elif _MIPS_SIM == _ABIN32 38 + +# define LIBC_MIPS gnuabin32 39 + +# elif _MIPS_SIM == _ABI64 40 + +# define LIBC_MIPS gnuabi64 41 + +# else 42 + +# error unknown mips sim value 43 + +# endif 44 + +# else 45 + +# if _MIPS_SIM == _ABIO32 46 + +# define LIBC_MIPS gnusf 47 + +# elif _MIPS_SIM == _ABIN32 48 + +# define LIBC_MIPS gnuabin32sf 49 + +# elif _MIPS_SIM == _ABI64 50 + +# define LIBC_MIPS gnuabi64sf 51 + +# else 52 + +# error unknown mips sim value 53 + +# endif 54 + +# endif 55 + +# endif 56 + +# if defined(__SPE__) 57 + +# define LIBC_PPC gnuspe 58 + +# else 59 + +# define LIBC_PPC gnu 60 + +# endif 61 + +# else 62 + +# include <stdarg.h> 63 + +# ifdef __DEFINED_va_list 64 + +# define LIBC musl 65 + +# define LIBC_X32 muslx32 66 + +# if defined(__ARM_PCS_VFP) 67 + +# define LIBC_ARM musleabihf 68 + +# else 69 + +# define LIBC_ARM musleabi 70 + +# endif 71 + +# if defined(__loongarch__) 72 + +# if defined(__loongarch_soft_float) 73 + +# define LIBC_LA muslsf 74 + +# elif defined(__loongarch_single_float) 75 + +# define LIBC_LA muslf32 76 + +# elif defined(__loongarch_double_float) 77 + +# define LIBC_LA musl 78 + +# else 79 + +# error unknown loongarch floating-point base abi 80 + +# endif 81 + +# endif 82 + +# if defined(_MIPS_SIM) 83 + +# if defined(__mips_hard_float) 84 + +# if _MIPS_SIM == _ABIO32 85 + +# define LIBC_MIPS musl 86 + +# elif _MIPS_SIM == _ABIN32 87 + +# define LIBC_MIPS musln32 88 + +# elif _MIPS_SIM == _ABI64 89 + +# define LIBC_MIPS musl 90 + +# else 91 + +# error unknown mips sim value 92 + +# endif 93 + +# else 94 + +# if _MIPS_SIM == _ABIO32 95 + +# define LIBC_MIPS muslsf 96 + +# elif _MIPS_SIM == _ABIN32 97 + +# define LIBC_MIPS musln32sf 98 + +# elif _MIPS_SIM == _ABI64 99 + +# define LIBC_MIPS muslsf 100 + +# else 101 + +# error unknown mips sim value 102 + +# endif 103 + +# endif 104 + +# endif 105 + +# if defined(_SOFT_FLOAT) || defined(__NO_FPRS__) 106 + +# define LIBC_PPC muslsf 107 + +# else 108 + +# define LIBC_PPC musl 109 + +# endif 110 + +# else 111 + +# error unknown libc 112 + +# endif 113 + +# endif 114 + # if defined(__x86_64__) && defined(__LP64__) 115 + - x86_64-linux-gnu 116 + + x86_64-linux-LIBC 117 + # elif defined(__x86_64__) && defined(__ILP32__) 118 + - x86_64-linux-gnux32 119 + + x86_64-linux-LIBC_X32 120 + # elif defined(__i386__) 121 + - i386-linux-gnu 122 + + i386-linux-LIBC 123 + # elif defined(__aarch64__) && defined(__AARCH64EL__) 124 + # if defined(__ILP32__) 125 + - aarch64_ilp32-linux-gnu 126 + + aarch64_ilp32-linux-LIBC 127 + # else 128 + - aarch64-linux-gnu 129 + + aarch64-linux-LIBC 130 + # endif 131 + # elif defined(__aarch64__) && defined(__AARCH64EB__) 132 + # if defined(__ILP32__) 133 + - aarch64_be_ilp32-linux-gnu 134 + + aarch64_be_ilp32-linux-LIBC 135 + # else 136 + - aarch64_be-linux-gnu 137 + + aarch64_be-linux-LIBC 138 + # endif 139 + # elif defined(__alpha__) 140 + - alpha-linux-gnu 141 + -# elif defined(__ARM_EABI__) && defined(__ARM_PCS_VFP) 142 + + alpha-linux-LIBC 143 + +# elif defined(__ARM_EABI__) 144 + # if defined(__ARMEL__) 145 + - arm-linux-gnueabihf 146 + + arm-linux-LIBC_ARM 147 + # else 148 + - armeb-linux-gnueabihf 149 + -# endif 150 + -# elif defined(__ARM_EABI__) && !defined(__ARM_PCS_VFP) 151 + -# if defined(__ARMEL__) 152 + - arm-linux-gnueabi 153 + -# else 154 + - armeb-linux-gnueabi 155 + + armeb-linux-LIBC_ARM 156 + # endif 157 + # elif defined(__hppa__) 158 + - hppa-linux-gnu 159 + + hppa-linux-LIBC 160 + # elif defined(__ia64__) 161 + - ia64-linux-gnu 162 + -# elif defined(__loongarch__) 163 + -# if defined(__loongarch_lp64) 164 + -# if defined(__loongarch_soft_float) 165 + - loongarch64-linux-gnusf 166 + -# elif defined(__loongarch_single_float) 167 + - loongarch64-linux-gnuf32 168 + -# elif defined(__loongarch_double_float) 169 + - loongarch64-linux-gnu 170 + + ia64-linux-LIBC 171 + +# elif defined(__loongarch__) && defined(__loongarch_lp64) 172 + + loongarch64-linux-LIBC_LA 173 + +# elif defined(__m68k__) && !defined(__mcoldfire__) 174 + + m68k-linux-LIBC 175 + +# elif defined(__mips__) 176 + +# if defined(__mips_isa_rev) && (__mips_isa_rev >=6) 177 + +# if defined(_MIPSEL) && defined(__mips64) 178 + + mipsisa64r6el-linux-LIBC_MIPS 179 + +# elif defined(_MIPSEL) 180 + + mipsisa32r6el-linux-LIBC_MIPS 181 + +# elif defined(__mips64) 182 + + mipsisa64r6-linux-LIBC_MIPS 183 + # else 184 + -# error unknown platform triplet 185 + + mipsisa32r6-linux-LIBC_MIPS 186 + # endif 187 + # else 188 + -# error unknown platform triplet 189 + -# endif 190 + -# elif defined(__m68k__) && !defined(__mcoldfire__) 191 + - m68k-linux-gnu 192 + -# elif defined(__mips_hard_float) && defined(__mips_isa_rev) && (__mips_isa_rev >=6) && defined(_MIPSEL) 193 + -# if _MIPS_SIM == _ABIO32 194 + - mipsisa32r6el-linux-gnu 195 + -# elif _MIPS_SIM == _ABIN32 196 + - mipsisa64r6el-linux-gnuabin32 197 + -# elif _MIPS_SIM == _ABI64 198 + - mipsisa64r6el-linux-gnuabi64 199 + -# else 200 + -# error unknown platform triplet 201 + -# endif 202 + -# elif defined(__mips_hard_float) && defined(__mips_isa_rev) && (__mips_isa_rev >=6) 203 + -# if _MIPS_SIM == _ABIO32 204 + - mipsisa32r6-linux-gnu 205 + -# elif _MIPS_SIM == _ABIN32 206 + - mipsisa64r6-linux-gnuabin32 207 + -# elif _MIPS_SIM == _ABI64 208 + - mipsisa64r6-linux-gnuabi64 209 + -# else 210 + -# error unknown platform triplet 211 + -# endif 212 + -# elif defined(__mips_hard_float) && defined(_MIPSEL) 213 + -# if _MIPS_SIM == _ABIO32 214 + - mipsel-linux-gnu 215 + -# elif _MIPS_SIM == _ABIN32 216 + - mips64el-linux-gnuabin32 217 + -# elif _MIPS_SIM == _ABI64 218 + - mips64el-linux-gnuabi64 219 + -# else 220 + -# error unknown platform triplet 221 + -# endif 222 + -# elif defined(__mips_hard_float) 223 + -# if _MIPS_SIM == _ABIO32 224 + - mips-linux-gnu 225 + -# elif _MIPS_SIM == _ABIN32 226 + - mips64-linux-gnuabin32 227 + -# elif _MIPS_SIM == _ABI64 228 + - mips64-linux-gnuabi64 229 + -# else 230 + -# error unknown platform triplet 231 + +# if defined(_MIPSEL) && defined(__mips64) 232 + + mips64el-linux-LIBC_MIPS 233 + +# elif defined(_MIPSEL) 234 + + mipsel-linux-LIBC_MIPS 235 + +# elif defined(__mips64) 236 + + mips64-linux-LIBC_MIPS 237 + +# else 238 + + mips-linux-LIBC_MIPS 239 + +# endif 240 + # endif 241 + # elif defined(__or1k__) 242 + - or1k-linux-gnu 243 + -# elif defined(__powerpc__) && defined(__SPE__) 244 + - powerpc-linux-gnuspe 245 + + or1k-linux-LIBC 246 + # elif defined(__powerpc64__) 247 + # if defined(__LITTLE_ENDIAN__) 248 + - powerpc64le-linux-gnu 249 + + powerpc64le-linux-LIBC 250 + # else 251 + - powerpc64-linux-gnu 252 + + powerpc64-linux-LIBC 253 + # endif 254 + # elif defined(__powerpc__) 255 + - powerpc-linux-gnu 256 + + powerpc-linux-LIBC_PPC 257 + # elif defined(__s390x__) 258 + - s390x-linux-gnu 259 + + s390x-linux-LIBC 260 + # elif defined(__s390__) 261 + - s390-linux-gnu 262 + + s390-linux-LIBC 263 + # elif defined(__sh__) && defined(__LITTLE_ENDIAN__) 264 + - sh4-linux-gnu 265 + + sh4-linux-LIBC 266 + # elif defined(__sparc__) && defined(__arch64__) 267 + - sparc64-linux-gnu 268 + + sparc64-linux-LIBC 269 + # elif defined(__sparc__) 270 + - sparc-linux-gnu 271 + + sparc-linux-LIBC 272 + # elif defined(__riscv) 273 + # if __riscv_xlen == 32 274 + - riscv32-linux-gnu 275 + + riscv32-linux-LIBC 276 + # elif __riscv_xlen == 64 277 + - riscv64-linux-gnu 278 + + riscv64-linux-LIBC 279 + # else 280 + # error unknown platform triplet 281 + # endif 282 + @@ -1102,12 +1169,7 @@ cat > conftest.c <<EOF 283 + EOF 284 + 285 + if $CPP $CPPFLAGS conftest.c >conftest.out 2>/dev/null; then 286 + - PLATFORM_TRIPLET=`grep -v '^#' conftest.out | grep -v '^ *$' | tr -d ' '` 287 + - case "$build_os" in 288 + - linux-musl*) 289 + - PLATFORM_TRIPLET=`echo "$PLATFORM_TRIPLET" | sed 's/linux-gnu/linux-musl/'` 290 + - ;; 291 + - esac 292 + + PLATFORM_TRIPLET=`grep -v '^#' conftest.out | grep -v '^ *$' | grep -v typedef | tr -d ' '` 293 + AC_MSG_RESULT([$PLATFORM_TRIPLET]) 294 + else 295 + AC_MSG_RESULT([none])