Skip to content

Commit a7a044b

Browse files
committed
feat: enhance launcher and packing-initializer scripts for improved functionality
- Updated the launcher to prefer the most-specific binary when searching for executables. - Improved pip detection to match specific cases and avoid false positives. - Added a shebang rewriter function in packing-initializer to update script shebangs for compatibility with the new Python launcher. - Refactored RPATH patching to compute paths directly, ensuring correctness regardless of directory structure changes.
1 parent 277102c commit a7a044b

11 files changed

Lines changed: 457 additions & 62 deletions

File tree

3.10/x86/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,17 @@ FROM musl_builder AS launcher_builder
117117
ENV MUSL_ARCH=i386
118118
WORKDIR /src
119119
COPY ["common/build/wrappers/launcher.c", "./launcher.c"]
120+
# config.mak carries `MUSL_VER = X.Y.Z`; drop the patch component and bake
121+
# `X.Y` into the launcher as MUSL_VERSION so the site hook can hand pip the
122+
# matching `musllinux_X_Y_*` wheel tag without subprocess'ing ld.so every
123+
# Python startup.
120124
RUN set -eux && \
125+
MUSL_VER=$(awk -F'=' '/^MUSL_VER[[:space:]]*=/ { gsub(/[[:space:]]/, "", $2); print $2 }' /src/config.mak) && \
126+
MUSL_TAG=$(echo "$MUSL_VER" | cut -d. -f1,2) && \
127+
test -n "$MUSL_TAG" && \
121128
/opt/musl/bin/${MUSL_ARCH}-linux-musl-gcc -static -Os -s \
122129
-DMUSL_ARCH="\"${MUSL_ARCH}\"" \
130+
-DMUSL_VERSION="\"${MUSL_TAG}\"" \
123131
launcher.c -o launcher && \
124132
file launcher
125133

@@ -152,6 +160,14 @@ COPY --from=musl_builder /opt/musl /opt/musl
152160
COPY ["common/build/wrappers/rpath-patcher.sh", "."]
153161
RUN set -eux && ./rpath-patcher.sh
154162

163+
# Site-level hook that tells pip/packaging the shipped libc is musl so wheel
164+
# resolution picks `musllinux_*` wheels instead of glibc-built manylinux
165+
# wheels. Runs on every Python startup via the .pth but is a no-op unless
166+
# the launcher has set _STANDALONE_PYTHON_MUSL_VERSION in the env.
167+
COPY ["common/build/wrappers/standalone_python_musl.py", \
168+
"common/build/wrappers/standalone_python_musl.pth", \
169+
"/opt/python/lib/python3.10/site-packages/"]
170+
155171
# =========== final ===========
156172
FROM --platform=linux/386 debian:latest AS final
157173
ARG DEBIAN_FRONTEND=noninteractive

3.10/x86_64/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,17 @@ FROM musl_builder AS launcher_builder
117117
ENV MUSL_ARCH=x86_64
118118
WORKDIR /src
119119
COPY ["common/build/wrappers/launcher.c", "./launcher.c"]
120+
# config.mak carries `MUSL_VER = X.Y.Z`; drop the patch component and bake
121+
# `X.Y` into the launcher as MUSL_VERSION so the site hook can hand pip the
122+
# matching `musllinux_X_Y_*` wheel tag without subprocess'ing ld.so every
123+
# Python startup.
120124
RUN set -eux && \
125+
MUSL_VER=$(awk -F'=' '/^MUSL_VER[[:space:]]*=/ { gsub(/[[:space:]]/, "", $2); print $2 }' /src/config.mak) && \
126+
MUSL_TAG=$(echo "$MUSL_VER" | cut -d. -f1,2) && \
127+
test -n "$MUSL_TAG" && \
121128
/opt/musl/bin/${MUSL_ARCH}-linux-musl-gcc -static -Os -s \
122129
-DMUSL_ARCH="\"${MUSL_ARCH}\"" \
130+
-DMUSL_VERSION="\"${MUSL_TAG}\"" \
123131
launcher.c -o launcher && \
124132
file launcher
125133

@@ -152,6 +160,14 @@ COPY --from=musl_builder /opt/musl /opt/musl
152160
COPY ["common/build/wrappers/rpath-patcher.sh", "."]
153161
RUN set -eux && ./rpath-patcher.sh
154162

163+
# Site-level hook that tells pip/packaging the shipped libc is musl so wheel
164+
# resolution picks `musllinux_*` wheels instead of glibc-built manylinux
165+
# wheels. Runs on every Python startup via the .pth but is a no-op unless
166+
# the launcher has set _STANDALONE_PYTHON_MUSL_VERSION in the env.
167+
COPY ["common/build/wrappers/standalone_python_musl.py", \
168+
"common/build/wrappers/standalone_python_musl.pth", \
169+
"/opt/python/lib/python3.10/site-packages/"]
170+
155171
# =========== final ===========
156172
FROM --platform=linux/amd64 debian:latest AS final
157173
ARG DEBIAN_FRONTEND=noninteractive

