Skip to content

Commit d49fa60

Browse files
LecrisUThenryiii
authored andcommitted
Document how to crosscompile with toolchain files
Signed-off-by: Cristian Le <git@lecris.dev>
1 parent 360c1c7 commit d49fa60

File tree

2 files changed

+74
-4
lines changed

2 files changed

+74
-4
lines changed

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
myst_substitutions = {
159159
"version": version,
160160
}
161+
myst_heading_anchors = 2
161162

162163
# One entry per manual page. List of tuples
163164
# (source start file, name, description, authors, manual section)

docs/guide/crosscompile.md

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Cross-compiling
22

3+
Generally scikit-build-core will try to account for environment variables that
4+
specify to CMake directly how to cross-compile. Alternatively, you can define
5+
manually how to cross-compile as detailed in [manual cross compilation] section.
6+
37
## macOS
48

59
Unlike the other platforms, macOS has the ability to target older operating
@@ -50,10 +54,7 @@ correct suffix. These values are set by cibuildwheel when cross-compiling.
5054

5155
## Linux
5256

53-
It should be possible to cross-compile to Linux, but due to the challenges of
54-
getting the manylinux RHEL devtoolkit compilers, this is currently a TODO. See
55-
`py-build-cmake <https://tttapa.github.io/py-build-cmake/Cross-compilation.html>`\_
56-
for an alternative package's usage of toolchain files.
57+
See [manual cross compilation] section for the general approach.
5758

5859
### Intel to Emscripten (Pyodide)
5960

@@ -67,3 +68,71 @@ so FindPython will report the wrong values, but pyodide-build will rename the
6768

6869
pyodide-build will also set `_PYTHON_HOST_PLATFORM` to the target Pyodide
6970
platform, so scikit-build-core can use that to compute the correct wheel name.
71+
72+
## Manual cross compilation
73+
74+
The manual cross compilation assumes you have [toolchain file] prepared defining
75+
the cross-compilers and where to search for the target development files,
76+
including the python library. A simple setup of this is to use the clang
77+
compiler and point `CMAKE_SYSROOT` to a mounted copy of the target system's root
78+
79+
```cmake
80+
set(CMAKE_SYSTEM_NAME Linux)
81+
set(CMAKE_SYSTEM_PROCESSOR aarch64)
82+
83+
set(triple aarch64-linux-gnu)
84+
85+
set(CMAKE_C_COMPILER clang)
86+
set(CMAKE_CXX_COMPILER clang++)
87+
set(CMAKE_C_COMPILER_TARGET ${triple})
88+
set(CMAKE_CXX_COMPILER_TARGET ${triple})
89+
90+
set(CMAKE_SYSROOT "/path/to/aarch64/mount/")
91+
```
92+
93+
For more complex environments such as embedded devices, Android or iOS see
94+
CMake's guide on how to write the [toolchain file].
95+
96+
You can pass the toolchain file using the environment variable
97+
`CMAKE_TOOLCHAIN_FILE`, or the `cmake.toolchain-file` pyproject option. You may
98+
also need to use `wheel.tags` to manually specify the wheel tags to use for the
99+
file and `cmake.no-python-hints` if the target python should be detected using
100+
the toolchain file instead.
101+
102+
:::{note}
103+
104+
Because most of the logic in [`FindPython`] is gated by the
105+
`CMAKE_CROSSCOMPILING`, you generally should _not_ include the `Interpreter`
106+
component in the `find_package` command or use the `Python_ARTIFACTS_PREFIX`
107+
feature to distinguish the system and target components.
108+
109+
:::
110+
111+
:::{versionadded} 0.11
112+
113+
:::
114+
115+
### Crossenv
116+
117+
[Crossenv] cross compilation is supported in scikit-build-core. This tool
118+
creates a fake virtual environment where configuration hints such as
119+
`EXT_SUFFIX` are overwritten with the target's values. This should work without
120+
specifying `wheel.tags` overwrites manually.
121+
122+
:::{note}
123+
124+
Because the target Python executable is being faked, the usage of
125+
`CMAKE_CROSSCOMPILING_EMULATOR` for the `Interpreter` would not be correct in
126+
this case.
127+
128+
:::
129+
130+
:::{versionadded} 0.11
131+
132+
:::
133+
134+
[manual cross compilation]: #manual-cross-compilation
135+
[toolchain file]:
136+
https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling
137+
[crossenv]: https://crossenv.readthedocs.io/en/latest/
138+
[`FindPython`]: https://cmake.org/cmake/help/git-master/module/FindPython.html

0 commit comments

Comments
 (0)