




















@@ -4,79 +4,81 @@
44Building
55========
667-Linux
8-=====
7+A Python distribution can be built on a Linux, macOS or Windows host.
8+Regardless of the operating system, `uv <https://docs.astral.sh/uv/>`_ must be installed.
9+Additional operating system requirements are needed and outlined in the following sections.
91010-The host system must be 64-bit. A Python 3.10+ interpreter must be
11-available. The execution environment must have access to a Docker
12-daemon (all build operations are performed in Docker containers for
13-isolation from the host system).
11+Regardless of the host, to build a Python distribution::
12+13+ $ uv run build.py
14+15+On Linux and macOS, ``./build.py`` can also be used.
16+17+To build a different version of Python::
18+19+ $ uv run build.py --python cpython-3.14
142015-To build a Python distribution for Linux x64::
21+Various build options can be specified::
162217- $ ./build-linux.py
18- # With profile-guided optimizations (generated code should be faster):
19- $ ./build-linux.py --options pgo
23+ # With profile-guided optimizations (generated code should be faster)
24+ $ uv run build.py --options pgo
2025 # Produce a debug build.
21- $ ./build-linux.py --options debug
26+ $ uv run build.py --options debug
2227 # Produce a free-threaded build without extra optimizations
23- $ ./build-linux.py --options freethreaded+noopt
28+ $ uv run build.py --options freethreaded+noopt
242925-You can also build another version of Python. e.g.::
30+Different platforms support different build options.
31+``uv run build.py --help`` will show the available build options and other usage information.
263227- $ ./build-linux.py --python cpython-3.13
283329-To build a Python distribution for Linux x64 using musl libc::
34+Linux
35+=====
303631- $ ./build-linux.py --target x86_64-unknown-linux-musl
37+The host system must be x86-64 or aarch64.
38+The execution environment must have access to a Docker
39+daemon (all build operations are performed in Docker containers for
40+isolation from the host system).
324133-Building a 32-bit x86 Python distribution is also possible::
42+``build.py`` accepts a ``--target-triple`` argument to support building
43+for non-native targets (i.e. cross-compiling).
344435- $ ./build-linux.py --target i686-unknown-linux-gnu
45+This option can be used to build for musl libc::
364637-As are various other targets::
47+ $ ./build.py --target-triple x86_64-unknown-linux-musl
384839- $ ./build-linux.py --target aarch64-unknown-linux-gnu
40- $ ./build-linux.py --target armv7-unknown-linux-gnueabi
41- $ ./build-linux.py --target armv7-unknown-linux-gnueabihf
42- $ ./build-linux.py --target loongarch64-unknown-linux-gnu
43- $ ./build-linux.py --target mips-unknown-linux-gnu
44- $ ./build-linux.py --target mipsel-unknown-linux-gnu
45- $ ./build-linux.py --target ppc64le-unknown-linux-gnu
46- $ ./build-linux.py --target riscv64-unknown-linux-gnu
47- $ ./build-linux.py --target s390x-unknown-linux-gnu
49+Or on a x86-64 host for different architectures::
485049-Additionally, an arm64 macOS host can be used to build Linux aarch64 targets
50-using Docker::
51+ $ ./build.py --target-triple i686-unknown-linux-gnu
52+ $ ./build.py --target-triple armv7-unknown-linux-gnueabi
53+ $ ./build.py --target-triple armv7-unknown-linux-gnueabihf
54+ $ ./build.py --target-triple loongarch64-unknown-linux-gnu
55+ $ ./build.py --target-triple mips-unknown-linux-gnu
56+ $ ./build.py --target-triple mipsel-unknown-linux-gnu
57+ $ ./build.py --target-triple ppc64le-unknown-linux-gnu
58+ $ ./build.py --target-triple riscv64-unknown-linux-gnu
59+ $ ./build.py --target-triple s390x-unknown-linux-gnu
516052- $ ./build-linux.py --target aarch64-unknown-linux-gnu
53615462macOS
5563=====
566457-The XCode command line tools must be installed. A Python 3 interpreter
58-is required to execute the build. ``/usr/bin/clang`` must exist.
65+The XCode command line tools must be installed.
66+``/usr/bin/clang`` must exist.
596760-macOS SDK headers must be installed. Try running ``xcode-select --install``
61-to install them if you see errors about e.g. ``stdio.h`` not being found.
62-Verify they are installed by running ``xcrun --show-sdk-path``. It
63-should print something like
68+macOS SDK headers must be installed.
69+If you see errors such as ``stdio.h`` not being found, try running ``xcode-select --install`` to install them.
70+Verify they are installed by running ``xcrun --show-sdk-path``.
71+It should print something like
6472``/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk``
6573on modern versions of macOS.
667467-To build a Python distribution for macOS::
75+The ``--target-triple`` argument can be used to build for an Intel Mac on an arm64 (Apple Silicon) host::
687669- $ ./build-macos.py
77+ $ ./build.py --target-triple x86_64-apple-darwin
707871-macOS uses the same build code as Linux, just without Docker.
72-So similar build configuration options are available.
79+Additionally, an arm64 macOS host can be used to build Linux aarch64 targets using Docker::
738074-``build-macos.py`` accepts a ``--target-triple`` argument to support building
75-for non-native targets (i.e. cross-compiling). By default, macOS builds target
76-the currently running architecture. e.g. an Intel Mac will target
77-``x86_64-apple-darwin`` and an M1 (ARM) Mac will target ``aarch64-apple-darwin``.
78-It should be possible to build an ARM distribution on an Intel Mac and an Intel
79-distribution on an ARM Mac.
81+ $ ./build.py --target-triple aarch64-unknown-linux-gnu
80828183The ``APPLE_SDK_PATH`` environment variable is recognized as the path
8284to the Apple SDK to use. If not defined, the build will attempt to find
@@ -89,24 +91,17 @@ an Intel 10.15 machine (as long as the 11.0+ SDK is used).
8991Windows
9092=======
919392-Visual Studio 2017 (or later) is required. A compatible Windows SDK is required
93-(10.0.17763.0 as per CPython 3.7.2).
94-95-* A ``git.exe`` on ``PATH`` (to clone ``libffi`` from source).
96-* An installation of Cygwin with the ``autoconf``, ``automake``, ``libtool``,
97- and ``make`` packages installed. (``libffi`` build dependency.)
98-99-To build a dynamically linked Python distribution for Windows x64::
100-101- $ py.exe build-windows.py --options noopt
102-103-It's also possible to build with optional PGO optimizations::
94+Visual Studio 2022 (or later) is required.
95+A compatible Windows SDK is required (10.0.26100.0 as of CPython 3.10).
96+A ``git.exe`` must be on ``PATH`` (to clone ``libffi`` from source).
97+Cygwin must be installed with the ``autoconf``, ``automake``, ``libtool``,
98+and ``make`` packages. (``libffi`` build dependency.)
10499105- $ py.exe build-windows.py --options pgo
100+Building can be done from the ``x64 Native Tools Command Prompt``, by calling
101+the vcvars batch file, or by adjusting the ``PATH`` and environment variables.
106102107-You will need to specify the path to a ``sh.exe`` installed from cygwin. e.g.
103+You will need to specify the path to ``sh.exe`` from cygwin::
108104109- $ py.exe build-windows.py --python cpython-3.13 --sh c:\cygwin\bin\sh.exe --options noopt
105+ $ uv run build.py --sh c:\cygwin\bin\sh.exe
110106111-To build a 32-bit x86 binary, simply use an ``x86 Native Tools
112-Command Prompt`` instead of ``x64``.
107+To build a 32-bit x86 binary, simply use an ``x86 Native Tools Command Prompt`` instead of ``x64``.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。