3.11/x86/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,17 @@ FROM musl_builder AS launcher_builder
117117
ENV MUSL_ARCH=i386
118118
WORKDIR /src
119119
COPY ["common/build/wrappers/launcher.c", "./launcher.c"]
120+
# config.mak carries `MUSL_VER = X.Y.Z`; drop the patch component and bake
121+
# `X.Y` into the launcher as MUSL_VERSION so the site hook can hand pip the
122+
# matching `musllinux_X_Y_*` wheel tag without subprocess'ing ld.so every
123+
# Python startup.
120124
RUN set -eux && \
125+
MUSL_VER=$(awk -F'=' '/^MUSL_VER[[:space:]]*=/ { gsub(/[[:space:]]/, "", $2); print $2 }' /src/config.mak) && \
126+
MUSL_TAG=$(echo "$MUSL_VER" | cut -d. -f1,2) && \
127+
test -n "$MUSL_TAG" && \
121128
/opt/musl/bin/${MUSL_ARCH}-linux-musl-gcc -static -Os -s \
122129
-DMUSL_ARCH="\"${MUSL_ARCH}\"" \
130+
-DMUSL_VERSION="\"${MUSL_TAG}\"" \
123131
launcher.c -o launcher && \
124132
file launcher
125133

@@ -152,6 +160,14 @@ COPY --from=musl_builder /opt/musl /opt/musl
152160
COPY ["common/build/wrappers/rpath-patcher.sh", "."]
153161
RUN set -eux && ./rpath-patcher.sh
154162

163+
# Site-level hook that tells pip/packaging the shipped libc is musl so wheel
164+
# resolution picks `musllinux_*` wheels instead of glibc-built manylinux
165+
# wheels. Runs on every Python startup via the .pth but is a no-op unless
166+
# the launcher has set _STANDALONE_PYTHON_MUSL_VERSION in the env.
167+
COPY ["common/build/wrappers/standalone_python_musl.py", \
168+
"common/build/wrappers/standalone_python_musl.pth", \
169+
"/opt/python/lib/python3.11/site-packages/"]
170+
155171
# =========== final ===========
156172
FROM --platform=linux/386 debian:latest AS final
157173
ARG DEBIAN_FRONTEND=noninteractive

3.11/x86_64/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,17 @@ FROM musl_builder AS launcher_builder
117117
ENV MUSL_ARCH=x86_64
118118
WORKDIR /src
119119
COPY ["common/build/wrappers/launcher.c", "./launcher.c"]
120+
# config.mak carries `MUSL_VER = X.Y.Z`; drop the patch component and bake
121+
# `X.Y` into the launcher as MUSL_VERSION so the site hook can hand pip the
122+
# matching `musllinux_X_Y_*` wheel tag without subprocess'ing ld.so every
123+
# Python startup.
120124
RUN set -eux && \
125+
MUSL_VER=$(awk -F'=' '/^MUSL_VER[[:space:]]*=/ { gsub(/[[:space:]]/, "", $2); print $2 }' /src/config.mak) && \
126+
MUSL_TAG=$(echo "$MUSL_VER" | cut -d. -f1,2) && \
127+
test -n "$MUSL_TAG" && \
121128
/opt/musl/bin/${MUSL_ARCH}-linux-musl-gcc -static -Os -s \
122129
-DMUSL_ARCH="\"${MUSL_ARCH}\"" \
130+
-DMUSL_VERSION="\"${MUSL_TAG}\"" \
123131
launcher.c -o launcher && \
124132
file launcher
125133

@@ -152,6 +160,14 @@ COPY --from=musl_builder /opt/musl /opt/musl
152160
COPY ["common/build/wrappers/rpath-patcher.sh", "."]
153161
RUN set -eux && ./rpath-patcher.sh
154162

163+
# Site-level hook that tells pip/packaging the shipped libc is musl so wheel
164+
# resolution picks `musllinux_*` wheels instead of glibc-built manylinux
165+
# wheels. Runs on every Python startup via the .pth but is a no-op unless
166+
# the launcher has set _STANDALONE_PYTHON_MUSL_VERSION in the env.
167+
COPY ["common/build/wrappers/standalone_python_musl.py", \
168+
"common/build/wrappers/standalone_python_musl.pth", \
169+
"/opt/python/lib/python3.11/site-packages/"]
170+
155171
# =========== final ===========
156172
FROM --platform=linux/amd64 debian:latest AS final
157173
ARG DEBIAN_FRONTEND=noninteractive

