Skip to content

Commit

Permalink
chore: replaced pb files with pbtxt
Browse files Browse the repository at this point in the history
The binary .pb files are now generated during build and embedded as
previously in the binary itself. But repo contains text proto versions
of the files.

This provides more transparency about what is built into the binary
itself, and more visibility into what PRs change around those files
(for more informed reviews as well as less security concerns).
  • Loading branch information
hauserx committed Dec 9, 2024
1 parent 43d80e6 commit e0e3c6c
Show file tree
Hide file tree
Showing 8 changed files with 35,033 additions and 4,928 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
*.pb binary linguist-vendored
*.pbtxt linguist-generated
4 changes: 4 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ rust_binary(
"//src/builtin:default_build_language.pb",
],
rustc_env_files = [":generate_rustc_env_file"],
rustc_env = {
"BUILTIN_PB" : "$(execpath //src/builtin:builtin.pb)",
"DEFAULT_BUILD_LANGUAGE_PB" : "$(execpath //src/builtin:default_build_language.pb)",
},
deps = [
"//src/builtin:build_proto_rust",
"//src/builtin:builtin_proto_rust",
Expand Down
4 changes: 2 additions & 2 deletions src/bazel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,13 +473,13 @@ impl<Client: BazelClient> BazelContext<Client> {

let language_proto = language_proto
.as_deref()
.unwrap_or(include_bytes!("builtin/default_build_language.pb"));
.unwrap_or(include_bytes!(env!("DEFAULT_BUILD_LANGUAGE_PB")));

let language = builtin::BuildLanguage::decode(&language_proto[..]).unwrap();

// TODO: builtins are also dependent on bazel version, but there is no way to obtain those,
// see https://github.com/bazel-contrib/vscode-bazel/issues/1.
let builtins_proto = include_bytes!("builtin/builtin.pb");
let builtins_proto = include_bytes!(env!("BUILTIN_PB"));
let builtins = builtin::Builtins::decode(&builtins_proto[..]).unwrap();

(language, builtins)
Expand Down
51 changes: 43 additions & 8 deletions src/builtin/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,46 @@ rust_prost_library(
visibility = ["//visibility:public"],
)

exports_files([
# Built from the bazel repo using:
# `bazel build //src/main/java/com/google/devtools/build/lib:gen_api_proto`
"builtin.pb",
# Obtained from bazel instance with:
# `bazel info build-language`
"default_build_language.pb",
])
# The pbtxt file can be obtained from bazel instance:
# bazel info build-language | protoc --decode=blaze_query.BuildLanguage --proto_path <BAZEL_REPO> src/main/protobuf/build.proto > default_build_language.pbtxt
genrule(
name = "default_build_language_pbtxt_to_pb",
srcs = [
":default_build_language.pbtxt",
],
outs = ["default_build_language.pb"],
tools = [
"@protobuf//:protoc",
"@bazel_tools//src/main/protobuf:build_proto",
],
cmd = "cat $(execpath :default_build_language.pbtxt) | " +
"$(execpath @protobuf//:protoc) " +
"--encode=blaze_query.BuildLanguage " +
"--deterministic_output " +
"--descriptor_set_in=$(execpath @bazel_tools//src/main/protobuf:build_proto) " +
"> $@",
visibility = ["//visibility:public"],
)

# The pbtxt file can be obtained from within bazel repository:
#
# bazel build src/main/java/com/google/devtools/build/lib:gen_api_proto
# cat bazel-bin/src/main/java/com/google/devtools/build/lib/builtin.pb | protoc --decode=builtin.Builtins --proto_path src/main/protobuf builtin.proto > builtin.pbtxt
genrule(
name = "builtin_pbtxt_to_pb",
srcs = [
":builtin.pbtxt",
],
outs = ["builtin.pb"],
tools = [
"@protobuf//:protoc",
"@bazel_tools//src/main/protobuf:builtin_proto",
],
cmd = "cat $(execpath :builtin.pbtxt) | " +
"$(execpath @protobuf//:protoc) " +
"--encode=builtin.Builtins " +
"--deterministic_output " +
"--descriptor_set_in=$(execpath @bazel_tools//src/main/protobuf:builtin_proto) " +
"> $@",
visibility = ["//visibility:public"],
)
4,917 changes: 0 additions & 4,917 deletions src/builtin/builtin.pb

This file was deleted.

Loading

0 comments on commit e0e3c6c

Please sign in to comment.