Skip to content

Latest commit

 

History

History
118 lines (86 loc) · 2.95 KB

cross_toml.md

File metadata and controls

118 lines (86 loc) · 2.95 KB

The cross configuration in the Cross.toml file, can contain the elements described below.

If the configuration is given in the Cargo.toml, these table headers must be of the form [package.metadata.cross.<KEY>].

build

The build key allows you to set global variables, e.g.:

[build]
xargo = true
build-std = true
default-target = "x86_64-unknown-linux-gnu"

build.env

With the build.env key you can globally set volumes that should be mounted in the Docker container or environment variables that should be passed through. For example:

[build.env]
volumes = ["VOL1_ARG", "VOL2_ARG"]
passthrough = ["IMPORTANT_ENV_VARIABLES"]

target.TARGET

The target key allows you to specify parameters for specific compilation targets.

[target.aarch64-unknown-linux-gnu]
xargo = false
build-std = false
zig = "2.17"
image = "test-image"
pre-build = ["apt-get update"] # can also be the path to a file to run
runner = "custom-runner"

target.TARGET.pre-build

The pre-build field can also reference a file to copy and run. This file is relative to the container context, which would be the workspace root, or the current directory if --manifest-path is used. For more involved scripts, consider using target.TARGET.dockerfile instead to directly control the execution.

This script will be invoked as RUN ./pre-build-script $CROSS_TARGET where $CROSS_TARGET is the target triple.

[target.aarch64-unknown-linux-gnu]
pre-build = "./scripts/my-script.sh"
$ cat ./scripts/my-script.sh
#!/usr/bin/env bash

apt-get install libssl-dev -y

target.TARGET.image

The image key can also take the toolchains/platforms supported by the image.

[target.aarch64-unknown-linux-gnu]
image.name = "alpine:edge"
image.toolchain = ["x86_64-unknown-linux-musl", "linux/arm64=aarch64-unknown-linux-musl"] # Defaults to `x86_64-unknown-linux-gnu`

target.TARGET.env

The target key allows you to specify environment variables that should be used for a specific compilation target. This is similar to build.env, but allows you to be more specific per target.

[target.x86_64-unknown-linux-gnu.env]
volumes = ["VOL1_ARG", "VOL2_ARG"]
passthrough = ["IMPORTANT_ENV_VARIABLES"]

target.TARGET.dockerfile

[target.x86_64-unknown-linux-gnu.dockerfile]
file = "./Dockerfile" # The dockerfile to use relative to the `Cargo.toml`
context = "." # What folder to run the build script in
build-args = { ARG1 = "foo" } # https://docs.docker.com/engine/reference/builder/#arg

also supports

[target.x86_64-unknown-linux-gnu]
dockerfile = "./Dockerfile"

target.TARGET.zig

[target.x86_64-unknown-linux-gnu.zig]
enable = true       # enable use of the zig image
version = "2.17"    # glibc version to use
image = "zig:local" # custom zig image to use

also supports

[target.x86_64-unknown-linux-gnu]
zig = true

or

[target.x86_64-unknown-linux-gnu]
zig = "2.17"