From 67944f298c1fb64f69766fc6ee0269ea6b1efb75 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Thu, 1 Nov 2018 02:29:39 +0100 Subject: [PATCH] cargo: build only necessary Ninja targets when invoked by RLS --- BUILD.gn | 7 +++++++ build.rs | 21 ++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/BUILD.gn b/BUILD.gn index 0399098932..9e6c7abd05 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -18,6 +18,13 @@ group("default") { ] } +# Set of targets that need to be built for `cargo check` to succeed. +group("cargo_check_deps") { + deps = [ + ":msg_rs", + ] +} + config("deno_config") { include_dirs = [ "third_party/v8" ] # This allows us to v8/src/base/ libraries. configs = [ "third_party/v8:external_config" ] diff --git a/build.rs b/build.rs index 489f9f9d26..351a00cf73 100644 --- a/build.rs +++ b/build.rs @@ -7,12 +7,31 @@ // TODO Combine DENO_BUILD_PATH and OUT_DIR. use std::env; +use std::path::PathBuf; use std::process::Command; fn main() { let mode = env::var("PROFILE").unwrap(); let deno_build_path = env::var("DENO_BUILD_PATH").unwrap(); + // Detect if we're being invoked by the rust language server (RLS). + // Unfortunately we can't detect whether we're being run by `cargo check`. + let check_only = env::var_os("CARGO") + .map(PathBuf::from) + .as_ref() + .and_then(|p| p.file_stem()) + .and_then(|f| f.to_str()) + .map(|s| s.starts_with("rls")) + .unwrap_or(false); + + // If we're being invoked by the RLS, build only the targets that are needed + // for `cargo check` to succeed. + let gn_target = if check_only { + "cargo_check_deps" + } else { + "deno_deps" + }; + let status = Command::new("python") .env("DENO_BUILD_PATH", &deno_build_path) .env("DENO_BUILD_MODE", &mode) @@ -31,7 +50,7 @@ fn main() { .env("DENO_BUILD_PATH", &deno_build_path) .env("DENO_BUILD_MODE", &mode) .arg("./tools/build.py") - .arg("deno_deps") + .arg(gn_target) .arg("-v") .status() .expect("build.py failed");