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

extraEnv in rust-anaylzer to define rustflags #14334

Open
1 task done
tomocrafter opened this issue Jul 12, 2024 · 10 comments
Open
1 task done

extraEnv in rust-anaylzer to define rustflags #14334

tomocrafter opened this issue Jul 12, 2024 · 10 comments
Labels
documentation [core label] rust Rust programming language support

Comments

@tomocrafter
Copy link

Check for existing issues

  • Completed

Describe the feature

In vscode version rust-analyzer, you can specify env in rust-analyzer.cargo.extraEnv to define rustflags to be used while analyzing workspace.

How can I specify rustflags in zed?

https://rust-analyzer.github.io/manual.html

If applicable, add mockups / screenshots to help present your vision of the feature

No response

@SomeoneToIgnore
Copy link
Contributor

Zed uses something similar but with a more convoluted syntax due to historic reasons unfortunately.
https://zed.dev/docs/languages/rust has some examples, and similar section could be created for cargo.

@notpeter notpeter added documentation [core label] rust Rust programming language support and removed enhancement [core label] triage labels Jul 13, 2024
@notpeter
Copy link
Member

@SomeoneToIgnore Is there any way to define rustflags for rust-analyzer.server.extraEnv or rust-analyzer.cargo.extraEnv currently?

@SomeoneToIgnore
Copy link
Contributor

No clue.

@djmaze
Copy link

djmaze commented Sep 15, 2024

This prevents working on wasm projects which use the web_sys_unstable_apis flag, because the analyzer bails out on the use of those unstable features / classes.

@djmaze
Copy link

djmaze commented Sep 15, 2024

Okay, I could make it work by setting the correct RUSTFLAGS as an env variable in the terminal and then starting zed from there.

(To be more precise, I was using a shell.nix which sets up the environment. I added a setting for RUSTFLAGS there.)

@aurexav
Copy link
Contributor

aurexav commented Sep 19, 2024

I simply adhere to the format and import the VSCode configuration. It appears to function correctly.

"lsp": {
	"rust-analyzer": {
		"initialization_options": {
			"cargo": {
				"buildScripts": {
					"enable": false
				}
			},
			"check": {
				"command": "clippy",
				"features": "all"
			},
			"checkOnSave": false,
			"completion": {
				"autoimport": {
					"enable": false
				}
			},
			"diagnostics": {
				"enable": false
			},
			"lens": {
				"debug": {
					"enable": false
				}
			},
			"notifications": {
				"cargoTomlNotFound": false
			},
			"rustfmt": {
				"extraArgs": ["+nightly"]
			}
		}
	}
},

@Noah-Kennedy
Copy link

I'm running into this while trying to work on tokio in Zed. I need to work on stuff with --cfg tokio_unstable, and am having trouble getting rust-analyzer to be passed that environment variable.

Is it possible to do this, or will I need to avoid zed for now when developing on tokio?

@osiewicz
Copy link
Contributor

osiewicz commented Feb 5, 2025

@Noah-Kennedy we seem to use tokio_unstable ourselves with config.toml

rustflags = ["-C", "symbol-mangling-version=v0", "--cfg", "tokio_unstable"]
; I haven't heard any complaints from my peers, so maybe you could give that a go?

@Noah-Kennedy
Copy link

@Noah-Kennedy we seem to use tokio_unstable ourselves with config.toml

zed/.cargo/config.toml

Line 3 in fef567b
rustflags = ["-C", "symbol-mangling-version=v0", "--cfg", "tokio_unstable"]
; I haven't heard any complaints from my peers, so maybe you could give that a go?

It doesn't work for me, not sure why.

I still get rust-analyzer: code is inactive due to #[cfg] directives: tokio_unstable is disabled

@Noah-Kennedy
Copy link

I have gotten this on three different computers while using .cargo/config.toml to specify the relevant RUSTFLAGS invocations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation [core label] rust Rust programming language support
Projects
None yet
Development

No branches or pull requests

7 participants