move protobuf into separate folder in preparation for multiple files
This commit is contained in:
parent
00f5d9ff96
commit
80b98e0db8
2
defs.bzl
2
defs.bzl
@ -4,7 +4,7 @@ load("@rules_rust//rust:repositories.bzl", "rust_repositories")
|
||||
load("@net_ankiweb_anki//cargo:crates.bzl", "raze_fetch_remote_crates")
|
||||
load(":python.bzl", "setup_local_python")
|
||||
load(":protobuf.bzl", "setup_protobuf_binary")
|
||||
load("//rslib:clang_format.bzl", "setup_clang_format")
|
||||
load("//proto:format.bzl", "setup_clang_format")
|
||||
load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "yarn_install")
|
||||
load("@io_bazel_rules_sass//:defs.bzl", "sass_repositories")
|
||||
load("@com_github_ali5h_rules_pip//:defs.bzl", "pip_import")
|
||||
|
18
proto/BUILD.bazel
Normal file
18
proto/BUILD.bazel
Normal file
@ -0,0 +1,18 @@
|
||||
# Copyright: Ankitects Pty Ltd and contributors
|
||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
load("@rules_proto//proto:defs.bzl", "proto_library")
|
||||
load("//proto:clang_format.bzl", "proto_format")
|
||||
|
||||
proto_format(
|
||||
name = "format",
|
||||
srcs = ["backend.proto"],
|
||||
)
|
||||
|
||||
proto_library(
|
||||
name = "backend_proto_lib",
|
||||
srcs = ["backend.proto"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
exports_files(["backend.proto"])
|
@ -68,7 +68,7 @@ def proto_format(name, srcs, **kwargs):
|
||||
py_test(
|
||||
name = name,
|
||||
srcs = [
|
||||
"proto_format.py",
|
||||
"format.py",
|
||||
],
|
||||
data = ["@clang_format//:clang_format"] + srcs,
|
||||
args = ["$(location @clang_format//:clang_format)"] + [native.package_name() + "/" + f for f in srcs],
|
76
proto/format.bzl
Normal file
76
proto/format.bzl
Normal file
@ -0,0 +1,76 @@
|
||||
# Copyright: Ankitects Pty Ltd and contributors
|
||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
"""
|
||||
Exposes a clang-format binary for formatting protobuf.
|
||||
"""
|
||||
|
||||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
|
||||
load("@rules_python//python:defs.bzl", "py_test")
|
||||
|
||||
def _impl(rctx):
|
||||
rctx.file("BUILD.bazel", """
|
||||
alias(
|
||||
name = "clang_format",
|
||||
actual = select({
|
||||
"@net_ankiweb_anki//platforms:windows_x86_64": "@clang_format_windows_x86_64//:clang-format.exe",
|
||||
"@net_ankiweb_anki//platforms:macos_x86_64": "@clang_format_macos_x86_64//:clang-format",
|
||||
"@net_ankiweb_anki//platforms:linux_x86_64": "@clang_format_linux_x86_64//:clang-format",
|
||||
}),
|
||||
visibility = ["//visibility:public"]
|
||||
)
|
||||
""")
|
||||
|
||||
_setup_clang_format = repository_rule(
|
||||
attrs = {},
|
||||
local = True,
|
||||
implementation = _impl,
|
||||
)
|
||||
|
||||
def setup_clang_format(name):
|
||||
maybe(
|
||||
http_archive,
|
||||
name = "clang_format_macos_x86_64",
|
||||
build_file_content = """exports_files(["clang-format"])""",
|
||||
sha256 = "238be68d9478163a945754f06a213483473044f5a004c4125d3d9d8d3556466e",
|
||||
urls = [
|
||||
"https://github.com/ankitects/clang-format-binaries/releases/download/anki-2021-01-09/clang-format_macos_x86_64.zip",
|
||||
],
|
||||
)
|
||||
|
||||
maybe(
|
||||
http_archive,
|
||||
name = "clang_format_linux_x86_64",
|
||||
build_file_content = """exports_files(["clang-format"])""",
|
||||
sha256 = "64060bc4dbca30d0d96aab9344e2783008b16e1cae019a2532f1126ca5ec5449",
|
||||
urls = [
|
||||
"https://github.com/ankitects/clang-format-binaries/releases/download/anki-2021-01-09/clang-format_linux_x86_64.zip",
|
||||
],
|
||||
)
|
||||
|
||||
maybe(
|
||||
http_archive,
|
||||
name = "clang_format_windows_x86_64",
|
||||
build_file_content = """exports_files(["clang-format.exe"])""",
|
||||
sha256 = "7d9f6915e3f0fb72407830f0fc37141308d2e6915daba72987a52f309fbeaccc",
|
||||
urls = [
|
||||
"https://github.com/ankitects/clang-format-binaries/releases/download/anki-2021-01-09/clang-format_windows_x86_64.zip",
|
||||
],
|
||||
)
|
||||
|
||||
if not native.existing_rule(name):
|
||||
_setup_clang_format(
|
||||
name = name,
|
||||
)
|
||||
|
||||
def proto_format(name, srcs, **kwargs):
|
||||
py_test(
|
||||
name = name,
|
||||
srcs = [
|
||||
"format.py",
|
||||
],
|
||||
data = ["@clang_format//:clang_format"] + srcs,
|
||||
args = ["$(location @clang_format//:clang_format)"] + [native.package_name() + "/" + f for f in srcs],
|
||||
**kwargs
|
||||
)
|
@ -6,7 +6,7 @@ load("@bazel_skylib//lib:selects.bzl", "selects")
|
||||
|
||||
py_proto_library_typed(
|
||||
name = "backend_pb2",
|
||||
src = "//rslib:backend.proto",
|
||||
src = "//proto:backend.proto",
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
],
|
||||
|
@ -1,11 +1,9 @@
|
||||
# Copyright: Ankitects Pty Ltd and contributors
|
||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
load("@rules_proto//proto:defs.bzl", "proto_library")
|
||||
load("@rules_rust//rust:rust.bzl", "rust_binary", "rust_library", "rust_test")
|
||||
load("@rules_rust//cargo:cargo_build_script.bzl", "cargo_build_script")
|
||||
load(":rustfmt.bzl", "rustfmt_fix", "rustfmt_test")
|
||||
load(":clang_format.bzl", "proto_format")
|
||||
load("//ts:sql_format.bzl", "sql_format")
|
||||
|
||||
# Build script
|
||||
@ -15,7 +13,7 @@ cargo_build_script(
|
||||
name = "build_script",
|
||||
srcs = glob(["build/*.rs"]),
|
||||
build_script_env = {
|
||||
"BACKEND_PROTO": "$(location backend.proto)",
|
||||
"BACKEND_PROTO": "$(location //proto:backend.proto)",
|
||||
"PROTOC": "$(location @com_google_protobuf//:protoc)",
|
||||
"RSLIB_FTL_ROOT": "$(location @rslib_ftl//:l10n.toml)",
|
||||
"EXTRA_FTL_ROOT": "$(location @extra_ftl//:l10n.toml)",
|
||||
@ -24,7 +22,7 @@ cargo_build_script(
|
||||
crate_root = "build/main.rs",
|
||||
data = [
|
||||
"//ftl",
|
||||
"backend.proto",
|
||||
"//proto:backend.proto",
|
||||
"@com_google_protobuf//:protoc",
|
||||
# bazel requires us to list these out separately
|
||||
"@rslib_ftl//:l10n.toml",
|
||||
@ -163,19 +161,3 @@ sql_format(
|
||||
name = "sql_format",
|
||||
srcs = glob(["**/*.sql"]),
|
||||
)
|
||||
|
||||
proto_format(
|
||||
name = "proto_format",
|
||||
srcs = ["backend.proto"],
|
||||
)
|
||||
|
||||
# backend.proto
|
||||
#######################
|
||||
|
||||
proto_library(
|
||||
name = "backend_proto_lib",
|
||||
srcs = ["backend.proto"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
exports_files(["backend.proto"])
|
||||
|
@ -80,7 +80,7 @@ pub fn write_backend_proto_rs() {
|
||||
proto_dir = backend_proto.parent().unwrap().to_owned();
|
||||
} else {
|
||||
backend_proto = PathBuf::from("backend.proto");
|
||||
proto_dir = PathBuf::from(".");
|
||||
proto_dir = PathBuf::from("../proto");
|
||||
}
|
||||
println!("cargo:rerun-if-changed={}", backend_proto.to_str().unwrap());
|
||||
|
||||
|
@ -9,7 +9,7 @@ load("//ts:jest.bzl", "jest_test")
|
||||
|
||||
protobufjs_library(
|
||||
name = "backend_proto",
|
||||
proto = "//rslib:backend_proto_lib",
|
||||
proto = "//proto:backend_proto_lib",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user