Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions pkgs/esp-idf/tools.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
, stdenv
, lib
, fetchurl
, makeWrapper
, makeBinaryWrapper
, autoPatchelfHook

# Dependencies for the various binary tools.
Expand All @@ -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 = {
Expand All @@ -38,9 +42,6 @@ let
libusb1
udev
python3
python310
python311
python312
libxml2_13
];

Expand Down Expand Up @@ -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 "*/"})'';
Expand All @@ -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.*

Expand All @@ -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
Expand Down