Skip to content
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ gmon.out
.pytest_cache/
.ruff_cache/
.DS_Store
.pixi/

*.exe

Expand Down
2 changes: 2 additions & 0 deletions Tools/README
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ patchcheck Tools for checking and applying patches to the Python source cod

peg_generator PEG-based parser generator (pegen) used for new parser.

pixi-packages Pixi package definitions for downstream from-source builds
Comment thread
lucascolley marked this conversation as resolved.
Outdated

scripts A number of useful single-file programs, e.g. run_tests.py
which runs the Python test suite.

Expand Down
36 changes: 36 additions & 0 deletions Tools/pixi-packages/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## CPython Pixi Packages
Comment thread
StanFromIreland marked this conversation as resolved.
Outdated

This directory contains definitions for [Pixi packages](https://pixi.sh/latest/reference/pixi_manifest/#the-package-section)
which can be built from the CPython source code.

Downstream developers can make use of these packages by adding them as git dependencies in a
[Pixi workspace](https://pixi.sh/latest/first_workspace/), like:

```toml
[dependencies]
python = { git = "https://github.com/python/cpython", subdirectory = "Tools/pixi-packages/asan" }
```

This is particularly useful when developers need to build CPython from source
(for example, for an ASan-instrumented build), as it does not require any manual
cloning or building steps. Instead, Pixi will automatically handle both the building
and installation of the package.

Each package definition is contained in a subdirectory, but they share the build script
`build.sh` in this directory. Currently defined package variants:

- `default`
- `asan`: ASan-instrumented build with `PYTHON_ASAN=1`

### Maintenance

- the `version` fields in each `recipe.yaml` should be kept up to date with the Python version
- dependency requirements should be kept up to date in each `recipe.yaml`
- `build.sh` should be updated for any breaking changes in the `configure` and `make` workflow

### Opportunities for future improvement

- more package variants (e.g. TSan, UBSan)
- support for Windows
- using a single `pixi.toml` and `recipe.yaml` for all package variants is blocked on https://github.com/prefix-dev/pixi/issues/4599
- a workaround can be removed from the build script once https://github.com/prefix-dev/rattler-build/issues/2012 is resolved
8 changes: 8 additions & 0 deletions Tools/pixi-packages/asan/pixi.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[workspace]
channels = ["https://prefix.dev/conda-forge"]
platforms = ["osx-arm64", "linux-64"]
preview = ["pixi-build"]

[package.build.backend]
name = "pixi-build-rattler-build"
version = "*"
65 changes: 65 additions & 0 deletions Tools/pixi-packages/asan/recipe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
context:
# XXX: keep up to date
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Re: https://discuss.python.org/t/cryptic-sequences-in-comments/38694

Can we replace all the "XXX" with "TODO" or something else? Maybe we don't even need it here:

Suggested change
# XXX: keep up to date
# Keep up to date

If we do merge this, we have code in https://github.com/python/release-tools which is run during the first beta, when main becomes the next version, that updates a bunch of versions in the repo. And we can later update that to also update these versions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is there a YAML, TOML, or JSON file that contains the version @hugovk ? If not, could we add one?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There isn't. Yes we can add one, it removes duplication here, and will be easier to programmatically update such a file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

any preference for format / location / name?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry, I missed this because it was marked as resolved but I don't think it has been :)

Format: TOML or JSON, we can read using the stdlib.

Location: Tools/pixi-packages/, or Tools/ so other scripts can re-use it.

Name: Hmm, python-version.[ext] ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think it was resolved for this PR via the third paragraph of #142469 (review)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Okay, thanks!

version: "3.15"

package:
name: python
version: ${{ version }}

source:
- path: ../../..

build:
files:
exclude:
- "*.o"
script:
file: ../build.sh
env:
PYTHON_VARIANT: "asan"

# XXX: maybe not all requirements necessary
Comment thread
FFY00 marked this conversation as resolved.
Outdated
Comment thread
lucascolley marked this conversation as resolved.
Outdated
# derived from https://github.com/conda-forge/python-feedstock/blob/main/recipe/meta.yaml
requirements:
Comment thread
lucascolley marked this conversation as resolved.
Outdated
build:
- ${{ compiler('c') }}
- ${{ compiler('cxx') }}
- make
- libtool
Comment thread
lucascolley marked this conversation as resolved.
Outdated
- pkg-config
# configure script looks for llvm-ar for lto
- if: osx
then:
- llvm-tools
Comment thread
FFY00 marked this conversation as resolved.
- if: linux
then:
- ld_impl_${{ target_platform }}
- binutils_impl_${{ target_platform }}
- clang-19
- llvm-tools-19

host:
- bzip2
- sqlite
- liblzma-devel
- zlib
- zstd
- openssl
- readline
- tk
# These two are just to get the headers needed for tk.h, but is unused
- xorg-libx11
- xorg-xorgproto
- ncurses
- libffi
- if: linux
then:
- ld_impl_${{ target_platform }}
- libuuid
- libmpdec-devel
- expat

about:
homepage: https://www.python.org/
license: Python-2.0
license_file: LICENSE
37 changes: 37 additions & 0 deletions Tools/pixi-packages/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

if [[ "${PYTHON_VARIANT}" == "asan" ]]; then
echo "BUILD TYPE: ASAN"
BUILD_DIR="../build_asan"
CONFIGURE_EXTRA="--with-address-sanitizer"
export PYTHON_ASAN="1"
export ASAN_OPTIONS="strict_init_order=true"
else
echo "BUILD TYPE: DEFAULT"
BUILD_DIR="../build"
CONFIGURE_EXTRA=""
fi

mkdir -p "${BUILD_DIR}"
cd "${BUILD_DIR}"

if [[ -f configure-done ]]; then
echo "Skipping configure step, already done."
Comment thread
FFY00 marked this conversation as resolved.
else
"${SRC_DIR}/configure" \
--prefix="${PREFIX}" \
--oldincludedir="${BUILD_PREFIX}/${HOST}/sysroot/usr/include" \
--enable-shared \
--srcdir="${SRC_DIR}" \
${CONFIGURE_EXTRA}
fi

touch configure-done

make -j"${CPU_COUNT}" install
ln -sf "${PREFIX}/bin/python3" "${PREFIX}/bin/python"

# https://github.com/prefix-dev/rattler-build/issues/2012
if [[ ${OSTYPE} == "darwin"* ]]; then
cp "${BUILD_PREFIX}/lib/clang/21/lib/darwin/libclang_rt.asan_osx_dynamic.dylib" "${PREFIX}/lib/libclang_rt.asan_osx_dynamic.dylib"
fi
Comment thread
lucascolley marked this conversation as resolved.
8 changes: 8 additions & 0 deletions Tools/pixi-packages/default/pixi.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[workspace]
channels = ["https://prefix.dev/conda-forge"]
platforms = ["osx-arm64", "linux-64"]
preview = ["pixi-build"]

[package.build.backend]
name = "pixi-build-rattler-build"
version = "*"
63 changes: 63 additions & 0 deletions Tools/pixi-packages/default/recipe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
context:
# XXX: keep up to date
Comment thread
lucascolley marked this conversation as resolved.
Outdated
version: "3.15"

package:
name: python
version: ${{ version }}

source:
- path: ../../..

build:
files:
exclude:
- "*.o"
script:
file: ../build.sh

# XXX: maybe not all requirements necessary
Comment thread
lucascolley marked this conversation as resolved.
Outdated
Comment thread
lucascolley marked this conversation as resolved.
Outdated
# derived from https://github.com/conda-forge/python-feedstock/blob/main/recipe/meta.yaml
requirements:
build:
- ${{ compiler('c') }}
- ${{ compiler('cxx') }}
- make
- libtool
Comment thread
lucascolley marked this conversation as resolved.
Outdated
- pkg-config
# configure script looks for llvm-ar for lto
- if: osx
then:
- llvm-tools
- if: linux
then:
- ld_impl_${{ target_platform }}
- binutils_impl_${{ target_platform }}
- clang-19
- llvm-tools-19

host:
- bzip2
- sqlite
- liblzma-devel
- zlib
- zstd
- openssl
- readline
- tk
# These two are just to get the headers needed for tk.h, but is unused
- xorg-libx11
- xorg-xorgproto
- ncurses
- libffi
- if: linux
then:
- ld_impl_${{ target_platform }}
- libuuid
- libmpdec-devel
- expat

about:
homepage: https://www.python.org/
license: Python-2.0
license_file: LICENSE
Loading