Search code examples
rustclion

How to set environment variables for build task in IntelliJ Rust?


In Rust 1.52.1 incremental compilation is disabled, but I want to enable it because it speeds up my compilation time by 3 times. There are RUSTC_FORCE_INCREMENTAL environmental variable for it. So I want to set RUSTC_FORCE_INCREMENTAL=1 for build task, but it seems CLion doesn't support that. I can only set environmental variables for Run Configurations.


Solution

  • Use a build script: place a build.rs file in the root of your package and use cargo:rustc-env=VAR=VALUE instruction:

    fn main() {
        println!("cargo:rustc-env=RUSTC_FORCE_INCREMENTAL=1");
    }