Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0c0b0d68 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Add bp2build for rust_protobuf module" into main

parents b5a1bbff 47faaad2
Loading
Loading
Loading
Loading
+30 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ func runRustProtobufTestCase(t *testing.T, tc Bp2buildTestCase) {

func registerRustProtobufModuleTypes(ctx android.RegistrationContext) {
	ctx.RegisterModuleType("rust_protobuf_host", rust.RustProtobufHostFactory)

	ctx.RegisterModuleType("rust_protobuf", rust.RustProtobufHostFactory)
}

func TestRustProtobufHostTestCase(t *testing.T) {
@@ -58,3 +58,32 @@ rust_protobuf_host {
	},
	)
}

func TestRustProtobufTestCase(t *testing.T) {
	runRustProtobufTestCase(t, Bp2buildTestCase{
		Dir:       "external/rust/crates/foo",
		Blueprint: "",
		Filesystem: map[string]string{
			"external/rust/crates/foo/src/lib.rs":    "",
			"external/rust/crates/foo/src/helper.rs": "",
			"external/rust/crates/foo/Android.bp": `
rust_protobuf {
	name: "libfoo",
	crate_name: "foo",
	protos: ["src/foo.proto"],
    bazel_module: { bp2build_available: true },
}
`,
		},
		ExpectedBazelTargets: []string{
			makeBazelTargetHostOrDevice("proto_library", "libfoo_proto", AttrNameToString{
				"srcs": `["src/foo.proto"]`,
			}, android.HostSupported),
			makeBazelTargetHostOrDevice("rust_proto_library", "libfoo", AttrNameToString{
				"crate_name": `"foo"`,
				"deps":       `[":libfoo_proto"]`,
			}, android.HostSupported),
		},
	},
	)
}
+8 −2
Original line number Diff line number Diff line
@@ -305,7 +305,11 @@ func protoLibraryBp2build(ctx android.Bp2buildMutatorContext, m *Module) {
		},
	}

	ctx.CreateBazelTargetModule(
	// TODO(b/295918553): Remove androidRestriction after rust toolchain for android is checked in.
	var androidRestriction bazel.BoolAttribute
	androidRestriction.SetSelectValue(bazel.OsConfigurationAxis, "android", proptools.BoolPtr(false))

	ctx.CreateBazelTargetModuleWithRestrictions(
		bazel.BazelTargetModuleProperties{
			Rule_class: "proto_library",
		},
@@ -317,9 +321,10 @@ func protoLibraryBp2build(ctx android.Bp2buildMutatorContext, m *Module) {
				android.BazelLabelForModuleSrc(ctx, protoFiles),
			),
		},
		androidRestriction,
	)

	ctx.CreateBazelTargetModule(
	ctx.CreateBazelTargetModuleWithRestrictions(
		bazel.BazelTargetModuleProperties{
			Rule_class:        "rust_proto_library",
			Bzl_load_location: "@rules_rust//proto/protobuf:defs.bzl",
@@ -333,5 +338,6 @@ func protoLibraryBp2build(ctx android.Bp2buildMutatorContext, m *Module) {
			},
			Deps: protoDeps,
		},
		androidRestriction,
	)
}
+1 −1
Original line number Diff line number Diff line
@@ -1853,7 +1853,7 @@ func (m *Module) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
		procMacroBp2build(ctx, m)
	} else if ctx.ModuleType() == "rust_binary_host" {
		binaryBp2build(ctx, m)
	} else if ctx.ModuleType() == "rust_protobuf_host" {
	} else if ctx.ModuleType() == "rust_protobuf_host" || ctx.ModuleType() == "rust_protobuf" {
		protoLibraryBp2build(ctx, m)
	} else {
		ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_TYPE_UNSUPPORTED, "")