2020-11-01 05:26:58 +01:00
|
|
|
load("@rules_proto//proto:defs.bzl", "proto_library")
|
|
|
|
load("@io_bazel_rules_rust//rust:rust.bzl", "rust_binary", "rust_library", "rust_test")
|
|
|
|
load("@io_bazel_rules_rust//cargo:cargo_build_script.bzl", "cargo_build_script")
|
|
|
|
load(":rustfmt.bzl", "rustfmt_fix", "rustfmt_test")
|
2021-01-09 05:16:26 +01:00
|
|
|
load("//ts:sql_format.bzl", "sql_format")
|
2020-11-01 05:26:58 +01:00
|
|
|
|
|
|
|
# Build script
|
|
|
|
#######################
|
|
|
|
|
|
|
|
cargo_build_script(
|
|
|
|
name = "build_script",
|
|
|
|
srcs = glob(["build/*.rs"]),
|
|
|
|
build_script_env = {
|
2020-11-02 07:28:31 +01:00
|
|
|
"BACKEND_PROTO": "$(location backend.proto)",
|
|
|
|
"PROTOC": "$(location @com_google_protobuf//:protoc)",
|
2020-11-04 10:20:49 +01:00
|
|
|
"RSLIB_FTL_ROOT": "$(location @rslib_ftl//:l10n.toml)",
|
|
|
|
"EXTRA_FTL_ROOT": "$(location @extra_ftl//:l10n.toml)",
|
2020-12-21 06:59:16 +01:00
|
|
|
"BAZEL": "1",
|
2020-11-01 05:26:58 +01:00
|
|
|
},
|
|
|
|
crate_root = "build/main.rs",
|
2020-11-18 07:17:19 +01:00
|
|
|
data = [
|
|
|
|
"//ftl",
|
2020-11-02 07:28:31 +01:00
|
|
|
"backend.proto",
|
2020-11-01 05:26:58 +01:00
|
|
|
"@com_google_protobuf//:protoc",
|
2020-11-04 10:20:49 +01:00
|
|
|
# bazel requires us to list these out separately
|
|
|
|
"@rslib_ftl//:l10n.toml",
|
|
|
|
"@extra_ftl//:l10n.toml",
|
2020-11-01 05:26:58 +01:00
|
|
|
],
|
|
|
|
deps = [
|
2020-11-24 09:41:03 +01:00
|
|
|
"//rslib/cargo:fluent_syntax",
|
|
|
|
"//rslib/cargo:prost_build",
|
2020-11-01 05:26:58 +01:00
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
# Library
|
|
|
|
#######################
|
|
|
|
|
2020-12-01 06:26:09 +01:00
|
|
|
_anki_compile_data = glob([
|
2020-11-01 05:26:58 +01:00
|
|
|
"src/**/*.sql",
|
|
|
|
"src/**/*.html",
|
|
|
|
"src/**/*.css",
|
|
|
|
"src/**/*.tex",
|
|
|
|
]) + [
|
|
|
|
"Cargo.toml", # prevents a warning about num_enum
|
|
|
|
"//:buildinfo.txt",
|
2020-11-24 11:10:16 +01:00
|
|
|
"templates/.empty", # required for askama
|
2020-11-01 05:26:58 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
_anki_features = [
|
|
|
|
"translations",
|
|
|
|
]
|
|
|
|
|
2020-12-21 06:59:16 +01:00
|
|
|
_anki_rustc_env = {
|
|
|
|
"BUILDINFO": "$(location //:buildinfo.txt)",
|
|
|
|
}
|
|
|
|
|
2020-11-01 05:26:58 +01:00
|
|
|
rust_library(
|
|
|
|
name = "anki",
|
|
|
|
srcs = glob([
|
|
|
|
"src/**/*.rs",
|
|
|
|
]),
|
2020-12-01 06:26:09 +01:00
|
|
|
compile_data = _anki_compile_data,
|
2020-11-01 05:26:58 +01:00
|
|
|
crate_features = _anki_features,
|
|
|
|
proc_macro_deps = [
|
2020-11-24 09:41:03 +01:00
|
|
|
"//rslib/cargo:serde_derive",
|
|
|
|
"//rslib/cargo:serde_repr",
|
2020-11-01 05:26:58 +01:00
|
|
|
],
|
2020-12-21 06:59:16 +01:00
|
|
|
rustc_env = _anki_rustc_env,
|
2020-11-01 05:26:58 +01:00
|
|
|
visibility = ["//visibility:public"],
|
|
|
|
deps = [
|
|
|
|
":build_script",
|
2020-11-24 09:41:03 +01:00
|
|
|
"//rslib/cargo:askama",
|
|
|
|
"//rslib/cargo:async_compression",
|
|
|
|
"//rslib/cargo:blake3",
|
|
|
|
"//rslib/cargo:bytes",
|
|
|
|
"//rslib/cargo:chrono",
|
|
|
|
"//rslib/cargo:coarsetime",
|
|
|
|
"//rslib/cargo:failure",
|
|
|
|
"//rslib/cargo:flate2",
|
|
|
|
"//rslib/cargo:fluent",
|
|
|
|
"//rslib/cargo:futures",
|
|
|
|
"//rslib/cargo:hex",
|
|
|
|
"//rslib/cargo:htmlescape",
|
|
|
|
"//rslib/cargo:intl_memoizer",
|
|
|
|
"//rslib/cargo:itertools",
|
|
|
|
"//rslib/cargo:lazy_static",
|
|
|
|
"//rslib/cargo:nom",
|
|
|
|
"//rslib/cargo:num_enum",
|
|
|
|
"//rslib/cargo:num_format",
|
|
|
|
"//rslib/cargo:num_integer",
|
|
|
|
"//rslib/cargo:once_cell",
|
|
|
|
"//rslib/cargo:pin_project",
|
|
|
|
"//rslib/cargo:prost",
|
|
|
|
"//rslib/cargo:rand",
|
|
|
|
"//rslib/cargo:regex",
|
|
|
|
"//rslib/cargo:reqwest",
|
|
|
|
"//rslib/cargo:rusqlite",
|
|
|
|
"//rslib/cargo:scopeguard",
|
|
|
|
"//rslib/cargo:serde",
|
|
|
|
"//rslib/cargo:serde_aux",
|
|
|
|
"//rslib/cargo:serde_json",
|
|
|
|
"//rslib/cargo:serde_tuple",
|
|
|
|
"//rslib/cargo:sha1",
|
|
|
|
"//rslib/cargo:slog",
|
|
|
|
"//rslib/cargo:slog_async",
|
|
|
|
"//rslib/cargo:slog_envlogger",
|
|
|
|
"//rslib/cargo:slog_term",
|
|
|
|
"//rslib/cargo:tempfile",
|
|
|
|
"//rslib/cargo:tokio",
|
|
|
|
"//rslib/cargo:unic_langid",
|
|
|
|
"//rslib/cargo:unicase",
|
|
|
|
"//rslib/cargo:unicode_normalization",
|
|
|
|
"//rslib/cargo:utime",
|
|
|
|
"//rslib/cargo:zip",
|
2020-11-01 05:26:58 +01:00
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
# Tests
|
|
|
|
#######################
|
|
|
|
|
|
|
|
rust_test(
|
|
|
|
name = "unit_tests",
|
2020-12-01 06:26:09 +01:00
|
|
|
compile_data = _anki_compile_data,
|
2020-11-01 05:26:58 +01:00
|
|
|
crate = ":anki",
|
|
|
|
crate_features = _anki_features,
|
2020-12-01 06:26:09 +01:00
|
|
|
data = glob([
|
2020-11-01 05:26:58 +01:00
|
|
|
"tests/support/**",
|
|
|
|
]),
|
2020-12-21 06:59:16 +01:00
|
|
|
rustc_env = _anki_rustc_env,
|
2020-11-24 09:41:03 +01:00
|
|
|
deps = ["//rslib/cargo:env_logger"],
|
2020-11-01 05:26:58 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
rustfmt_test(
|
2020-11-12 11:11:40 +01:00
|
|
|
name = "format_check",
|
2020-11-01 05:26:58 +01:00
|
|
|
srcs = glob([
|
|
|
|
"src/**/*.rs",
|
|
|
|
]),
|
|
|
|
)
|
|
|
|
|
|
|
|
rustfmt_fix(
|
2020-11-12 11:11:40 +01:00
|
|
|
name = "format",
|
2020-11-01 05:26:58 +01:00
|
|
|
srcs = glob([
|
|
|
|
"src/**/*.rs",
|
|
|
|
]),
|
|
|
|
)
|
|
|
|
|
2021-01-09 05:16:26 +01:00
|
|
|
sql_format(
|
|
|
|
name = "sql_format",
|
|
|
|
srcs = glob(["**/*.sql"]),
|
|
|
|
)
|
|
|
|
|
2020-11-01 05:26:58 +01:00
|
|
|
# fluent.proto generation
|
|
|
|
###########################
|
|
|
|
# This separate step is required to make the file available to downstream consumers.
|
|
|
|
|
|
|
|
rust_binary(
|
|
|
|
name = "write_fluent_proto",
|
|
|
|
srcs = [
|
|
|
|
"build/mergeftl.rs",
|
|
|
|
"build/write_fluent_proto.rs",
|
|
|
|
],
|
2020-11-24 09:41:03 +01:00
|
|
|
deps = ["//rslib/cargo:fluent_syntax"],
|
2020-11-01 05:26:58 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
genrule(
|
|
|
|
name = "fluent_proto",
|
2020-11-18 07:17:19 +01:00
|
|
|
srcs = [
|
|
|
|
"//ftl",
|
|
|
|
"//ftl:BUILD.bazel",
|
2020-11-24 09:41:03 +01:00
|
|
|
"//rslib/cargo:fluent_syntax",
|
2020-11-04 10:20:49 +01:00
|
|
|
"@rslib_ftl//:l10n.toml",
|
|
|
|
"@extra_ftl//:l10n.toml",
|
2020-11-01 05:26:58 +01:00
|
|
|
],
|
|
|
|
outs = ["fluent.proto"],
|
2020-11-04 10:20:49 +01:00
|
|
|
cmd = """\
|
|
|
|
RSLIB_FTL_ROOT="$(location @rslib_ftl//:l10n.toml)" \
|
|
|
|
EXTRA_FTL_ROOT="$(location @extra_ftl//:l10n.toml)" \
|
2020-11-18 07:17:19 +01:00
|
|
|
FTL_SRC="$(location //ftl:BUILD.bazel)" \
|
2020-11-04 10:20:49 +01:00
|
|
|
$(location :write_fluent_proto) $(location fluent.proto)""",
|
|
|
|
tools = [
|
|
|
|
":write_fluent_proto",
|
|
|
|
],
|
2020-11-01 05:26:58 +01:00
|
|
|
visibility = ["//visibility:public"],
|
|
|
|
)
|
|
|
|
|
|
|
|
proto_library(
|
|
|
|
name = "fluent_proto_lib",
|
|
|
|
srcs = ["fluent.proto"],
|
|
|
|
visibility = ["//visibility:public"],
|
|
|
|
)
|
2020-11-02 07:28:31 +01:00
|
|
|
|
|
|
|
proto_library(
|
|
|
|
name = "backend_proto_lib",
|
|
|
|
srcs = ["backend.proto"],
|
|
|
|
visibility = ["//visibility:public"],
|
|
|
|
)
|
|
|
|
|
|
|
|
exports_files(["backend.proto"])
|