1
1
# Cross-compiling
2
2
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
+
3
7
## macOS
4
8
5
9
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.
50
54
51
55
## Linux
52
56
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.
57
58
58
59
### Intel to Emscripten (Pyodide)
59
60
@@ -64,3 +65,71 @@ by setting `_PYTHON_SYSCONFIGDATA_NAME`. This causes values like `SOABI` and
64
65
This is unfortunately incorrectly stripped from the cmake wrapper pyodide uses,
65
66
so FindPython will report the wrong values, but pyodide-build will rename the
66
67
.so's afterwards.
68
+
69
+ ## Manual cross compilation
70
+
71
+ The manual cross compilation assumes you have [ toolchain file] prepared defining
72
+ the cross-compilers and where to search for the target development files,
73
+ including the python library. A simple setup of this is to use the clang
74
+ compiler and point ` CMAKE_SYSROOT ` to a mounted copy of the target system's root
75
+
76
+ ``` cmake
77
+ set(CMAKE_SYSTEM_NAME Linux)
78
+ set(CMAKE_SYSTEM_PROCESSOR aarch64)
79
+
80
+ set(triple aarch64-linux-gnu)
81
+
82
+ set(CMAKE_C_COMPILER clang)
83
+ set(CMAKE_CXX_COMPILER clang++)
84
+ set(CMAKE_C_COMPILER_TARGET ${triple})
85
+ set(CMAKE_CXX_COMPILER_TARGET ${triple})
86
+
87
+ set(CMAKE_SYSROOT "/path/to/aarch64/mount/")
88
+ ```
89
+
90
+ For more complex environments such as embedded devices, Android or iOS see
91
+ CMake's guide on how to write the [ toolchain file] .
92
+
93
+ You can pass the toolchain file using the environment variable
94
+ ` CMAKE_TOOLCHAIN_FILE ` , or the ` cmake.toolchain-file ` pyproject option. You may
95
+ also need to use ` wheel.tags ` to manually specify the wheel tags to use for the
96
+ file and ` cmake.no-python-hints ` if the target python should be detected using
97
+ the toolchain file instead.
98
+
99
+ :::{note}
100
+
101
+ Because most of the logic in [ ` FindPython ` ] is gated by the
102
+ ` CMAKE_CROSSCOMPILING ` , you generally should _ not_ include the ` Interpreter `
103
+ component in the ` find_package ` command or use the ` Python_ARTIFACTS_PREFIX `
104
+ feature to distinguish the system and target components.
105
+
106
+ :::
107
+
108
+ :::{versionadded} 0.11
109
+
110
+ :::
111
+
112
+ ### Crossenv
113
+
114
+ [ Crossenv] cross compilation is supported in scikit-build-core. This tool
115
+ creates a fake virtual environment where configuration hints such as
116
+ ` EXT_SUFFIX ` are overwritten with the target's values. This should work without
117
+ specifying ` wheel.tags ` overwrites manually.
118
+
119
+ :::{note}
120
+
121
+ Because the target Python executable is being faked, the usage of
122
+ ` CMAKE_CROSSCOMPILING_EMULATOR ` for the ` Interpreter ` would not be correct in
123
+ this case.
124
+
125
+ :::
126
+
127
+ :::{versionadded} 0.11
128
+
129
+ :::
130
+
131
+ [ manual cross compilation ] : #manual-cross-compilation
132
+ [ toolchain file] :
133
+ https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling
134
+ [ crossenv ] : https://crossenv.readthedocs.io/en/latest/
135
+ [ `FindPython` ] : https://cmake.org/cmake/help/git-master/module/FindPython.html
0 commit comments