Skip to content

How to use rust-project.json to achieve the cfg test hack? #17226

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

Closed
huang-jl opened this issue May 14, 2024 · 4 comments
Closed

How to use rust-project.json to achieve the cfg test hack? #17226

huang-jl opened this issue May 14, 2024 · 4 comments
Labels
C-support Category: support questions

Comments

@huang-jl
Copy link

In issue #7225, there is a discussion about disable cfg(test) and there is a PR #12599 that only enables cfg(test) for local crates.

In PR #12599, it said:

"Local" here currently means anything that's not from the registry, so anything inside the workspace, but also path dependencies. So this isn't perfect, and users might still need to use rust-analyzer.cargo.unsetTest for these in some cases.

So I think if I need to manually disable cfg(test) for local path dependencies, I have to use the rust-analyzer.cargo.unsetTest features. After test, I find that it works as what I want.

But recently, there is a new PR #16726 that removes the rust-analyzer.cargo.unsetTest and it is related to project-rust.json. And I cannot use rust-analyzer.cargo.unsetTest in new release of RA.

So my questions is what is project-rust.json? Why can it replace the rust-analyzer.cargo.unsetTest for local path dependencies?

I cannot find any information of using project-rust.json, except the docs. But I still do not know how to use project-rust.json to achieve rust-analyzer.cargo.unsetTest. Is there any example of using project-rust.json that I can copy from?

@huang-jl huang-jl added the C-support Category: support questions label May 14, 2024
@Veykril
Copy link
Member

Veykril commented May 14, 2024

rust-project.json projects do not get test set at all unless its specified in your rust-project.json for each crate. It is the responsibility of the tool (or manual author) of the rust-project.json to set the test cfg where wanted.

I think you are mixing up features here, are you working with a rust-project.json or a plain cargo project? rust-project.json is not meant to disable the implicit cargo test cfg. rust-analyzer.cargo.unsetTest was removed as it was mainly a hack for the core library.

@huang-jl
Copy link
Author

I am working with a plain cargo project. If I understand correctly, do you mean:

  1. If I am working with plain cargo project, I should not use rust-project.json.
  2. rust-analyzer.cargo.unsetTest feature has been removed, and there is currently no method to disable cfg(test) for local path dependencies.

@Veykril
Copy link
Member

Veykril commented May 14, 2024

  1. Yes, rust-project.json is for rust projects that cannot make use of cargo.
  2. Yes. We might want to bring back the configurability of this here somehow, but the config as exposed wasn't really the appropriate way I'd say.

@huang-jl
Copy link
Author

Thanks for you quick reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-support Category: support questions
Projects
None yet
Development

No branches or pull requests

2 participants