Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

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

Open
cmazakas opened this issue May 8, 2020 · 3 comments

Comments

@cmazakas
Copy link

cmazakas commented May 8, 2020

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\\...
				}
			}
		}
	]
}
@rib
Copy link

rib commented Nov 6, 2020

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:

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

@cmazakas
Copy link
Author

cmazakas commented Nov 7, 2020

Yay, I'm not alone!

@rib
Copy link

rib commented Nov 7, 2020

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.

rust-lang/cargo#4121 (comment)

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 added a commit to rib/cargo that referenced this issue Nov 7, 2020
Some custom build scripts (especially for -sys packages) expect to
query environment variables to locate build resources (such as
pre-built binaries) but these cause lots of trouble when considering
the numerous different ways in which cargo may be invoked.

For example each editor that invokes cargo as part of providing
development diagnostics needs to offer some way to configure environment
variables or users need to find their own way of controlling the environment
variables of these different tools which is burdensome and can lead
to an inconsistent duplication of state across tools.

This introduces support for reading an (optional) environment.json found
at the root of the current workspace that may contain a map of
environment variable key, value pairs. These variables will be exported
to all build scripts run under the workspace. The removes any need to
configure tools and editors independently.

The configuration is separate from any Config.toml since it's likely
that the state shouldn't be under version control in many situations
(generally locating resources for the project within a specific user's
development environment).

Fixes: rust-lang/issues/4121
Fixes: rust-lang/rls/issues/915
Fixes: rust-lang/vscode-rust/issues/791
Fixes: rust-lang/rust-analyzer/pull/6099
Fixes: intellij-rust/intellij-rust/issues/1569
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants