r/rust•
UARTman

Passing environmental variables to Intellij-Rust cargo expansion module

I'm trying to use sqlx, and its query macro in particular. This macro requires a DATABASE_URL to be set to, well, database url during macro expansion, so it can check whether on not the queries are possible. As a result, Intellij Rust Plugin's macro expansion module can't properly expand the macro and shows it as an error.

Is there a way to pass an environmental variable to it so it can correctly expand the macro?

Posted Jul 18, 2020, 8:18 PM UTC

14
thelights0123•

Unless I've missed something big, Intellij-Rust doesn't yet support proc macro expansion for autocomplete. When you Alt+Enter→Show the result of macro expansion, it runs cargo expand, but doesn't actually do anything with that output—just shows it to you. It doesn't appear to be possible to add additional environment variables to that command.

2
UARTmanOP•

This could mean that what shows errors is an external cargo clippy linter. Is there no way to add environmental variables to it too?

1
thelights0123•

You can start the IDE with the variable already set, or you may have success with adding println!("cargo:rustc-env=DATABASE_URL=VALUE"); to a build.rs script.

1
UARTmanOP•

Thanks! The second one helped!

1