use protobuf binaries to reduce initial compile times

This commit is contained in:
Damien Elmes 2020-12-23 17:10:37 +10:00
parent 7a3e21daad
commit 9f1bd14527
4 changed files with 68 additions and 18 deletions

View file

@ -3,10 +3,10 @@ load("@bazel_skylib//lib:versions.bzl", "versions")
load("@io_bazel_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("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "yarn_install")
load("@io_bazel_rules_sass//:defs.bzl", "sass_repositories")
load("@build_bazel_rules_svelte//:defs.bzl", "rules_svelte_dependencies")
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
load("@com_github_ali5h_rules_pip//:defs.bzl", "pip_import")
load("//pip/pyqt5:defs.bzl", "install_pyqt5")
@ -26,6 +26,8 @@ def setup_deps():
setup_local_python(name = "python")
setup_protobuf_binary(name = "com_google_protobuf")
native.register_toolchains("@python//:python3_toolchain")
pip_import(
@ -50,5 +52,3 @@ def setup_deps():
sass_repositories()
rules_svelte_dependencies()
protobuf_deps()

View file

@ -1,2 +1,2 @@
Platform constraints. Currently only used to control wheel filenames
on a per-platform basis.
Platform constraints, used for things like controlling wheel filenames
on a per-platform basis, and selecting the correct protobuf binary.

63
protobuf.bzl Normal file
View file

@ -0,0 +1,63 @@
"""
Replace @com_google_protobuf with a platform binary.
Avoids the long initial compile, but will fail if anything depends on the protobuf library.
"""
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
def _impl(rctx):
rctx.file("BUILD.bazel", """
alias(
name = "protoc",
actual = select({
"@net_ankiweb_anki//platforms:windows_x86_64": "@protoc_bin_windows//:bin/protoc.exe",
"@net_ankiweb_anki//platforms:macos_x86_64": "@protoc_bin_macos//:bin/protoc",
"@net_ankiweb_anki//platforms:linux_x86_64": "@protoc_bin_linux//:bin/protoc"
}),
visibility = ["//visibility:public"]
)
""")
_setup_protoc = repository_rule(
implementation = _impl,
local = True,
attrs = {},
)
def setup_protobuf_binary(name):
maybe(
http_archive,
name = "protoc_bin_macos",
urls = [
"https://github.com/protocolbuffers/protobuf/releases/download/v3.14.0/protoc-3.14.0-osx-x86_64.zip",
],
sha256 = "699ceee7ef0988ecf72bf1c146dee5d9d89351a19d4093d30ebea3c04008bb8c",
build_file_content = """exports_files(["bin/protoc"])""",
)
maybe(
http_archive,
name = "protoc_bin_linux",
urls = [
"https://github.com/protocolbuffers/protobuf/releases/download/v3.14.0/protoc-3.14.0-linux-x86_64.zip",
],
sha256 = "a2900100ef9cda17d9c0bbf6a3c3592e809f9842f2d9f0d50e3fba7f3fc864f0",
build_file_content = """exports_files(["bin/protoc"])""",
)
maybe(
http_archive,
name = "protoc_bin_windows",
urls = [
"https://github.com/protocolbuffers/protobuf/releases/download/v3.14.0/protoc-3.14.0-win64.zip",
],
sha256 = "642554ed4dd2dba94e1afddcccdd7d832999cea309299cc5952f13db389894f8",
build_file_content = """exports_files(["bin/protoc.exe"])""",
)
if not native.existing_rule(name):
_setup_protoc(
name = name,
)

View file

@ -22,19 +22,6 @@ def register_repos():
],
)
# protobuf
############
maybe(
http_archive,
name = "com_google_protobuf",
sha256 = "6dd0f6b20094910fbb7f1f7908688df01af2d4f6c5c21331b9f636048674aebf",
strip_prefix = "protobuf-3.14.0",
urls = [
"https://github.com/protocolbuffers/protobuf/releases/download/v3.14.0/protobuf-all-3.14.0.tar.gz",
],
)
# rust
########