klipper: fix cross runtime behavior (#512114)

This commit is contained in:
Cabia Rangris
2026-04-22 21:36:18 +00:00
committed by GitHub
+27 -10
View File
@@ -9,7 +9,9 @@
makeWrapper,
writeShellScript,
}:
let
isCross = (stdenv.hostPlatform != stdenv.buildPlatform);
in
stdenv.mkDerivation rec {
pname = "klipper";
version = "0.13.0-unstable-2026-03-21";
@@ -46,11 +48,31 @@ stdenv.mkDerivation rec {
))
];
# we need to run this to prebuild the chelper.
postBuild = ''
python ./chelper/__init__.py
# we need to run this to prebuild the chelper .so. However when cross
# compiling, a patch is temporarily required during the build process to
# prevent the build process from using dlopen() on this .so which has been
# built for a foreign architecture. We then place the unpatched __init__.py
# back, as this dlopen() call is required at runtime
postBuild =
if isCross then
''
python ./chelper/__init__.py
mv ./chelper/__init__unpatched.py ./chelper/__init__.py
''
else
''
python ./chelper/__init__.py
'';
prePatch = lib.optionalString isCross ''
cp ./chelper/__init__.py ./chelper/__init__unpatched.py
'';
patches = lib.optionals isCross [
# https://github.com/Klipper3d/klipper/pull/7254
./cross-ffi.patch
];
# Python 3 is already supported but shebangs aren't updated yet
postPatch = ''
for file in klippy.py console.py parsedump.py; do
@@ -59,15 +81,10 @@ stdenv.mkDerivation rec {
done
# needed for cross compilation
substituteInPlace ./chelper/__init__.py \
substituteInPlace ./chelper/__init__*.py \
--replace 'GCC_CMD = "gcc"' 'GCC_CMD = "${stdenv.cc.targetPrefix}cc"'
'';
patches = lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
# https://github.com/Klipper3d/klipper/pull/7254
./cross-ffi.patch
];
pythonInterpreter =
(python3.withPackages (
p: with p; [