Skip to content
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

Provide per-project configuration #11010

Closed
sdroege opened this issue Dec 14, 2021 · 2 comments
Closed

Provide per-project configuration #11010

sdroege opened this issue Dec 14, 2021 · 2 comments
Labels
A-config configuration

Comments

@sdroege
Copy link

sdroege commented Dec 14, 2021

My use-case is to not run cargo on the whole workspace in a repository I'm working on but only on the single crate that is currently being worked on. Globally this can be configured but I don't think there's per-project configuration (e.g. via some configuration file at the root of the repository).

@Veykril Veykril added the A-config configuration label Dec 14, 2021
@Veykril
Copy link
Member

Veykril commented Dec 14, 2021

Currently the only way to do it per project is if your editor supports it(VSCode being one example here that enables this), we would like to have a per project rust-analyzer.toml(or use the metadata section of a Cargo.toml) or similar from what I remember(the idea about this is split over a bunch of issues I think).

tetsuharuohzeki added a commit to tetsuharuohzeki/fastly-compute-template that referenced this issue Sep 27, 2022
…s will be `true`

This fixes the bug that is `cfg!(feature = "production")` always will be evaluated as `true`.
For example, the following code in `c_at_e_main` will always returns `"this is production"`
even if we run `make build_debug -j RELEASE_CHANNEL=canary`.

```rust
fn main() {
    let message = if cfg!(feature = "production") {
        "production"
    } else if cfg!(feature = "canary") {
        "canary"
    } else {
        "others"
    };
    println!("this is {}", message);
}
```

This bug is caused accidentally by our build system.

We set `default` feature for `c_at_e_main` to run
many rust toolchain that are not integrated for our build system
easily.

But our _release channel_ model is not mutually exclusive.
[cargo does not support it](rust-lang/cargo#2980).
So when we invoke `cargo build --feature canary`, then cargo will
enables both of `production` and `canary` feature because cargo enables
`default` feature set implicitly too.

Therefore, he above code will be expanded to:

```rust
fn main() {
    let message = if (true) {
        "production"
    } else if (true) {
        "canary"
    } else {
        "others"
    };
    println!("This is {}", message);
}
```

This causes the bug.

This change set `--no-default-features` CLI flags to cargo.
By this change, cargo will not enable `default` feature implicitly
and the bug will be fixed.

This change does not remove `default` feature from
`c_at_e_main`'s Cargo.toml
to still allow to invoke rust-analyzer without zero-configuration.

Note
-----

Can we set cargo's default CLI arguments without our build system?
=============

No.
[`.cargo/config.toml`](https://doc.rust-lang.org/cargo/reference/config.html)
has no way to disable default features without passing CLI flags.

Can we configure rust-analyzer to disable all default features?
==========

Yes, we can config it by vscode's setting.
But rust-analyzer does not have a way to editor agnostic settings.

- rust-lang/rust-analyzer#11010

There are rust-project.json but it's for non-cargo based project.
We would not like to use it.
https://rust-analyzer.github.io/manual.html#non-cargo-based-projects
tetsuharuohzeki added a commit to tetsuharuohzeki/fastly-compute-template that referenced this issue Sep 27, 2022
In the prev commit, we don't use default features in dependencies by default.
But it's not clear for rust-analyzer or other toolchains which are not
integrated to our build system.

To make it simplify, this change removes all `default` feature set from
Cargo.toml in this repository.

This express that this project requires an additional way to enable
toolchain supports which is not added to our build system.

Drawbacks
--------

1. rust-analyzer does not support editor agnostic setting.
   A developer that do not use vscode would requires additional config.
   rust-lang/rust-analyzer#11010
2. This requires to commit `.vscode/settings.json`.
@Veykril
Copy link
Member

Veykril commented Nov 2, 2022

I went and opened #13529 for a more detailed discussion about per-project configurations

@Veykril Veykril closed this as completed Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-config configuration
Projects
None yet
Development

No branches or pull requests

2 participants