Add pkg build rules to create a zip of the protobuf rust crate
PiperOrigin-RevId: 657215370
diff --git a/rust/BUILD b/rust/BUILD
index d403bb3..43b6e6a 100644
--- a/rust/BUILD
+++ b/rust/BUILD
@@ -1,6 +1,12 @@
# Protobuf Rust runtime packages.
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
+
+# begin:github_only
+load("@rules_pkg//pkg:mappings.bzl", "pkg_filegroup", "pkg_files", "strip_prefix")
+load("@rules_pkg//pkg:zip.bzl", "pkg_zip")
+# end:github_only
+
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
load("//bazel/toolchains:proto_lang_toolchain.bzl", "proto_lang_toolchain")
@@ -203,3 +209,57 @@
":rust_proto_library_kernel": "upb",
},
)
+
+# begin:github_only
+# pkg_files(
+# name = "rust_protobuf_src",
+# srcs = glob(
+# [
+# "*",
+# ],
+# ),
+# strip_prefix = strip_prefix.from_root("rust"),
+# visibility = ["//:__pkg__"],
+# )
+
+# pkg_files(
+# name = "crate_root_files",
+# srcs = glob(["cargo/**/*"]),
+# strip_prefix = strip_prefix.from_root("rust/cargo"),
+# visibility = ["//:__pkg__"],
+# )
+
+# pkg_filegroup(
+# name = "rust_protobuf_src_dir",
+# srcs = [
+# ":rust_protobuf_src",
+# "//rust/upb:rust_protobuf_upb_src",
+# ],
+# prefix = "src",
+# )
+
+# pkg_files(
+# name = "amalgamated_upb",
+# srcs = ["//upb:gen_amalgamation"],
+# strip_prefix = strip_prefix.from_root(""),
+# )
+
+# pkg_filegroup(
+# name = "rust_protobuf_libupb_src",
+# srcs = [
+# ":amalgamated_upb",
+# "//upb/cmake:upb_cmake_dist",
+# ],
+# prefix = "libupb",
+# )
+
+# pkg_zip(
+# name = "rust_crate",
+# srcs = [
+# ":crate_root_files",
+# ":rust_protobuf_libupb_src",
+# ":rust_protobuf_src_dir",
+# "//:LICENSE",
+# ],
+# )
+# end:github_only
diff --git a/rust/cargo/Cargo.toml b/rust/cargo/Cargo.toml
index 2d8e44b..7a389e7 100644
--- a/rust/cargo/Cargo.toml
+++ b/rust/cargo/Cargo.toml
@@ -1,8 +1,16 @@
+# Protocol Buffers - Google's data interchange format
+# Copyright 2024 Google LLC. All rights reserved.
+
+# Use of this source code is governed by a BSD-style
+# license that can be found in the LICENSE file or at
+# https://developers.google.com/open-source/licenses/bsd
+
[package]
name = "protobuf"
version = "4.27.3-beta.0"
edition = "2021"
-links = "upb"
+links = "libupb"
+license = "BSD-3-Clause"
[lib]
path = "src/shared.rs"
@@ -14,7 +22,7 @@
googletest = {git = "https://github.com/google/googletest-rust.git" }
[build-dependencies]
-cmake = "0.1.50"
+cc = "1.1.6"
[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(bzl)', 'cfg(cpp_kernel)', 'cfg(upb_kernel)'] }
\ No newline at end of file
diff --git a/rust/cargo/build.rs b/rust/cargo/build.rs
index e400e15..c69ef7c 100644
--- a/rust/cargo/build.rs
+++ b/rust/cargo/build.rs
@@ -1,16 +1,21 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2024 Google LLC. All rights reserved.
+
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file or at
+// https://developers.google.com/open-source/licenses/bsd
+
fn main() {
cc::Build::new()
.flag("-std=c99")
// TODO: Come up with a way to enable lto
// .flag("-flto=thin")
.warnings(false)
- .include("src")
- .file("src/upb.c")
- .file("src/utf8_range.c")
- .file("src/upb/upb_api.c")
+ .include("libupb")
+ .file("libupb/upb/upb.c")
+ .file("libupb/third_party/utf8_range/utf8_range.c")
.define("UPB_BUILD_API", Some("1"))
- .define("PROTOBUF_CARGO", Some("1"))
- .compile("upb");
- let path = std::path::Path::new("src");
+ .compile("libupb");
+ let path = std::path::Path::new("libupb");
println!("cargo:include={}", path.canonicalize().unwrap().display())
}
diff --git a/rust/upb/BUILD b/rust/upb/BUILD
index 3cd2c5e..4ac6a3f 100644
--- a/rust/upb/BUILD
+++ b/rust/upb/BUILD
@@ -4,6 +4,10 @@
# license that can be found in the LICENSE file or at
# https://developers.google.com/open-source/licenses/bsd
+# begin:github_only
+load("@rules_pkg//pkg:mappings.bzl", "pkg_filegroup", "pkg_files", "strip_prefix")
+# end:github_only
+
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
# begin:google_only
@@ -53,3 +57,16 @@
"//upb/text:debug",
],
)
+
+# begin:github_only
+pkg_files(
+ name = "rust_protobuf_upb_src",
+ srcs = glob(
+ [
+ "*",
+ ],
+ ),
+ strip_prefix = strip_prefix.from_root("rust"),
+ visibility = ["//rust:__pkg__"],
+)
+# end:github_only
diff --git a/upb/BUILD b/upb/BUILD
index 42797dc..b46ee4b 100644
--- a/upb/BUILD
+++ b/upb/BUILD
@@ -288,6 +288,7 @@
"//upb/reflection:internal",
],
strip_import_prefix = ["src"],
+ visibility = ["//rust:__pkg__"],
)
cc_library(
diff --git a/upb/cmake/BUILD.bazel b/upb/cmake/BUILD.bazel
index e17ce84..fdf0f23 100644
--- a/upb/cmake/BUILD.bazel
+++ b/upb/cmake/BUILD.bazel
@@ -5,6 +5,7 @@
# license that can be found in the LICENSE file or at
# https://developers.google.com/open-source/licenses/bsd
+load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix")
load(
"//upb/bazel:build_defs.bzl",
"make_shell_script",
@@ -106,3 +107,26 @@
}),
deps = ["@bazel_tools//tools/bash/runfiles"],
)
+
+pkg_files(
+ name = "upb_cmake_dist",
+ srcs = [
+ ":copy_protos",
+ ":gen_cmakelists",
+ "//third_party/utf8_range:utf8_range_srcs",
+ "//upb:source_files",
+ "//upb/base:source_files",
+ "//upb/hash:source_files",
+ "//upb/lex:source_files",
+ "//upb/mem:source_files",
+ "//upb/message:source_files",
+ "//upb/mini_descriptor:source_files",
+ "//upb/mini_table:source_files",
+ "//upb/port:source_files",
+ "//upb/reflection:source_files",
+ "//upb/text:source_files",
+ "//upb/wire:source_files",
+ ],
+ strip_prefix = strip_prefix.from_root(""),
+ visibility = ["//rust:__pkg__"],
+)