diff --git a/Cargo.lock b/Cargo.lock index 068f85711..da19d3704 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -118,6 +118,7 @@ dependencies = [ "unicase", "unicode-normalization", "utime", + "which", "zip", "zstd", ] diff --git a/cargo/BUILD.bazel b/cargo/BUILD.bazel index 2b529535e..42a561ba5 100644 --- a/cargo/BUILD.bazel +++ b/cargo/BUILD.bazel @@ -579,6 +579,15 @@ alias( ], ) +alias( + name = "which", + actual = "@raze__which__4_3_0//:which", + tags = [ + "cargo-raze", + "manual", + ], +) + alias( name = "zip", actual = "@raze__zip__0_6_2//:zip", diff --git a/pylib/rsbridge/cargo/BUILD.bazel b/pylib/rsbridge/cargo/BUILD.bazel index 5104f9b3e..cf09ad565 100644 --- a/pylib/rsbridge/cargo/BUILD.bazel +++ b/pylib/rsbridge/cargo/BUILD.bazel @@ -579,6 +579,15 @@ alias( ], ) +alias( + name = "which", + actual = "@raze__which__4_3_0//:which", + tags = [ + "cargo-raze", + "manual", + ], +) + alias( name = "zip", actual = "@raze__zip__0_6_2//:zip", diff --git a/rslib/BUILD.bazel b/rslib/BUILD.bazel index 2c027a0b8..7dfb7abfb 100644 --- a/rslib/BUILD.bazel +++ b/rslib/BUILD.bazel @@ -31,6 +31,7 @@ cargo_build_script( ], deps = [ "//rslib/cargo:prost_build", + "//rslib/cargo:which", ], ) diff --git a/rslib/Cargo.toml b/rslib/Cargo.toml index 3bc06a78c..efc87b693 100644 --- a/rslib/Cargo.toml +++ b/rslib/Cargo.toml @@ -23,6 +23,7 @@ required-features = ["bench"] [build-dependencies] prost-build = "0.11.1" +which = "4.3.0" [dev-dependencies] env_logger = "0.9.1" diff --git a/rslib/build/protobuf.rs b/rslib/build/protobuf.rs index 4535be3e1..a51dfd097 100644 --- a/rslib/build/protobuf.rs +++ b/rslib/build/protobuf.rs @@ -1,7 +1,11 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use std::{env, fmt::Write, path::PathBuf}; +use std::{ + env, + fmt::Write, + path::{Path, PathBuf}, +}; struct CustomGenerator {} @@ -71,6 +75,7 @@ fn service_generator() -> Box { } pub fn write_backend_proto_rs() { + maybe_add_protobuf_to_path(); let proto_dir = if let Ok(proto) = env::var("PROTO_TOP") { PathBuf::from(proto).parent().unwrap().to_owned() } else { @@ -122,3 +127,24 @@ pub fn write_backend_proto_rs() { .compile_protos(paths.as_slice(), &[proto_dir]) .unwrap(); } + +/// If PROTOC is not defined, and protoc is not on path, use the protoc +/// fetched by Bazel so that Rust Analyzer does not fail. +fn maybe_add_protobuf_to_path() { + if std::env::var("PROTOC").is_ok() { + return; + } + if which::which("protoc").is_ok() { + return; + } + let base = Path::new("../.bazel/out/../external"); + let subpath = if cfg!(target_os = "windows") { + "protoc_bin_windows/bin/protoc.exe" + } else if cfg!(target_os = "macos") { + "protoc_bin_macos/bin/protoc" + } else { + "protoc_bin_linux_x86_64/bin/protoc" + }; + let path = base.join(subpath); + std::env::set_var("PROTOC", path.to_str().unwrap()); +} diff --git a/rslib/cargo/BUILD.bazel b/rslib/cargo/BUILD.bazel index 5104f9b3e..cf09ad565 100644 --- a/rslib/cargo/BUILD.bazel +++ b/rslib/cargo/BUILD.bazel @@ -579,6 +579,15 @@ alias( ], ) +alias( + name = "which", + actual = "@raze__which__4_3_0//:which", + tags = [ + "cargo-raze", + "manual", + ], +) + alias( name = "zip", actual = "@raze__zip__0_6_2//:zip", diff --git a/rslib/i18n/cargo/BUILD.bazel b/rslib/i18n/cargo/BUILD.bazel index 5104f9b3e..cf09ad565 100644 --- a/rslib/i18n/cargo/BUILD.bazel +++ b/rslib/i18n/cargo/BUILD.bazel @@ -579,6 +579,15 @@ alias( ], ) +alias( + name = "which", + actual = "@raze__which__4_3_0//:which", + tags = [ + "cargo-raze", + "manual", + ], +) + alias( name = "zip", actual = "@raze__zip__0_6_2//:zip", diff --git a/rslib/i18n_helpers/cargo/BUILD.bazel b/rslib/i18n_helpers/cargo/BUILD.bazel index 5104f9b3e..cf09ad565 100644 --- a/rslib/i18n_helpers/cargo/BUILD.bazel +++ b/rslib/i18n_helpers/cargo/BUILD.bazel @@ -579,6 +579,15 @@ alias( ], ) +alias( + name = "which", + actual = "@raze__which__4_3_0//:which", + tags = [ + "cargo-raze", + "manual", + ], +) + alias( name = "zip", actual = "@raze__zip__0_6_2//:zip", diff --git a/rslib/linkchecker/cargo/BUILD.bazel b/rslib/linkchecker/cargo/BUILD.bazel index 5104f9b3e..cf09ad565 100644 --- a/rslib/linkchecker/cargo/BUILD.bazel +++ b/rslib/linkchecker/cargo/BUILD.bazel @@ -579,6 +579,15 @@ alias( ], ) +alias( + name = "which", + actual = "@raze__which__4_3_0//:which", + tags = [ + "cargo-raze", + "manual", + ], +) + alias( name = "zip", actual = "@raze__zip__0_6_2//:zip",