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

Commit 54a59058 authored by Vinh Tran's avatar Vinh Tran Committed by Gerrit Code Review
Browse files

Merge changes from topics "build-aconfig", "build-libprotobuf-for-host-only" into main

* changes:
  Allowlist aconfig
  Implement bp2build converter for rust_protobuf_host
  Implement bp2build converter for rust_binary
  Convert libprotobuf to Bazel
  Allowlist all aconfig deps modulo libprotobuf and libaconfig_protos
  Implement bp2build converter for rust_proc_macro
  Allowlist rust_library dependencies of aconfig
  Implement bp2build converter for rust_library
parents 1725b20d 85b177df
Loading
Loading
Loading
Loading
+63 −0
Original line number Diff line number Diff line
@@ -488,6 +488,55 @@ var (
	}

	Bp2buildModuleAlwaysConvertList = []string{
		// aconfig
		"libonce_cell",
		"libanyhow",
		"libunicode_segmentation",
		"libmemchr",
		"libbitflags-1.3.2",
		"libryu",
		"libitoa",
		"libos_str_bytes",
		"libheck",
		"libclap_lex",
		"libsyn",
		"libquote",
		"libunicode_ident",
		"libproc_macro2",
		"libthiserror_impl",
		"libserde_derive",
		"libclap_derive",
		"libthiserror",
		"libserde",
		"libclap",
		"libbytes",
		"libprotobuf_support",
		"libtinytemplate",
		"libserde_json",
		"libprotobuf",

		"protoc-gen-rust",
		"libprotobuf_codegen",
		"libprotobuf_parse",
		"libregex",
		"libtempfile",
		"libwhich",
		"libregex_syntax",
		"libfastrand",
		"libeither",
		"libaho_corasick",
		"liblibc",
		"libcfg_if",
		"liblog_rust",
		"libgetrandom",
		"libremove_dir_all",
		"libahash",
		"libhashbrown",
		"libindexmap",
		"libaconfig_protos",
		"libpaste",
		"aconfig",

		// ext
		"tagsoup",

@@ -881,6 +930,20 @@ var (
	// the "prebuilt_" prefix to the name, so that it's differentiable from
	// the source versions within Soong's module graph.
	Bp2buildModuleDoNotConvertList = []string{
		// rust modules that have cc deps
		"liblogger",
		"libbssl_ffi",
		"libbssl_ffi_nostd",
		"pull_rust",
		"libstatslog_rust",
		"libstatslog_rust_header",
		"libflatbuffers",
		"liblog_event_list",
		"libminijail_rust",
		"libminijail_sys",
		"libfsverity_rs",
		"libtombstoned_client_rust",

		// TODO(b/263326760): Failed already.
		"minijail_compiler_unittest",
		"minijail_parser_unittest",
+74 −0
Original line number Diff line number Diff line
package bp2build

import (
	"android/soong/android"
	"android/soong/rust"
	"testing"
)

func runRustBinaryTestCase(t *testing.T, tc Bp2buildTestCase) {
	t.Helper()
	RunBp2BuildTestCase(t, registerRustBinaryModuleTypes, tc)
}

func registerRustBinaryModuleTypes(ctx android.RegistrationContext) {
	ctx.RegisterModuleType("rust_binary_host", rust.RustBinaryHostFactory)
	ctx.RegisterModuleType("rust_library_host", rust.RustLibraryHostFactory)
	ctx.RegisterModuleType("rust_proc_macro", rust.ProcMacroFactory)

}

func TestRustBinaryHost(t *testing.T) {
	runRustBinaryTestCase(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_binary_host {
	name: "libfoo",
	crate_name: "foo",
	srcs: ["src/main.rs"],
	edition: "2021",
	features: ["bah-enabled"],
	cfgs: ["baz"],
	rustlibs: ["libbar"],
	proc_macros: ["libbah"],
    bazel_module: { bp2build_available: true },
}
`,
			"external/rust/crates/bar/Android.bp": `
rust_library_host {
	name: "libbar",
	crate_name: "bar",
	srcs: ["src/lib.rs"],
    bazel_module: { bp2build_available: true },
}
`,
			"external/rust/crates/bah/Android.bp": `
rust_proc_macro {
	name: "libbah",
	crate_name: "bah",
	srcs: ["src/lib.rs"],
    bazel_module: { bp2build_available: true },
}
`,
		},
		ExpectedBazelTargets: []string{
			makeBazelTargetHostOrDevice("rust_binary", "libfoo", AttrNameToString{
				"crate_name": `"foo"`,
				"srcs": `[
        "src/helper.rs",
        "src/lib.rs",
    ]`,
				"deps":            `["//external/rust/crates/bar:libbar"]`,
				"proc_macro_deps": `["//external/rust/crates/bah:libbah"]`,
				"edition":         `"2021"`,
				"crate_features":  `["bah-enabled"]`,
				"rustc_flags":     `["--cfg=baz"]`,
			}, android.HostSupported),
		},
	},
	)
}
+96 −0
Original line number Diff line number Diff line
package bp2build

import (
	"android/soong/android"
	"android/soong/rust"
	"testing"
)

func runRustLibraryTestCase(t *testing.T, tc Bp2buildTestCase) {
	t.Helper()
	RunBp2BuildTestCase(t, registerRustLibraryModuleTypes, tc)
}

func registerRustLibraryModuleTypes(ctx android.RegistrationContext) {
	ctx.RegisterModuleType("rust_library", rust.RustLibraryFactory)
	ctx.RegisterModuleType("rust_library_host", rust.RustLibraryHostFactory)
}

func TestLibProtobuf(t *testing.T) {
	runRustLibraryTestCase(t, Bp2buildTestCase{
		Dir:       "external/rust/crates/foo",
		Blueprint: "",
		Filesystem: map[string]string{
			"external/rust/crates/foo/src/lib.rs": "",
			"external/rust/crates/foo/Android.bp": `
rust_library_host {
	name: "libprotobuf",
	crate_name: "protobuf",
	srcs: ["src/lib.rs"],
    bazel_module: { bp2build_available: true },
}
`,
		},
		ExpectedBazelTargets: []string{
			// TODO(b/290790800): Remove the restriction when rust toolchain for android is implemented
			makeBazelTargetHostOrDevice("rust_library", "libprotobuf", AttrNameToString{
				"crate_name": `"protobuf"`,
				"srcs":       `["src/lib.rs"]`,
				"deps":       `[":libprotobuf_build_script"]`,
			}, android.HostSupported),
			makeBazelTargetHostOrDevice("cargo_build_script", "libprotobuf_build_script", AttrNameToString{
				"srcs": `["build.rs"]`,
			}, android.HostSupported),
		},
	},
	)
}

func TestRustLibrary(t *testing.T) {
	expectedAttrs := AttrNameToString{
		"crate_name": `"foo"`,
		"srcs": `[
        "src/helper.rs",
        "src/lib.rs",
    ]`,
		"crate_features": `["bah-enabled"]`,
		"edition":        `"2021"`,
		"rustc_flags":    `["--cfg=baz"]`,
	}

	runRustLibraryTestCase(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_library {
	name: "libfoo",
	crate_name: "foo",
    host_supported: true,
	srcs: ["src/lib.rs"],
	edition: "2021",
	features: ["bah-enabled"],
	cfgs: ["baz"],
    bazel_module: { bp2build_available: true },
}
rust_library_host {
    name: "libfoo_host",
    crate_name: "foo",
    srcs: ["src/lib.rs"],
    edition: "2021",
    features: ["bah-enabled"],
    cfgs: ["baz"],
    bazel_module: { bp2build_available: true },
}
`,
		},
		ExpectedBazelTargets: []string{
			// TODO(b/290790800): Remove the restriction when rust toolchain for android is implemented
			makeBazelTargetHostOrDevice("rust_library", "libfoo", expectedAttrs, android.HostSupported),
			makeBazelTargetHostOrDevice("rust_library", "libfoo_host", expectedAttrs, android.HostSupported),
		},
	},
	)
}
+62 −0
Original line number Diff line number Diff line
package bp2build

import (
	"android/soong/android"
	"android/soong/rust"
	"testing"
)

func rustRustProcMacroTestCase(t *testing.T, tc Bp2buildTestCase) {
	t.Helper()
	RunBp2BuildTestCase(t, registerRustProcMacroModuleTypes, tc)
}

func registerRustProcMacroModuleTypes(ctx android.RegistrationContext) {
	ctx.RegisterModuleType("rust_library_host", rust.RustLibraryHostFactory)
	ctx.RegisterModuleType("rust_proc_macro", rust.ProcMacroFactory)
}

func TestRustProcMacroLibrary(t *testing.T) {
	runRustLibraryTestCase(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_proc_macro {
	name: "libfoo",
	crate_name: "foo",
	srcs: ["src/lib.rs"],
	edition: "2021",
	features: ["bah-enabled"],
	cfgs: ["baz"],
	rustlibs: ["libbar"],
    bazel_module: { bp2build_available: true },
}
`,
			"external/rust/crates/bar/src/lib.rs": "",
			"external/rust/crates/bar/Android.bp": `
rust_library_host {
    name: "libbar",
    crate_name: "bar",
    srcs: ["src/lib.rs"],
    bazel_module: { bp2build_available: true },
}`,
		},
		ExpectedBazelTargets: []string{
			makeBazelTargetHostOrDevice("rust_proc_macro", "libfoo", AttrNameToString{
				"crate_name": `"foo"`,
				"srcs": `[
        "src/helper.rs",
        "src/lib.rs",
    ]`,
				"crate_features": `["bah-enabled"]`,
				"edition":        `"2021"`,
				"rustc_flags":    `["--cfg=baz"]`,
				"deps":           `["//external/rust/crates/bar:libbar"]`,
			}, android.HostSupported),
		},
	},
	)
}
+46 −0
Original line number Diff line number Diff line
package bp2build

import (
	"android/soong/android"
	"android/soong/rust"
	"testing"
)

func runRustProtobufTestCase(t *testing.T, tc Bp2buildTestCase) {
	t.Helper()
	RunBp2BuildTestCase(t, registerRustProtobufModuleTypes, tc)
}

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

}

func TestRustProtobufHostTestCase(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_host {
	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),
		},
	},
	)
}
Loading