micropython: fix cross

+89 -1
+31
pkgs/by-name/mi/micropython/fix-cross-compilation.patch
···
··· 1 + --- a/ports/unix/Makefile 2 + +++ b/ports/unix/Makefile 3 + @@ -31,7 +31,7 @@ 4 + QSTR_GLOBAL_DEPENDENCIES += $(VARIANT_DIR)/mpconfigvariant.h 5 + 6 + # OS name, for simple autoconfig 7 + -UNAME_S := $(shell uname -s) 8 + +UNAME_S := @UNAME_S@ 9 + 10 + # include py core make definitions 11 + include $(TOP)/py/py.mk 12 + @@ -151,7 +151,7 @@ 13 + # If the variant enables it, enable modbluetooth. 14 + ifeq ($(MICROPY_PY_BLUETOOTH),1) 15 + ifeq ($(MICROPY_BLUETOOTH_BTSTACK),1) 16 + -HAVE_LIBUSB := $(shell (which pkg-config > /dev/null && pkg-config --exists libusb-1.0) 2>/dev/null && echo '1') 17 + +HAVE_LIBUSB := $(shell (which @PKG_CONFIG@ > /dev/null && @PKG_CONFIG@ --exists libusb-1.0) 2>/dev/null && echo '1') 18 + 19 + # Figure out which BTstack transport to use. 20 + ifeq ($(HAVE_LIBUSB),1) 21 + @@ -180,8 +180,8 @@ 22 + endif 23 + else 24 + # Use system version of libffi. 25 + -LIBFFI_CFLAGS := $(shell pkg-config --cflags libffi) 26 + -LIBFFI_LDFLAGS := $(shell pkg-config --libs libffi) 27 + +LIBFFI_CFLAGS := $(shell @PKG_CONFIG@ --cflags libffi) 28 + +LIBFFI_LDFLAGS := $(shell @PKG_CONFIG@ --libs libffi) 29 + endif 30 + 31 + ifeq ($(UNAME_S),Linux)
+13
pkgs/by-name/mi/micropython/fix-mpy-cross-path.patch
···
··· 1 + --- a/mpy-cross/mpy_cross/__init__.py 2 + +++ b/mpy-cross/mpy_cross/__init__.py 3 + @@ -61,6 +61,10 @@ 4 + def _find_mpy_cross_binary(mpy_cross): 5 + if mpy_cross: 6 + return mpy_cross 7 + + # Check for MPY_CROSS environment variable first (for cross-compilation) 8 + + env_mpy_cross = os.environ.get("MPY_CROSS") 9 + + if env_mpy_cross: 10 + + return env_mpy_cross 11 + return os.path.abspath(os.path.join(os.path.dirname(__file__), "../build/mpy-cross")) 12 + 13 +
+45 -1
pkgs/by-name/mi/micropython/package.nix
··· 7 python3, 8 libffi, 9 readline, 10 }: 11 12 stdenv.mkDerivation rec { ··· 43 extraPrefix = "lib/mbedtls/"; 44 hash = "sha256-Sllp/iWWEhykMJ3HALw5KzR4ta22120Jcl51JZCkZE0="; 45 }) 46 ]; 47 48 nativeBuildInputs = [ ··· 58 makeFlags = [ 59 "-C" 60 "ports/unix" 61 ]; # also builds mpy-cross 62 63 enableParallelBuilding = true; 64 65 doCheck = true; ··· 87 runHook preInstall 88 mkdir -p $out/bin 89 install -Dm755 ports/unix/build-standard/micropython -t $out/bin 90 - install -Dm755 mpy-cross/build/mpy-cross -t $out/bin 91 runHook postInstall 92 ''; 93
··· 7 python3, 8 libffi, 9 readline, 10 + buildPackages, 11 }: 12 13 stdenv.mkDerivation rec { ··· 44 extraPrefix = "lib/mbedtls/"; 45 hash = "sha256-Sllp/iWWEhykMJ3HALw5KzR4ta22120Jcl51JZCkZE0="; 46 }) 47 + ./fix-cross-compilation.patch 48 + ./fix-mpy-cross-path.patch 49 + ]; 50 + 51 + postPatch = '' 52 + # Fix cross-compilation by replacing uname and pkg-config 53 + substituteInPlace ports/unix/Makefile \ 54 + --subst-var-by UNAME_S "${ 55 + { 56 + "x86_64-linux" = "Linux"; 57 + "i686-linux" = "Linux"; 58 + "aarch64-linux" = "Linux"; 59 + "armv7l-linux" = "Linux"; 60 + "armv6l-linux" = "Linux"; 61 + "riscv64-linux" = "Linux"; 62 + "powerpc64le-linux" = "Linux"; 63 + "x86_64-darwin" = "Darwin"; 64 + "aarch64-darwin" = "Darwin"; 65 + } 66 + .${stdenv.hostPlatform.system} or stdenv.hostPlatform.parsed.kernel.name 67 + }" \ 68 + --subst-var-by PKG_CONFIG "${stdenv.cc.targetPrefix}pkg-config" 69 + ''; 70 + 71 + depsBuildBuild = [ 72 + buildPackages.stdenv.cc 73 + buildPackages.python3 74 ]; 75 76 nativeBuildInputs = [ ··· 86 makeFlags = [ 87 "-C" 88 "ports/unix" 89 + "CROSS_COMPILE=${stdenv.cc.targetPrefix}" 90 + ] 91 + ++ lib.optionals (stdenv.hostPlatform.isAarch64 && stdenv.hostPlatform.isLinux) [ 92 + # Workaround for false positive gcc warning in mbedtls on aarch64 93 + "CFLAGS_EXTRA=-Wno-array-bounds" 94 ]; # also builds mpy-cross 95 96 + # Build mpy-cross for the build platform first when cross-compiling 97 + preBuild = '' 98 + # Build mpy-cross for the build platform 99 + make -C mpy-cross \ 100 + CC="${buildPackages.stdenv.cc}/bin/${buildPackages.stdenv.cc.targetPrefix}cc" \ 101 + CROSS_COMPILE="" 102 + '' 103 + + lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) '' 104 + # Set MPY_CROSS environment variable for cross-compilation 105 + export MPY_CROSS="$PWD/mpy-cross/build/mpy-cross" 106 + ''; 107 + 108 enableParallelBuilding = true; 109 110 doCheck = true; ··· 132 runHook preInstall 133 mkdir -p $out/bin 134 install -Dm755 ports/unix/build-standard/micropython -t $out/bin 135 runHook postInstall 136 ''; 137