summaryrefslogtreecommitdiff
path: root/rust/proc_macro.go
diff options
context:
space:
mode:
author Vinh Tran <vinhdaitran@google.com> 2023-08-24 11:10:01 -0400
committer Vinh Tran <vinhdaitran@google.com> 2023-08-25 17:50:48 -0400
commitb4bb20f583baa63aefb231871c6e707f9e60a786 (patch)
tree27b53eb9385df2d5d1eeaf7c5d92546050def605 /rust/proc_macro.go
parent3570ce3f69b4ded24e92c63c521d5c77782d0f9f (diff)
Implement bp2build converter for rust_proc_macro
Test: WIP Bug: 297356482 Change-Id: I17d1a0a95d4a67ccbc9b2d74e49bcacd6ff4d26b
Diffstat (limited to 'rust/proc_macro.go')
-rw-r--r--rust/proc_macro.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/rust/proc_macro.go b/rust/proc_macro.go
index 832b62c36..26227d048 100644
--- a/rust/proc_macro.go
+++ b/rust/proc_macro.go
@@ -16,6 +16,8 @@ package rust
import (
"android/soong/android"
+ "android/soong/bazel"
+ "fmt"
)
func init() {
@@ -47,6 +49,8 @@ func ProcMacroFactory() android.Module {
func NewProcMacro(hod android.HostOrDeviceSupported) (*Module, *procMacroDecorator) {
module := newModule(hod, android.MultilibFirst)
+ android.InitBazelModule(module)
+
procMacro := &procMacroDecorator{
baseCompiler: NewBaseCompiler("lib", "lib64", InstallInSystem),
flagExporter: NewFlagExporter(),
@@ -99,3 +103,65 @@ func (procMacro *procMacroDecorator) everInstallable() bool {
// Proc_macros are never installed
return false
}
+
+type procMacroAttributes struct {
+ Srcs bazel.LabelListAttribute
+ Compile_data bazel.LabelListAttribute
+ Crate_name bazel.StringAttribute
+ Edition bazel.StringAttribute
+ Crate_features bazel.StringListAttribute
+ Deps bazel.LabelListAttribute
+ Rustc_flags bazel.StringListAttribute
+}
+
+func procMacroBp2build(ctx android.TopDownMutatorContext, m *Module) {
+ procMacro := m.compiler.(*procMacroDecorator)
+ srcs, compileData := srcsAndCompileDataAttrs(ctx, *procMacro.baseCompiler)
+ deps := android.BazelLabelForModuleDeps(ctx, append(
+ procMacro.baseCompiler.Properties.Rustlibs,
+ procMacro.baseCompiler.Properties.Rlibs...,
+ ))
+
+ var rustcFLags []string
+ for _, cfg := range procMacro.baseCompiler.Properties.Cfgs {
+ rustcFLags = append(rustcFLags, fmt.Sprintf("--cfg=%s", cfg))
+ }
+
+ attrs := &procMacroAttributes{
+ Srcs: bazel.MakeLabelListAttribute(
+ srcs,
+ ),
+ Compile_data: bazel.MakeLabelListAttribute(
+ compileData,
+ ),
+ Crate_name: bazel.StringAttribute{
+ Value: &procMacro.baseCompiler.Properties.Crate_name,
+ },
+ Edition: bazel.StringAttribute{
+ Value: procMacro.baseCompiler.Properties.Edition,
+ },
+ Crate_features: bazel.StringListAttribute{
+ Value: procMacro.baseCompiler.Properties.Features,
+ },
+ Deps: bazel.MakeLabelListAttribute(
+ deps,
+ ),
+ Rustc_flags: bazel.StringListAttribute{
+ Value: append(
+ rustcFLags,
+ procMacro.baseCompiler.Properties.Flags...,
+ ),
+ },
+ }
+ // m.IsConvertedByBp2build()
+ ctx.CreateBazelTargetModule(
+ bazel.BazelTargetModuleProperties{
+ Rule_class: "rust_proc_macro",
+ Bzl_load_location: "@rules_rust//rust:defs.bzl",
+ },
+ android.CommonAttributes{
+ Name: m.Name(),
+ },
+ attrs,
+ )
+}