3.12/x86/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,17 @@ FROM musl_builder AS launcher_builder
117117
ENV MUSL_ARCH=i386
118118
WORKDIR /src
119119
COPY ["common/build/wrappers/launcher.c", "./launcher.c"]
120+
# config.mak carries `MUSL_VER = X.Y.Z`; drop the patch component and bake
121+
# `X.Y` into the launcher as MUSL_VERSION so the site hook can hand pip the
122+
# matching `musllinux_X_Y_*` wheel tag without subprocess'ing ld.so every
123+
# Python startup.
120124
RUN set -eux && \
125+
MUSL_VER=$(awk -F'=' '/^MUSL_VER[[:space:]]*=/ { gsub(/[[:space:]]/, "", $2); print $2 }' /src/config.mak) && \
126+
MUSL_TAG=$(echo "$MUSL_VER" | cut -d. -f1,2) && \
127+
test -n "$MUSL_TAG" && \
121128
/opt/musl/bin/${MUSL_ARCH}-linux-musl-gcc -static -Os -s \
122129
-DMUSL_ARCH="\"${MUSL_ARCH}\"" \
130+
-DMUSL_VERSION="\"${MUSL_TAG}\"" \
123131
launcher.c -o launcher && \
124132
file launcher
125133

@@ -152,6 +160,14 @@ COPY --from=musl_builder /opt/musl /opt/musl
152160
COPY ["common/build/wrappers/rpath-patcher.sh", "."]
153161
RUN set -eux && ./rpath-patcher.sh
154162

163+
# Site-level hook that tells pip/packaging the shipped libc is musl so wheel
164+
# resolution picks `musllinux_*` wheels instead of glibc-built manylinux
165+
# wheels. Runs on every Python startup via the .pth but is a no-op unless
166+
# the launcher has set _STANDALONE_PYTHON_MUSL_VERSION in the env.
167+
COPY ["common/build/wrappers/standalone_python_musl.py", \
168+
"common/build/wrappers/standalone_python_musl.pth", \
169+
"/opt/python/lib/python3.12/site-packages/"]
170+
155171
# =========== final ===========
156172
FROM --platform=linux/386 debian:latest AS final
157173
ARG DEBIAN_FRONTEND=noninteractive

3.12/x86_64/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,17 @@ FROM musl_builder AS launcher_builder
117117
ENV MUSL_ARCH=x86_64
118118
WORKDIR /src
119119
COPY ["common/build/wrappers/launcher.c", "./launcher.c"]
120+
# config.mak carries `MUSL_VER = X.Y.Z`; drop the patch component and bake
121+
# `X.Y` into the launcher as MUSL_VERSION so the site hook can hand pip the
122+
# matching `musllinux_X_Y_*` wheel tag without subprocess'ing ld.so every
123+
# Python startup.
120124
RUN set -eux && \
125+
MUSL_VER=$(awk -F'=' '/^MUSL_VER[[:space:]]*=/ { gsub(/[[:space:]]/, "", $2); print $2 }' /src/config.mak) && \
126+
MUSL_TAG=$(echo "$MUSL_VER" | cut -d. -f1,2) && \
127+
test -n "$MUSL_TAG" && \
121128
/opt/musl/bin/${MUSL_ARCH}-linux-musl-gcc -static -Os -s \
122129
-DMUSL_ARCH="\"${MUSL_ARCH}\"" \
130+
-DMUSL_VERSION="\"${MUSL_TAG}\"" \
123131
launcher.c -o launcher && \
124132
file launcher
125133

@@ -152,6 +160,14 @@ COPY --from=musl_builder /opt/musl /opt/musl
152160
COPY ["common/build/wrappers/rpath-patcher.sh", "."]
153161
RUN set -eux && ./rpath-patcher.sh
154162

163+
# Site-level hook that tells pip/packaging the shipped libc is musl so wheel
164+
# resolution picks `musllinux_*` wheels instead of glibc-built manylinux
165+
# wheels. Runs on every Python startup via the .pth but is a no-op unless
166+
# the launcher has set _STANDALONE_PYTHON_MUSL_VERSION in the env.
167+
COPY ["common/build/wrappers/standalone_python_musl.py", \
168+
"common/build/wrappers/standalone_python_musl.pth", \
169+
"/opt/python/lib/python3.12/site-packages/"]
170+
155171
# =========== final ===========
156172
FROM --platform=linux/amd64 debian:latest AS final
157173
ARG DEBIAN_FRONTEND=noninteractive

0 commit comments

Comments
 (0)