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