diff --git a/pkgs/esp-idf/tools.nix b/pkgs/esp-idf/tools.nix index 80e665f..d4d4fb3 100644 --- a/pkgs/esp-idf/tools.nix +++ b/pkgs/esp-idf/tools.nix @@ -4,7 +4,7 @@ , stdenv , lib , fetchurl -, makeWrapper +, makeBinaryWrapper , autoPatchelfHook # Dependencies for the various binary tools. @@ -14,12 +14,16 @@ , glibc , ncurses5 , python3 -, python310 -, python311 -, python312 , libxml2_13 }: +let + required-python-version = "3.9"; + ESP-IDF-version = lib.removePrefix "esp-idf-" versionSuffix; +in +assert lib.assertMsg (lib.versionAtLeast python3.version required-python-version) + "ESP-IDF ${ESP-IDF-version} requires Python ≧${required-python-version}"; + let # Map nix system strings to the platforms listed in tools.json systemToToolPlatformString = { @@ -38,9 +42,6 @@ let libusb1 udev python3 - python310 - python311 - python312 libxml2_13 ]; @@ -98,18 +99,9 @@ let inherit url sha256; }; - nativeBuildInputs = [ makeWrapper ] ++ lib.optionals stdenv.isLinux [ autoPatchelfHook ]; + nativeBuildInputs = [ makeBinaryWrapper ] ++ lib.optionals stdenv.isLinux [ autoPatchelfHook ]; buildInputs = lib.optionals stdenv.isLinux runtimeDeps; - # Configure autoPatchelfHook to ignore missing Python libraries that aren't available - autoPatchelfIgnoreMissingDeps = [ - "libpython3.13.so.1.0" - "libpython3.9.so.1.0" - "libpython3.8.so.1.0" - "libpython3.7.so.1.0" - "libpython3.6.so.1.0" - ]; - phases = [ "unpackPhase" "installPhase" ] ++ lib.optionals stdenv.isLinux [ "fixupPhase" ]; setSourceRoot = ''sourceRoot=$(echo ./${lib.strings.replicate stripContainerDirs "*/"})''; @@ -124,6 +116,10 @@ let dontStrip = true; installPhase = '' + python_lib="$(find "${lib.getLib python3}/lib" -maxdepth 1 -name 'libpython*.so.*' -type f | head -n1)" + so_name="$(patchelf --print-soname "$python_lib")" + export so_name + cp -r . $out rm $out/.attrs.* @@ -136,12 +132,16 @@ let bindir=unwrapped_bin fi if [ -d "$out/$bindir" ]; then - for file in $out/$bindir/*; do - if [ -f "$file" ] && [ -x "$file" ]; then - wrapper_file="$out/bin/$(basename "$file")" - [ -d "$out/bin" ] || mkdir -p "$out/bin" - makeWrapper "$file" "$wrapper_file" ${lib.strings.concatStringsSep " " exportVarsWrapperArgsList} + for file in $(find "$out/$bindir" -type f -executable -maxdepth 1); do + libpython_so=$(patchelf --print-needed "$file" | grep -e "^libpython" || true) + if [ -n "$libpython_so" ] && [ "$libpython_so" != "$so_name" ]; then + echo "Removing $file" >&2 + rm "$file" + continue fi + wrapper_file="$out/bin/$(basename "$file")" + [ -d "$out/bin" ] || mkdir -p "$out/bin" + makeBinaryWrapper "$file" "$wrapper_file" ${lib.strings.concatStringsSep " " exportVarsWrapperArgsList} done fi done