sagiegurari / cargo-make

Rust task runner and build tool.
https://sagiegurari.github.io/cargo-make/
Apache License 2.0
2.58k stars 125 forks source link

toolchain = "nightly" not respected in a workspace #1151

Closed matta closed 1 month ago

matta commented 2 months ago

Describe The Bug

A task's toolchain = "nightly" option doesn't seem to take effect in the child tasks executed in each package of a virtual workspace repo.

In my git repo I have the following in a Makefile.toml at the root:

[tasks.format]
description = "Fix code formatting"
toolchain = "nightly"
command = "cargo"
args = ["fmt", "--all"]

I also have a rustfmt.toml in the root that sets some rustfmt options available only in nightly:

max_width = 100

use_field_init_shorthand = true
imports_granularity = "Module"

#
# Unstable options.  This requires nightly rust to format code.  Try:
#
# 1) cargo make format
# 2) cargo +nightly fmt --all
#
# The latter requires rustup.
#

group_imports = "StdExternalCrate"
wrap_comments = true
reorder_impl_items = true

With the above, in a non-workspace repo, cargo-make runs "cargo fmt --all" using the nightly toolchain, as expected.

With the above, in a virtual workspace repo, cargo-make appears to run the same command in each package in the workspace but not with the nightly toolchain. I would expect it to use the nightly toolchain.

The fix in this specific case is to set workspace = false for [tasks.format], since fmt has its own workspace traversal logic anyway (which I enable by passing it the --all flag).

I'm filing this despite that available workaround. It seems useful to have the toolchain = "nightly" option propagate to the child tasks executed in each package of a virtual workspace repo.

To Reproduce

$ git clone https://github.com/matta/sift
$ cd sift
$ git reset --hard dad768bd8ab55baeb55c4a0700757b08d30ef2b2
$ cargo make format

The above sets up a small repo that exhibits the bug (at a revision before I found the workaround I describe above).

Now run cargo make format.

The output is:

cargo-make] INFO - cargo make 0.37.15
[cargo-make] INFO - Calling cargo metadata to extract project info
[cargo-make] INFO - Cargo metadata done
[cargo-make] INFO - Build File: Makefile.toml
[cargo-make] INFO - Task: format
[cargo-make] INFO - Profile: development
[cargo-make] INFO - Running Task: workspace
/home/matt/git/sift
[cargo-make][1] INFO - Calling cargo metadata to extract project info
[cargo-make][1] INFO - Cargo metadata done
[cargo-make][1] INFO - Project: sift-core
[cargo-make][1] INFO - Build File: Makefile.toml
[cargo-make][1] INFO - Task: format
[cargo-make][1] INFO - Profile: development
[cargo-make][1] INFO - Execute Command: "cargo" "fmt"
Warning: can't set `wrap_comments = true`, unstable features are only available in nightly channel.
Warning: can't set `imports_granularity = Module`, unstable features are only available in nightly channel.
Warning: can't set `group_imports = StdExternalCrate`, unstable features are only available in nightly channel.
Warning: can't set `reorder_impl_items = true`, unstable features are only available in nightly channel.
[cargo-make][1] INFO - Build Done in 0.70 seconds.
[cargo-make][1] INFO - Calling cargo metadata to extract project info
[cargo-make][1] INFO - Cargo metadata done
[cargo-make][1] INFO - Project: sift-egui
[cargo-make][1] INFO - Build File: Makefile.toml
[cargo-make][1] INFO - Task: format
[cargo-make][1] INFO - Profile: development
[cargo-make][1] INFO - Execute Command: "cargo" "fmt"
Warning: can't set `wrap_comments = true`, unstable features are only available in nightly channel.
Warning: can't set `imports_granularity = Module`, unstable features are only available in nightly channel.
Warning: can't set `group_imports = StdExternalCrate`, unstable features are only available in nightly channel.
Warning: can't set `reorder_impl_items = true`, unstable features are only available in nightly channel.
Warning: can't set `wrap_comments = true`, unstable features are only available in nightly channel.
Warning: can't set `imports_granularity = Module`, unstable features are only available in nightly channel.
Warning: can't set `group_imports = StdExternalCrate`, unstable features are only available in nightly channel.
Warning: can't set `reorder_impl_items = true`, unstable features are only available in nightly channel.
[cargo-make][1] INFO - Build Done in 0.71 seconds.

The visible warnings make it clear that the exec of each "cargo fmt" command is not being done with the nightly channel.

sagiegurari commented 2 months ago

@matta sorry for late reply. this is hard to act on as i'm missing some info but i think you are confusing how things work in workspaces. in workspaces, each make doesn't 'see' the workspace level makefile so whatever you configured there is lost and actually they are invoking the core built in format task

so add: CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true to your makefile in the workspace level

see more here https://github.com/sagiegurari/cargo-make?tab=readme-ov-file#automatically-extend-workspace-makefile

also got a hunch you are not aware you get dozens of built in tasks unless you skip core tasks https://github.com/sagiegurari/cargo-make?tab=readme-ov-file#disabling-predefined-tasksflows

tell me if that 1 liner solve it for you

sagiegurari commented 1 month ago

closing due to lack of feedback