Avoid running build.rs in RLS / VSCode

I have some code in build.rs that breaks when compiling under RLS in the editor. Even if it did work, it probably shouldn’t run.

What’s the most straightforward way to avoid executing build.rs during syntax checking in VS Code, but let it run for cargo builds from the command line?

  • I thought about checking an environment variable but I can’t work out how to set one that’s specific to RLS
  • I’m currently just commenting out the contents of main() in build.rs which works great but it’s getting old

Do not use rls :slight_smile:
Try rls 2.0 (https://github.com/rust-analyzer/rust-analyzer) it is by design is not compiler,
so it doesn’t run compile code via rustc, and doesn’t run build.rs


Thanks for the tip! I had no idea there was a better project in the works. It’s still a bit fiddly to install and the error-highlighting is not as complete, but I’ve got it running and it’s a lot faster. I’ll give this a go for a while.

1 Like

While rust-analyzer is almost certainly the way forward, after a day I’m back to RLS. It’s so much easier to spot the red squiggly lines, even if I have to wait 5 seconds for them.

So I’m still interested in suggestions for how to make RLS avoid build.rs if anyone has any ideas.

It turns out that there are quite a lot of environment variables that are already different between an RLS build and a normal cargo build. In the end I settled on this to bail out of main() early:

match &env::var("CARGO") {
    Ok(path) if path.ends_with("rls") => return,
    _ => (),

It’s maybe a touch fragile but I can always update it later.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.