vscode-rust icon indicating copy to clipboard operation
vscode-rust copied to clipboard

Error squiggles for Cargo.toml when build.rs requires environment variable

Open cmazakas opened this issue 5 years ago • 3 comments

Even with a custom build command (and ctrl-shift-b succeeding), Cargo.toml still renders everything with red squiggles under everything telling me that the package failed to build, i.e.

failed to run custom build command for `cvrust v0.1.0 (C:\Users\...)`

My tasks.json is:

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "cargo",
			"subcommand": "build",
			"problemMatcher": [
				"$rustc"
			],
			"group": "build",
			"label": "Rust: cargo build - cvrust",
			"options": {
				"env": {
					"PNG_LIBRARY_DIR": "C:\\Users\\...
				}
			}
		}
	]
}

cmazakas avatar May 08 '20 00:05 cmazakas

I have the same problem because I need to set the FFMPEG_DIR environment variable for building ffmpeg-sys-next against pre-built ffmpeg libraries.

It feels like lots of people have been struggling with this limitation for many years but not getting any traction figuring out a good solution. E.g. some related issues I came across:

https://github.com/rust-lang/cargo/issues/97 https://github.com/rust-lang/cargo/issues/4121 https://github.com/rust-lang/rls/issues/915 intellij-rust/intellij-rust#1569 rust-analyzer/rust-analyzer#6099 https://stackoverflow.com/questions/57017066/how-do-i-set-environment-variables-with-cargo

rib avatar Nov 06 '20 23:11 rib

Yay, I'm not alone!

cmazakas avatar Nov 07 '20 16:11 cmazakas

For reference I've proposed one way that Cargo could ideally help here to avoid the need for configuring all the various IDEs to see the same environment.

https://github.com/rust-lang/cargo/issues/4121#issuecomment-723465202

The basic idea is that Cargo would check for an environment.json file (or something similar) at the top of your project which would let you configure environment variables for your project in one place and then it wouldn't matter if you're building via the command line or via vscode-rust/rust-analyzer/RLE etc in various different editors they would all see the same environment.

rib avatar Nov 07 '20 18:11 rib