Multiple target "categories" in config.toml

Let's say I have the following config.toml:

[build]
jobs = 17 # 2N+1 where 2 is number of cores
incremental = true
# May need to run `cargo install sccache`
rustc-wrapper = "sccache"

[profile.release]
opt-level = 3 # All optimizations!
debug = 0 # No debug info
strip = "symbols"
lto = "fat"

I can then build this with cargo build --release.
I'm aware I could also add a target entry to build, e.g.

[build]
jobs = 17 # 2N+1 where 2 is number of cores
incremental = true
# May need to run `cargo install sccache`
rustc-wrapper = "sccache" # Might need to change to full path for windows
target = ["foo", "bar"]

However, I'd like to have certain targets only build for release builds. How I thought I could do this would be something like:

[build]
jobs = 17 # 2N+1 where 2 is number of cores
incremental = true
# May need to run `cargo install sccache`
rustc-wrapper = "sccache" # Might need to change to full path for windows
[build.release] # Set different build options for release?
jobs = 17
rustc-wrapper = "sccache"
target = [  "aarch64-apple-darwin", "aarch64-pc-windows-gnullvm"]

Similar to how you have profile and profile.release. This does not work however.
Is there a way to achieve what I'm seeking in the config.toml file? I'm aware I could probably use something like a makefile, but I'd prefer not to if there is a more elegant inbuilt way.

On a design level, keep in mind that the following are equivalent:

[build]
jobs = 17 # 2N+1 where 2 is number of cores
incremental = true
# May need to run `cargo install sccache`
rustc-wrapper = "sccache" # Might need to change to full path for windows
[build.release] # Set different build options for release?
jobs = 17
rustc-wrapper = "sccache"
target = [  "aarch64-apple-darwin", "aarch64-pc-windows-gnullvm"]
[build]
jobs = 17 # 2N+1 where 2 is number of cores
incremental = true
# May need to run `cargo install sccache`
rustc-wrapper = "sccache" # Might need to change to full path for windows
# Set different build options for release?
release = {
  jobs = 17,
  rustc-wrapper = "sccache",
  target = [  "aarch64-apple-darwin", "aarch64-pc-windows-gnullvm"],
}

and users are allowed to name profiles with whatever they want, including having a jobs profile.

(use of multi-line inline tables like that is supported in the TOML 1.1 spec which will be supported in Cargo once feat(toml): TOML 1.1 parse support by epage · Pull Request #16415 · rust-lang/cargo · GitHub is merged)

Not that I know of. If anyone does want to explore this design space, the initial focus should be on the use case then on potential options for resolving that use case.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.