Skip to content

Conversation

@zanieb
Copy link
Member

@zanieb zanieb commented Jul 3, 2025

This task was deferred from the initial Python 3.14 support. There's already support on Windows.

@zanieb zanieb added platform:darwin Specific to the macOS platform platform:linux Specific to the Linux platform python:3.14 labels Jul 3, 2025
@zanieb

This comment was marked as outdated.

@zanieb

This comment was marked as outdated.

@zanieb zanieb force-pushed the zb/zstd branch 3 times, most recently from 8c6ba15 to 1e20c6f Compare July 3, 2025 15:56
@zanieb zanieb changed the title Add zstd support on Unix Add zstd support for Python 3.14+ on Unix Jul 3, 2025
@zanieb zanieb force-pushed the zb/zstd branch 7 times, most recently from 0d98044 to c0ee532 Compare July 3, 2025 17:59
@zanieb zanieb force-pushed the zb/zstd branch 5 times, most recently from 79e21bd to a294ae1 Compare July 3, 2025 19:21
@zanieb zanieb removed platform:darwin Specific to the macOS platform python:3.13 labels Jul 3, 2025
@zanieb zanieb force-pushed the zb/zstd branch 5 times, most recently from c02be2c to 0ef4ea9 Compare July 3, 2025 23:17
@indygreg
Copy link
Collaborator

indygreg commented Jul 4, 2025

@Cyan4973 there is a musl workaround patch in this PR that may interest you.

Our build environment is quite esoteric though (clang on ancient Debian), so please apply scrutiny.

@zanieb zanieb added platform:darwin Specific to the macOS platform python:3.13 and removed libc:musl labels Jul 4, 2025
pushd cpython-source-deps-zstd-${ZSTD_VERSION}/lib

if [ "${CC}" = "musl-clang" ]; then
# In order to build the library with SSE2, BMI, and AVX2 intrinstics, we need musl-clang to find
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is modeled off of

# In order to build the _blake2 extension module with SSE3+ instructions, we need
# musl-clang to find headers that provide access to the intrinsics, as they are not
# provided by musl. These are part of the include files that are part of clang.
# But musl-clang eliminates them from the default include path. So copy them into
# place.
for h in /tools/${TOOLCHAIN}/lib/clang/*/include/*intrin.h /tools/${TOOLCHAIN}/lib/clang/*/include/{__wmmintrin_aes.h,__wmmintrin_pclmul.h,mm_malloc.h,cpuid.h}; do
filename=$(basename "$h")
if [ -e "/tools/host/include/${filename}" ]; then
echo "${filename} already exists; don't need to copy!"
exit 1
fi
cp "$h" /tools/host/include/
done

Copy link
Member Author

@zanieb zanieb Jul 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annoyingly, I didn't realize this was the problem until I was pretty far in. We might want to generalize this at some point, e.g., by fixing musl-clang or rolling our own.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I've been wanting to do that, filed #684.

On a separate note - I assume zstd is smart enough to correctly detect availability of the intrinsics and we don't need to patch these out for x86-64-v1? I guess put another way, do we have tests that our x86-64-v1 builds don't include things that aren't supported on that microarch? If not we should add some (either with objdump or I think qemu can do it with machine options).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume zstd is smart enough to correctly detect availability of the intrinsics and we don't need to patch these out for x86-64-v1?

Things looked properly gated from the poking around I did to get this working. I don't know of explicit test coverage.

@zanieb zanieb marked this pull request as ready for review July 4, 2025 02:29
Copy link
Collaborator

@geofft geofft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :shipit:

pushd cpython-source-deps-zstd-${ZSTD_VERSION}/lib

if [ "${CC}" = "musl-clang" ]; then
# In order to build the library with SSE2, BMI, and AVX2 intrinstics, we need musl-clang to find
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I've been wanting to do that, filed #684.

On a separate note - I assume zstd is smart enough to correctly detect availability of the intrinsics and we don't need to patch these out for x86-64-v1? I guess put another way, do we have tests that our x86-64-v1 builds don't include things that aren't supported on that microarch? If not we should add some (either with objdump or I think qemu can do it with machine options).

done
EXTRA_TARGET_CFLAGS="${EXTRA_TARGET_CFLAGS} -I${TOOLS_PATH}/host/include/"

# `qsort_r` is not available in musl and the zstd source provides a fallback implementation, but
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's in 1.2.3, but I guess we're on 1.2.2 for compatibility with older systems of some sort?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's funny. Yeah we're on the oldest version we can use for compatibility with old systems since we dynamically link now. We can probably upgrade at some point though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll update that comment.

@geofft
Copy link
Collaborator

geofft commented Jul 4, 2025

I guess the trouble here is that musl (intentionally) does not expose any sort of version information in headers, and so if you want to figure out whether the target musl supports qsort_r, then you have to do ./configure-style feature detection, and zstd (understandably) doesn't do that and only has a Makefile that you run directly. So I'm not actually sure there's anything I'd advocate changing in zstd upstream.

@zanieb zanieb added the ci:skip label Jul 4, 2025
@zanieb zanieb merged commit aaf6022 into main Jul 5, 2025
10 checks passed
@zanieb zanieb deleted the zb/zstd branch July 5, 2025 16:23
@dtrodrigues dtrodrigues mentioned this pull request Jul 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:skip platform:darwin Specific to the macOS platform platform:linux Specific to the Linux platform python:3.13 python:3.14

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants