You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/how-to/advanced/cross-compilation.mdx
+109Lines changed: 109 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,9 @@
2
2
title: 'Cross-compilation'
3
3
---
4
4
5
+
importTabsfrom'@theme/Tabs';
6
+
importTabItemfrom'@theme/TabItem';
7
+
5
8
Cross-compiling means building a package for a different architecture than the one the build process
6
9
is running on. It is a common way of obtaining packages for an architecture that conda-forge does
7
10
not provide any runners for (the other available technique is
@@ -117,6 +120,9 @@ are a few examples.
117
120
118
121
A simple C library using autotools for cross-compilation might look like this:
119
122
123
+
<Tabs groupId="recipe">
124
+
125
+
<TabItem label="v0 (meta.yaml)" value="v0">
120
126
```yaml
121
127
requirements:
122
128
build:
@@ -128,6 +134,23 @@ requirements:
128
134
host:
129
135
- libogg
130
136
```
137
+
</TabItem>
138
+
139
+
<TabItem label="v1 (recipe.yaml)" value="v1">
140
+
```yaml
141
+
requirements:
142
+
build:
143
+
- ${{ compiler("c") }}
144
+
- ${{ stdlib("c") }}
145
+
- make
146
+
- pkg-config
147
+
- gnuconfig
148
+
host:
149
+
- libogg
150
+
```
151
+
</TabItem>
152
+
153
+
</Tabs>
131
154
132
155
In the build script, it would need to update the config files and guard any tests when
133
156
cross-compiling:
@@ -149,6 +172,9 @@ fi
149
172
150
173
A simple C++ library using CMake for cross-compilation might look like this:
151
174
175
+
<Tabs groupId="recipe">
176
+
177
+
<TabItem label="v0 (meta.yaml)" value="v0">
152
178
```yaml
153
179
requirements:
154
180
build:
@@ -159,6 +185,22 @@ requirements:
159
185
host:
160
186
- libboost-devel
161
187
```
188
+
</TabItem>
189
+
190
+
<TabItem label="v1 (recipe.yaml)" value="v1">
191
+
```yaml
192
+
requirements:
193
+
build:
194
+
- ${{ compiler("cxx") }}
195
+
- ${{ stdlib("c") }}
196
+
- cmake
197
+
- ninja
198
+
host:
199
+
- libboost-devel
200
+
```
201
+
</TabItem>
202
+
203
+
</Tabs>
162
204
163
205
In the build script, it would need to update `cmake` call and guard any tests when cross-compiling:
164
206
@@ -177,6 +219,9 @@ fi
177
219
178
220
Similarly, with Meson, the `meta.yaml` needs:
179
221
222
+
<Tabs groupId="recipe">
223
+
224
+
<TabItem label="v0 (meta.yaml)" value="v0">
180
225
```yaml
181
226
requirements:
182
227
build:
@@ -188,6 +233,23 @@ requirements:
188
233
host:
189
234
- libogg
190
235
```
236
+
</TabItem>
237
+
238
+
<TabItem label="v1 (recipe.yaml)" value="v1">
239
+
```yaml
240
+
requirements:
241
+
build:
242
+
- ${{ compiler("c") }}
243
+
- ${{ compiler("cxx") }}
244
+
- ${{ stdlib("c") }}
245
+
- meson
246
+
- pkg-config
247
+
host:
248
+
- libogg
249
+
```
250
+
</TabItem>
251
+
252
+
</Tabs>
191
253
192
254
And this in `build.sh`:
193
255
@@ -201,6 +263,9 @@ meson compile
201
263
202
264
A simple Python extension using Cython and NumPy's C API would look like so:
203
265
266
+
<Tabs groupId="recipe">
267
+
268
+
<TabItem label="v0 (meta.yaml)" value="v0">
204
269
```yaml
205
270
requirements:
206
271
build:
@@ -218,13 +283,41 @@ requirements:
218
283
run:
219
284
- python
220
285
```
286
+
</TabItem>
287
+
288
+
<TabItem label="v1 (recipe.yaml)" value="v1">
289
+
```yaml
290
+
requirements:
291
+
build:
292
+
- ${{ compiler("c") }}
293
+
- ${{ stdlib("c") }}
294
+
- if: build_platform != target_platform
295
+
then:
296
+
- cross-python_{{ target_platform }}
297
+
- python
298
+
- cython
299
+
- numpy
300
+
host:
301
+
- python
302
+
- pip
303
+
- cython
304
+
- numpy
305
+
run:
306
+
- python
307
+
```
308
+
</TabItem>
309
+
310
+
</Tabs>
221
311
222
312
For more details about NumPy see [Building against NumPy](/docs/maintainer/knowledge_base/#building-against-numpy).
223
313
224
314
### MPI
225
315
226
316
With MPI, openmpi is required for the build platform as the compiler wrappers are binaries, but mpich is not required as the compiler wrappers are scripts (see [example](https://github.com/conda-forge/mpi4py-feedstock/blob/743d379c4a04/recipe/meta.yaml#L37)):
227
317
318
+
<Tabs groupId="recipe">
319
+
320
+
<TabItem label="v0 (meta.yaml)" value="v0">
228
321
```yaml
229
322
requirements:
230
323
build:
@@ -234,6 +327,22 @@ requirements:
234
327
run:
235
328
- {{ mpi }}
236
329
```
330
+
</TabItem>
331
+
332
+
<TabItem label="v1 (recipe.yaml)" value="v1">
333
+
```yaml
334
+
requirements:
335
+
build:
336
+
- if: build_platform != target_platform and mpi == "openmpi"
337
+
then: ${{ mpi }}
338
+
host:
339
+
- ${{ mpi }}
340
+
run:
341
+
- ${{ mpi }}
342
+
```
343
+
</TabItem>
344
+
345
+
</Tabs>
237
346
238
347
In the build script, openmpi compiler wrappers can use host libraries by setting the environmental variable `OPAL_PREFIX` to `$PREFIX`.
0 commit comments