Skip to content

Commit

Permalink
Merge #842
Browse files Browse the repository at this point in the history
842: Allow `Cargo.toml` as configuration source r=Emilgardis a=mntns

Due to a GitHub mishap in #754, this is a new PR containing the same commits (rebased by `@Emilgardis).` Just for reference, it still addresses #657.

Co-authored-by: Niklas Kunz <git@monoton.space>
  • Loading branch information
bors[bot] and mntns authored Jun 23, 2022
2 parents b15c29c + 88bcbda commit 7d5a8b2
Show file tree
Hide file tree
Showing 7 changed files with 368 additions and 38 deletions.
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

0 comments on commit 7d5a8b2

Please sign in to comment.