mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Fix building outside workspace
rslib/build.rs needs descriptors, even if env var not set
This commit is contained in:
parent
c6f429ab17
commit
0f77de896d
4 changed files with 23 additions and 16 deletions
|
@ -3,10 +3,9 @@
|
||||||
|
|
||||||
mod rust_interface;
|
mod rust_interface;
|
||||||
|
|
||||||
use std::env;
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
|
use anki_proto_gen::descriptors_path;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use prost_reflect::DescriptorPool;
|
use prost_reflect::DescriptorPool;
|
||||||
|
|
||||||
|
@ -15,7 +14,7 @@ fn main() -> Result<()> {
|
||||||
let buildhash = fs::read_to_string("../out/buildhash").unwrap_or_default();
|
let buildhash = fs::read_to_string("../out/buildhash").unwrap_or_default();
|
||||||
println!("cargo:rustc-env=BUILDHASH={buildhash}");
|
println!("cargo:rustc-env=BUILDHASH={buildhash}");
|
||||||
|
|
||||||
let descriptors_path = env::var("DESCRIPTORS_BIN").ok().map(PathBuf::from).unwrap();
|
let descriptors_path = descriptors_path();
|
||||||
println!("cargo:rerun-if-changed={}", descriptors_path.display());
|
println!("cargo:rerun-if-changed={}", descriptors_path.display());
|
||||||
let pool = DescriptorPool::decode(std::fs::read(descriptors_path)?.as_ref())?;
|
let pool = DescriptorPool::decode(std::fs::read(descriptors_path)?.as_ref())?;
|
||||||
rust_interface::write_rust_interface(&pool)?;
|
rust_interface::write_rust_interface(&pool)?;
|
||||||
|
|
|
@ -5,14 +5,12 @@ pub mod python;
|
||||||
pub mod rust;
|
pub mod rust;
|
||||||
pub mod ts;
|
pub mod ts;
|
||||||
|
|
||||||
use std::env;
|
use anki_proto_gen::descriptors_path;
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
use anki_proto_gen::get_services;
|
use anki_proto_gen::get_services;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
let descriptors_path = env::var("DESCRIPTORS_BIN").ok().map(PathBuf::from);
|
let descriptors_path = descriptors_path();
|
||||||
|
|
||||||
let pool = rust::write_rust_protos(descriptors_path)?;
|
let pool = rust::write_rust_protos(descriptors_path)?;
|
||||||
let (_, services) = get_services(&pool);
|
let (_, services) = get_services(&pool);
|
||||||
|
|
|
@ -14,7 +14,7 @@ use anyhow::Context;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use prost_reflect::DescriptorPool;
|
use prost_reflect::DescriptorPool;
|
||||||
|
|
||||||
pub fn write_rust_protos(descriptors_path: Option<PathBuf>) -> Result<DescriptorPool> {
|
pub fn write_rust_protos(descriptors_path: PathBuf) -> Result<DescriptorPool> {
|
||||||
set_protoc_path();
|
set_protoc_path();
|
||||||
let proto_dir = PathBuf::from("../../proto");
|
let proto_dir = PathBuf::from("../../proto");
|
||||||
let paths = gather_proto_paths(&proto_dir)?;
|
let paths = gather_proto_paths(&proto_dir)?;
|
||||||
|
@ -49,14 +49,12 @@ pub fn write_rust_protos(descriptors_path: Option<PathBuf>) -> Result<Descriptor
|
||||||
.context("prost build")?;
|
.context("prost build")?;
|
||||||
|
|
||||||
let descriptors = read_file(&tmp_descriptors)?;
|
let descriptors = read_file(&tmp_descriptors)?;
|
||||||
if let Some(descriptors_path) = descriptors_path {
|
|
||||||
create_dir_all(
|
create_dir_all(
|
||||||
descriptors_path
|
descriptors_path
|
||||||
.parent()
|
.parent()
|
||||||
.context("missing parent of descriptor")?,
|
.context("missing parent of descriptor")?,
|
||||||
)?;
|
)?;
|
||||||
write_file_if_changed(descriptors_path, &descriptors)?;
|
write_file_if_changed(descriptors_path, &descriptors)?;
|
||||||
}
|
|
||||||
|
|
||||||
let pool = DescriptorPool::decode(descriptors.as_ref())?;
|
let pool = DescriptorPool::decode(descriptors.as_ref())?;
|
||||||
add_must_use_annotations(
|
add_must_use_annotations(
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
//! match.
|
//! match.
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::env;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use anki_io::read_to_string;
|
use anki_io::read_to_string;
|
||||||
|
@ -266,3 +267,14 @@ pub fn determine_if_message_is_empty(pool: &DescriptorPool, path: &Utf8Path, nam
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// - When building via a local checkout, the path defined in .cargo/config
|
||||||
|
/// - When building via cargo install or a third-party crate,
|
||||||
|
/// OUT_DIR/../../anki_descriptors.bin (so it can be seen by the rslib crate)
|
||||||
|
pub fn descriptors_path() -> PathBuf {
|
||||||
|
if let Ok(path) = env::var("DESCRIPTORS_BIN") {
|
||||||
|
PathBuf::from(path)
|
||||||
|
} else {
|
||||||
|
PathBuf::from(env::var("OUT_DIR").unwrap()).join("../../anki_descriptors.bin")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue