Skip to content

Commit 2a324bf

Browse files
committed
docs/config_file: Add docs for config file
taken from the wiki with some added information.
1 parent 53963fb commit 2a324bf

File tree

1 file changed

+196
-0
lines changed

1 file changed

+196
-0
lines changed

docs/config_file.md

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
<!--toc:start-->
2+
- [`build`](#build)
23
- [`build.env`](#buildenv)
34
- [`build.dockerfile`](#builddockerfile)
5+
- [`build.zig`](#buildzig)
6+
- [`target.TARGET`](#targettarget)
7+
- [`target.TARGET.pre-build`](#targettargetpre-build)
8+
- [`target.TARGET.image`](#targettargetimage)
49
- [`target.TARGET.env`](#targettargetenv)
10+
- [`target.TARGET.dockerfile`](#targettargetdockerfile)
11+
- [`target.TARGET.zig`](#targettargetzig)
512
<!--toc:end-->
613

714
> **Note**: Additional configuration is available through
@@ -22,6 +29,26 @@ The `cross` configuration in the `Cross.toml` file can contain the following
2229
elements:
2330

2431

32+
# `build`
33+
34+
The `build` key allows you to set global variables, e.g.:
35+
36+
> *NOTE*: `$CROSS_DEB_ARCH` is automatically provided by cross, [see
37+
> here][custom_images_automatic_arch].
38+
39+
```toml
40+
[build]
41+
build-std = false # do not build the std library. has precedence over xargo
42+
xargo = true # enable the use of xargo by default
43+
zig = false # do not use zig cc for the builds
44+
default-target = "x86_64-unknown-linux-gnu" # use this target if none is explicitly provided
45+
pre-build = [ # additional commands to run prior to building the package
46+
"dpkg --add-architecture $CROSS_DEB_ARCH",
47+
"apt-get update && apt-get --assume-yes install libssl-dev:$CROSS_DEB_ARCH"
48+
]
49+
```
50+
51+
2552
# `build.env`
2653

2754
With the `build.env` key you can globally set volumes that should be mounted in
@@ -93,6 +120,117 @@ FROM $CROSS_BASE_IMAGE
93120
RUN ...
94121
```
95122

123+
124+
# `build.zig`
125+
126+
The `build.zig` key lets you use `zig cc` as a cross-compiler, enabling
127+
cross-compilation to numerous architectures and glibc versions using a single
128+
Docker image. Note that `zig cc` doesn't support all targets: only a subset of
129+
our Linux GNU targets, so it might be better to set these values in
130+
`target.TARGET.zig` instead. The value can be provided as either a table, a bool,
131+
or a string. If `build.zig` is set to a string, it's equivalent to setting
132+
`build.zig.version` to that value and `build.zig.enable` to true:
133+
134+
```toml
135+
[build]
136+
zig = "2.17"
137+
```
138+
139+
If `build.zig` is set to a bool, it's equivalent to setting `build.zig.enable`
140+
to that value:
141+
142+
```toml
143+
[build]
144+
zig = true
145+
```
146+
147+
Or using a table:
148+
149+
```toml
150+
[build.zig]
151+
enable = true # enable or disable the use of zig cc
152+
version = "2.17" # the glibc version to use
153+
image = "myimage" # a custom image containing zig to use
154+
```
155+
156+
157+
# `target.TARGET`
158+
159+
The `target` key allows you to specify parameters for specific compilation
160+
targets:
161+
162+
```toml
163+
[target.aarch64-unknown-linux-gnu]
164+
build-std = false # always build the std library. has precedence over xargo
165+
xargo = false # disable the use of xargo
166+
image = "test-image" # use a different image for the target
167+
runner = "qemu-user" # wrapper to run the binary (must be `qemu-system`, `qemu-user`, or `native`).
168+
```
169+
170+
171+
# `target.TARGET.pre-build`
172+
173+
The `pre-build` field can reference a file to copy and run. This file is
174+
relative to the container context, which would be the workspace root, or the
175+
current directory if `--manifest-path` is used. For more involved scripts,
176+
consider using `target.TARGET.dockerfile` instead to directly control the
177+
execution.
178+
179+
This script will be invoked as `RUN ./pre-build-script $CROSS_TARGET` where
180+
`$CROSS_TARGET` is the target triple.
181+
182+
```toml
183+
[target.aarch64-unknown-linux-gnu]
184+
pre-build = "./scripts/my-script.sh"
185+
```
186+
187+
```bash
188+
$ cat ./scripts/my-script.sh
189+
#!/usr/bin/env bash
190+
191+
apt-get install libssl-dev -y
192+
```
193+
194+
`pre-build` can also be a list of commands to directly run inside the image:
195+
196+
> *NOTE*: `$CROSS_DEB_ARCH` is automatically provided by cross, [see
197+
> here][custom_images_automatic_arch].
198+
199+
```toml
200+
[target.aarch64-unknown-linux-gnu]
201+
pre-build = [
202+
"dpkg --add-architecture $CROSS_DEB_ARCH",
203+
"apt-get update",
204+
"apt-get install --assume-yes libfoo:$CROSS_DEB_ARCH"
205+
]
206+
```
207+
208+
209+
# `target.TARGET.image`
210+
211+
```toml
212+
[target.aarch64-unknown-linux-gnu]
213+
image = "my/image:latest"
214+
```
215+
216+
In the example above, `cross` will use a image named `my/image:latest` instead of
217+
the default one. Normal Docker behavior applies, so:
218+
219+
- Docker will first look for a local image named `my/image:latest`
220+
- If it doesn't find a local image, then it will look in Docker Hub.
221+
- If only `image:latest` is specified, then Docker won't look in Docker Hub.
222+
- If the tag is omitted, then Docker will use the `latest` tag.
223+
224+
The `image` key can also take the toolchains/platforms supported by the image:
225+
226+
```toml
227+
[target.aarch64-unknown-linux-gnu]
228+
image.name = "alpine:edge"
229+
image.toolchain = ["x86_64-unknown-linux-musl", "linux/arm64=aarch64-unknown-linux-musl"] # Defaults to `x86_64-unknown-linux-gnu`
230+
```
231+
232+
233+
96234
# `target.TARGET.env`
97235

98236
The `env` key allows you to specify environment variables that should be used
@@ -106,3 +244,61 @@ passthrough = ["VAR1_ARG", "VAR2_ARG=VALUE"]
106244
```
107245

108246

247+
# `target.TARGET.dockerfile`
248+
249+
The `dockerfile` key lets you provide a custom Docker image for the
250+
given target. The value can be provided as either a table or a string. If
251+
`target.TARGET.dockerfile` is set to a string, it's equivalent to setting
252+
`target.(...).dockerfile.file` to that value. For example, using only a string:
253+
254+
```toml
255+
[target.aarch64-unknown-linux-gnu]
256+
dockerfile = "./Dockerfile"
257+
```
258+
259+
Or using a table:
260+
261+
```toml
262+
[target.aarch64-unknown-linux-gnu.dockerfile]
263+
file = "./Dockerfile" # the dockerfile to use relative to the `Cargo.toml`
264+
context = "." # the context folder to build the script in. defaults to `.`
265+
build-args = { ARG1 = "foo" } # https://docs.docker.com/engine/reference/builder/#arg
266+
```
267+
268+
269+
# `target.TARGET.zig`
270+
271+
The `target.TARGET.zig` key lets you use `zig cc` as a cross-compiler, enabling
272+
cross-compilation to numerous architectures and glibc versions using a single
273+
Docker image. The value can be provided as either a table, a bool, or a string.
274+
If `target.TARGET.zig` is set to a string, it's equivalent to setting
275+
`target.TARGET.zig.version` to that value and `target.TARGET.zig.enable` to
276+
true:
277+
278+
```toml
279+
[target.aarch64-unknown-linux-gnu]
280+
zig = "2.17"
281+
```
282+
283+
If `target.TARGET.zig` is set to a bool, it's equivalent to setting
284+
`target.TARGET.zig.enable` to that value:
285+
286+
```toml
287+
[target.aarch64-unknown-linux-gnu]
288+
zig = true
289+
```
290+
291+
Or using a table:
292+
293+
```toml
294+
[target.aarch64-unknown-linux-gnu.zig]
295+
enable = true # enable or disable the use of zig cc
296+
version = "2.17" # the glibc version to use
297+
image = "myimage" # a custom image containing zig to use
298+
```
299+
300+
301+
302+
[example-cross-toml]: https://github.com/cross-rs/wiki_assets/blob/main/Configuration/Cross.toml
303+
[example-cargo-toml]: https://github.com/cross-rs/wiki_assets/blob/main/Configuration/Cargo.toml
304+
[custom_images_automatic_arch]: ./custom_images.md#automatic-target-architecture-on-debian

0 commit comments

Comments
 (0)