-
-
Notifications
You must be signed in to change notification settings - Fork 236
Add zstd support for Python 3.14+ on Unix #682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| #!/usr/bin/env bash | ||
| # This Source Code Form is subject to the terms of the Mozilla Public | ||
| # License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| # file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
|
||
| set -ex | ||
|
|
||
| ROOT=`pwd` | ||
|
|
||
| export PATH=${TOOLS_PATH}/${TOOLCHAIN}/bin:${TOOLS_PATH}/host/bin:$PATH | ||
| export PREFIX="/tools/deps" | ||
|
|
||
| tar -xf zstd-${ZSTD_VERSION}.tar.gz | ||
|
|
||
| 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 | ||
| # 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_PATH}/${TOOLCHAIN}/lib/clang/*/include/*intrin.h ${TOOLS_PATH}/${TOOLCHAIN}/lib/clang/*/include/{__wmmintrin_aes.h,__wmmintrin_pclmul.h,emmintrin.h,immintrin.h,mm_malloc.h}; do | ||
| filename=$(basename "$h") | ||
| if [ -e "${TOOLS_PATH}/host/include/${filename}" ]; then | ||
| echo "warning: ${filename} already exists" | ||
| fi | ||
| cp "$h" ${TOOLS_PATH}/host/include/ | ||
| done | ||
| EXTRA_TARGET_CFLAGS="${EXTRA_TARGET_CFLAGS} -I${TOOLS_PATH}/host/include/" | ||
|
|
||
| # `qsort_r` is only available in musl 1.2.3+ but we use 1.2.2. The zstd source provides a | ||
| # fallback implementation, but they do not have a `configure`-style detection of whether | ||
| # `qsort_r` is actually available so we patch it to include a check for glibc. | ||
| patch -p1 <<EOF | ||
| diff --git a/dictBuilder/cover.c b/dictBuilder/cover.c | ||
| index 5e6e8bc..6ca72a1 100644 | ||
| --- a/dictBuilder/cover.c | ||
| +++ b/dictBuilder/cover.c | ||
| @@ -241,7 +241,7 @@ typedef struct { | ||
| unsigned d; | ||
| } COVER_ctx_t; | ||
|
|
||
| -#if !defined(_GNU_SOURCE) && !defined(__APPLE__) && !defined(_MSC_VER) | ||
| +#if !(defined(_GNU_SOURCE) && defined(__GLIBC__)) && !defined(__APPLE__) && !defined(_MSC_VER) | ||
| /* C90 only offers qsort() that needs a global context. */ | ||
| static COVER_ctx_t *g_coverCtx = NULL; | ||
| #endif | ||
| @@ -328,7 +328,7 @@ static void stableSort(COVER_ctx_t *ctx) { | ||
| qsort_r(ctx->suffix, ctx->suffixSize, sizeof(U32), | ||
| ctx, | ||
| (ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp)); | ||
| -#elif defined(_GNU_SOURCE) | ||
| +#elif defined(_GNU_SOURCE) && defined(__GLIBC__) | ||
| qsort_r(ctx->suffix, ctx->suffixSize, sizeof(U32), | ||
| (ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp), | ||
| ctx); | ||
| EOF | ||
| fi | ||
|
|
||
| CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" LDFLAGS="${EXTRA_TARGET_LDFLAGS}" make -j ${NUM_CPUS} libzstd.a | ||
| make -j ${NUM_CPUS} install-static DESTDIR=${ROOT}/out | ||
| make -j ${NUM_CPUS} install-includes DESTDIR=${ROOT}/out | ||
| make -j ${NUM_CPUS} install-pc DESTDIR=${ROOT}/out | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
python-build-standalone/cpython-unix/build-cpython.sh
Lines 410 to 422 in 13731b0
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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-clangor rolling our own.There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Things looked properly gated from the poking around I did to get this working. I don't know of explicit test coverage.