Skip to content

Allow Cargo.toml as configuration source #842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- #678 - Add `target.{target}.pre-build` config for running commands before building the image.
- #772 - added `CROSS_CONTAINER_OPTS` environment variable to replace `DOCKER_OPTS`.
- #767, #788 - added the `cross-util` and `xtask` commands.
- #842 - Add `Cargo.toml` as configuration source
- #745 - added `thumbv7neon-*` targets.
- #741 - added `armv7-unknown-linux-gnueabi` and `armv7-unknown-linux-musleabi` targets.
- #721 - add support for running doctests on nightly if `CROSS_UNSTABLE_ENABLE_DOCTESTS=true`.
Expand Down
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,27 @@ Additional documentation can be found on the [wiki](https://github.com/cross-rs/

## Configuration

You can place a `Cross.toml` file in the root of your Cargo project or use a
`CROSS_CONFIG` environment variable to tweak `cross`'s behavior. The format
of `Cross.toml` is documented in [docs/cross_toml.md](docs/cross_toml.md).
You have three options to configure `cross`. All of these options use the TOML format for configuration and the possible configuration values are documented [here](docs/cross_toml.md).

### Option 1: Configuring `cross` directly in your `Cargo.toml`

You can directly set [configuration values](docs/cross_toml.md) in your `Cargo.toml` file, under the `[package.metadata.cross]` table, i.e. key prefix.
An example config snippet would look like this:

```
[package.metadata.cross.target.aarch64-unknown-linux-gnu]
xargo = false
image = "test-image"
runner = "custom-runner"
```

### Option 2: Configuring `cross` via a `Cross.toml` file

You can put your [configuration](docs/cross_toml.md) inside a `Cross.toml` file in your project root directory.

### Option 3: Using `CROSS_CONFIG` to specify the location of your configuration

By setting the `CROSS_CONFIG` environment variable, you can tell `cross` where it should search for the config file. This way you are not limited to a `Cross.toml` file in the project root.

### Custom Docker images

Expand Down
4 changes: 3 additions & 1 deletion docs/cross_toml.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
The `cross` configuration in the `Cross.toml` file, can contain the following elements:
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`

Expand Down
4 changes: 3 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,9 @@ mod tests {
use std::matches;

fn toml(content: &str) -> Result<crate::CrossToml> {
Ok(CrossToml::parse(content).wrap_err("couldn't parse toml")?.0)
Ok(CrossToml::parse_from_cross(content)
.wrap_err("couldn't parse toml")?
.0)
}

#[test]
Expand Down
Loading