Skip to content

Commit

Permalink
Add Cargo packages for proc macro.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 732342560
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Mar 1, 2025
1 parent 87a2b46 commit 24830cf
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 5 deletions.
19 changes: 19 additions & 0 deletions rust/proto_proc_macro/BUILD
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
# This directory contains the implementation of the proto! macro as a proc macro.
# It has not yet been made to work with bazel and so no targets are defined here.

load("@rules_pkg//pkg:mappings.bzl", "pkg_filegroup", "pkg_files", "strip_prefix")

PROC_MACRO_IMPL_SRCS = ["proto_proc_macro_impl.rs"]

pkg_files(
name = "rust_protobuf_macros_src",
srcs = PROC_MACRO_IMPL_SRCS,
strip_prefix = strip_prefix.from_root("rust/proto_proc_macro"),
)

pkg_filegroup(
name = "rust_protobuf_macros_src_dir",
srcs = [
":rust_protobuf_macros_src",
],
prefix = "src",
visibility = ["//rust/release_crates:__subpackages__"],
)
5 changes: 0 additions & 5 deletions rust/proto_proc_macro/proto_proc_macro_impl.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
google3::import! {
"//third_party/rust/quote/v1:quote";
"//third_party/rust/syn/v2:syn";
}

extern crate proc_macro;

use quote::{format_ident, quote, ToTokens};
Expand Down
1 change: 1 addition & 0 deletions rust/release_crates/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ filegroup(
"//rust/release_crates/protobuf:protobuf_crate",
"//rust/release_crates/protobuf_codegen:protobuf_codegen_crate",
"//rust/release_crates/protobuf_example:protobuf_example_crate",
"//rust/release_crates/protobuf_macros:protobuf_macros_crate",
"//rust/release_crates/protobuf_well_known_types:crate",
],
)
Expand Down
13 changes: 13 additions & 0 deletions rust/release_crates/cargo_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ EXAMPLE_TAR=$(rlocation com_google_protobuf/rust/release_crates/protobuf_example
echo "Expanding protobuf_example crate tar"
tar -xvf $EXAMPLE_TAR -C $EXAMPLE_ROOT

MACROS_ROOT=$TMP_DIR/protobuf_macros
mkdir $MACROS_ROOT

MACROS_TAR=$(rlocation com_google_protobuf/rust/release_crates/protobuf_macros/protobuf_macros_crate.tar)

echo "Expanding protobuf_macros crate tar"
tar -xvf $MACROS_TAR -C $MACROS_ROOT

WELL_KNOWN_TYPES_ROOT=$TMP_DIR/protobuf_well_known_types
mkdir $WELL_KNOWN_TYPES_ROOT

Expand All @@ -80,10 +88,15 @@ CARGO_HOME=$CARGO_HOME cargo publish --dry-run
cd $EXAMPLE_ROOT
CARGO_HOME=$CARGO_HOME cargo test

cd $MACROS_ROOT
# Macros should be tested by the main protobuf test suite.
CARGO_HOME=$CARGO_HOME cargo publish --dry-run

cd $WELL_KNOWN_TYPES_ROOT
CARGO_HOME=$CARGO_HOME cargo test

# TODO: Cannot enable this dry-run yet because it checks that the versions of
# its dependencies are published on crates.io, which they are definitely not
# in this case.
# See also https://github.com/rust-lang/cargo/issues/1169.
# CARGO_HOME=$CARGO_HOME cargo publish --dry-run
33 changes: 33 additions & 0 deletions rust/release_crates/protobuf_macros/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
load("//rust/release_crates:substitute_rust_release_version.bzl", "substitute_rust_release_version")

pkg_tar(
name = "protobuf_macros_crate",
srcs = [
":crate_root_files",
"//:LICENSE",
"//rust/proto_proc_macro:rust_protobuf_macros_src_dir",
],
visibility = ["//rust:__subpackages__"],
)

pkg_files(
name = "crate_root_files",
srcs = [":srcs"],
strip_prefix = strip_prefix.from_root("rust/release_crates/protobuf_macros"),
)

substitute_rust_release_version(
src = "Cargo-template.toml",
out = "Cargo.toml",
)

filegroup(
name = "srcs",
srcs = [
"Cargo.toml",
"README.md",
],
visibility = ["//rust:__subpackages__"],
)
22 changes: 22 additions & 0 deletions rust/release_crates/protobuf_macros/Cargo-template.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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-macros"
version = "{VERSION}"
edition = "2021" # The Rust edition (not to be confused with Protobuf Edition).
license = "BSD-3-Clause"
rust-version = "1.74"
description = "Protobuf proc macro implementation (internal)"

[lib]
path = "src/proto_proc_macro_impl.rs"
proc-macro = true

[dependencies]
quote = "1.0.38"
syn = { version = "2.0.98", features = ["full"] }
1 change: 1 addition & 0 deletions rust/release_crates/protobuf_macros/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Internal crate. Use [protobuf](http://crates.io/crates/protobuf) instead.
1 change: 1 addition & 0 deletions rust/release_crates/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ CARGO_HOME=$CARGO_HOME CARGO_REGISTRY_TOKEN=$AUTH_TOKEN cargo publish
cd $EXAMPLE_ROOT
CARGO_HOME=$CARGO_HOME CARGO_REGISTRY_TOKEN=$AUTH_TOKEN cargo publish

# TODO: Add protobuf_macros to release script.

0 comments on commit 24830cf

Please sign in to comment.