don't pass BUILDINFO into build script
It was causing the build script to be recompiled each time a commit was made, even though buildinfo.txt was not changing.
This commit is contained in:
parent
019a65efc1
commit
ebeae9a5a0
@ -14,13 +14,12 @@ cargo_build_script(
|
||||
"PROTOC": "$(location @com_google_protobuf//:protoc)",
|
||||
"RSLIB_FTL_ROOT": "$(location @rslib_ftl//:l10n.toml)",
|
||||
"EXTRA_FTL_ROOT": "$(location @extra_ftl//:l10n.toml)",
|
||||
"BUILDINFO": "$(location //:buildinfo.txt)",
|
||||
"BAZEL": "1",
|
||||
},
|
||||
crate_root = "build/main.rs",
|
||||
data = [
|
||||
"//ftl",
|
||||
"backend.proto",
|
||||
"//:buildinfo.txt",
|
||||
"@com_google_protobuf//:protoc",
|
||||
# bazel requires us to list these out separately
|
||||
"@rslib_ftl//:l10n.toml",
|
||||
@ -50,6 +49,10 @@ _anki_features = [
|
||||
"translations",
|
||||
]
|
||||
|
||||
_anki_rustc_env = {
|
||||
"BUILDINFO": "$(location //:buildinfo.txt)",
|
||||
}
|
||||
|
||||
rust_library(
|
||||
name = "anki",
|
||||
srcs = glob([
|
||||
@ -61,6 +64,7 @@ rust_library(
|
||||
"//rslib/cargo:serde_derive",
|
||||
"//rslib/cargo:serde_repr",
|
||||
],
|
||||
rustc_env = _anki_rustc_env,
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
":build_script",
|
||||
@ -121,6 +125,7 @@ rust_test(
|
||||
data = glob([
|
||||
"tests/support/**",
|
||||
]),
|
||||
rustc_env = _anki_rustc_env,
|
||||
deps = ["//rslib/cargo:env_logger"],
|
||||
)
|
||||
|
||||
|
@ -5,13 +5,14 @@ fn main() {
|
||||
mergeftl::write_ftl_files_and_fluent_rs();
|
||||
protobuf::write_backend_proto_rs();
|
||||
|
||||
// copy or mock buildinfo in out_dir
|
||||
let buildinfo = if let Ok(buildinfo) = std::env::var("BUILDINFO") {
|
||||
std::fs::read_to_string(&buildinfo).expect("buildinfo missing")
|
||||
} else {
|
||||
"".to_string()
|
||||
};
|
||||
let buildinfo_out =
|
||||
std::path::Path::new(&std::env::var("OUT_DIR").unwrap()).join("buildinfo.txt");
|
||||
std::fs::write(&buildinfo_out, buildinfo).unwrap();
|
||||
// when building with cargo (eg for rust analyzer), generate a dummy BUILDINFO
|
||||
if std::env::var("BAZEL").is_err() {
|
||||
let buildinfo_out =
|
||||
std::path::Path::new(&std::env::var("OUT_DIR").unwrap()).join("buildinfo.txt");
|
||||
std::fs::write(&buildinfo_out, "").unwrap();
|
||||
println!(
|
||||
"cargo:rustc-env=BUILDINFO={}",
|
||||
buildinfo_out.to_str().expect("buildinfo")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ use lazy_static::lazy_static;
|
||||
use std::env;
|
||||
|
||||
fn buildinfo(key: &str) -> &'static str {
|
||||
let buildinfo = include_str!(concat!(env!("OUT_DIR"), "/buildinfo.txt"));
|
||||
let buildinfo = include_str!(env!("BUILDINFO"));
|
||||
for line in buildinfo.split('\n') {
|
||||
let mut it = line.split(' ');
|
||||
if it.next().unwrap() == key {
|
||||
|
Loading…
Reference in New Issue
Block a user