Fix clean build failure due to protoc change

da7d4dd2fc changed the name of the env
var in .cargo/config.toml, causing the check in setup_protoc() to think
a custom path had been provided, which skipped the download and extract
step.
This commit is contained in:
Damien Elmes 2023-01-26 09:31:02 +10:00
parent ae8f44d4b3
commit 4142de57e2
2 changed files with 10 additions and 9 deletions

View file

@ -1,7 +1,7 @@
[env]
STRINGS_JSON = { value = "out/rslib/i18n/strings.json", relative = true }
# build script will append .exe if necessary
PROTOC_BINARY = { value = "out/extracted/protoc/bin/protoc", relative = true }
PROTOC = { value = "out/extracted/protoc/bin/protoc", relative = true }
PYO3_NO_PYTHON = "1"
MACOSX_DEPLOYMENT_TARGET = "10.13.4"

View file

@ -73,7 +73,7 @@ fn service_generator() -> Box<dyn prost_build::ServiceGenerator> {
}
pub fn write_backend_proto_rs() {
maybe_add_protobuf_to_path();
set_protoc_path();
let proto_dir = PathBuf::from("../proto");
let subfolders = &["anki"];
@ -122,13 +122,14 @@ pub fn write_backend_proto_rs() {
.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 let Ok(protoc) = env::var("PROTOC_BINARY") {
env::set_var("PROTOC", &protoc);
if cfg!(windows) && !protoc.ends_with(".exe") {
env::set_var("PROTOC", format!("{protoc}.exe"));
/// Set PROTOC to the custom path provided by PROTOC_BINARY, or add .exe to
/// the standard path if on Windows.
fn set_protoc_path() {
if let Ok(custom_protoc) = env::var("PROTOC_BINARY") {
env::set_var("PROTOC", custom_protoc);
} else if let Ok(bundled_protoc) = env::var("PROTOC") {
if cfg!(windows) && !bundled_protoc.ends_with(".exe") {
env::set_var("PROTOC", format!("{bundled_protoc}.exe"));
}
}
}