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

Commit 89e4882d authored by Ivan Lozano's avatar Ivan Lozano Committed by Gerrit Code Review
Browse files

Merge "[rust] Add SourceProviders as crates support."

parents 9b7b8f16 26ecd6c5
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -55,7 +55,6 @@ func (mod *Module) AndroidMk() android.AndroidMkData {
	ret := android.AndroidMkData{
		OutputFile: mod.outputFile,
		Include:    "$(BUILD_SYSTEM)/soong_rust_prebuilt.mk",
		SubName:    mod.subName,
		Extra: []android.AndroidMkExtraFunc{
			func(w io.Writer, outputFile android.Path) {
				if len(mod.Properties.AndroidMkRlibs) > 0 {
@@ -76,9 +75,11 @@ func (mod *Module) AndroidMk() android.AndroidMkData {
			},
		},
	}
	if mod.compiler != nil {

	if mod.compiler != nil && !mod.compiler.Disabled() {
		mod.subAndroidMk(&ret, mod.compiler)
	} else if mod.sourceProvider != nil {
		// If the compiler is disabled, this is a SourceProvider.
		mod.subAndroidMk(&ret, mod.sourceProvider)
	}
	ret.SubName += mod.Properties.SubName
@@ -162,6 +163,7 @@ func (sourceProvider *baseSourceProvider) AndroidMk(ctx AndroidMkContext, ret *a
	outFile := sourceProvider.outputFile
	ret.Class = "ETC"
	ret.OutputFile = android.OptionalPathForPath(outFile)
	ret.SubName += sourceProvider.subName
	ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
		_, file := filepath.Split(outFile.String())
		stem, suffix, _ := android.SplitFileExt(file)
+8 −2
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ type BindgenProperties struct {
	Wrapper_src *string `android:"path,arch_variant"`

	// list of bindgen-specific flags and options
	Flags []string `android:"arch_variant"`
	Bindgen_flags []string `android:"arch_variant"`

	// list of clang flags required to correctly interpret the headers.
	Cflags []string `android:"arch_variant"`
@@ -121,7 +121,7 @@ func (b *bindgenDecorator) generateSource(ctx android.ModuleContext, deps PathDe
	}

	bindgenFlags := defaultBindgenFlags
	bindgenFlags = append(bindgenFlags, strings.Join(b.Properties.Flags, " "))
	bindgenFlags = append(bindgenFlags, strings.Join(b.Properties.Bindgen_flags, " "))

	wrapperFile := android.OptionalPathForModuleSrc(ctx, b.Properties.Wrapper_src)
	if !wrapperFile.Valid() {
@@ -170,7 +170,13 @@ func NewRustBindgen(hod android.HostOrDeviceSupported) (*Module, *bindgenDecorat
		baseSourceProvider: NewSourceProvider(),
		Properties:         BindgenProperties{},
	}

	_, library := NewRustLibrary(hod)
	library.BuildOnlyRust()
	library.sourceProvider = bindgen

	module.sourceProvider = bindgen
	module.compiler = library

	return module, bindgen
}
+4 −3
Original line number Diff line number Diff line
@@ -24,8 +24,10 @@ func TestRustBindgen(t *testing.T) {
		rust_bindgen {
			name: "libbindgen",
			wrapper_src: "src/any.h",
			stem: "bindings",
			flags: ["--bindgen-flag"],
			crate_name: "bindgen",
			stem: "libbindgen",
			source_stem: "bindings",
			bindgen_flags: ["--bindgen-flag"],
			cflags: ["--clang-flag"],
			shared_libs: ["libfoo_shared"],
			static_libs: ["libfoo_static"],
@@ -38,7 +40,6 @@ func TestRustBindgen(t *testing.T) {
			name: "libfoo_static",
			export_include_dirs: ["static_include"],
		}

	`)
	libbindgen := ctx.ModuleForTests("libbindgen", "android_arm64_armv8-a").Output("bindings.rs")
	if !strings.Contains(libbindgen.Args["flags"], "--bindgen-flag") {
+4 −2
Original line number Diff line number Diff line
@@ -28,12 +28,14 @@ func TestSourceProviderCollision(t *testing.T) {
		}
		rust_bindgen {
			name: "libbindings1",
			stem: "bindings",
			source_stem: "bindings",
			crate_name: "bindings1",
			wrapper_src: "src/any.h",
		}
		rust_bindgen {
			name: "libbindings2",
			stem: "bindings",
			source_stem: "bindings",
			crate_name: "bindings2",
			wrapper_src: "src/any.h",
		}
	`)
+12 −1
Original line number Diff line number Diff line
@@ -81,7 +81,10 @@ type BaseCompilerProperties struct {
	// list of C static library dependencies
	Static_libs []string `android:"arch_variant"`

	// crate name, required for libraries. This must be the expected extern crate name used in source
	// crate name, required for modules which produce Rust libraries: rust_library, rust_ffi and SourceProvider
	// modules which create library variants (rust_bindgen). This must be the expected extern crate name used in
	// source, and is required to conform to an enforced format matching library output files (if the output file is
	// lib<someName><suffix>, the crate_name property must be <someName>).
	Crate_name string `android:"arch_variant"`

	// list of features to enable for this crate
@@ -120,6 +123,14 @@ type baseCompiler struct {
	distFile              android.OptionalPath
}

func (compiler *baseCompiler) Disabled() bool {
	return false
}

func (compiler *baseCompiler) SetDisabled() {
	panic("baseCompiler does not implement SetDisabled()")
}

func (compiler *baseCompiler) coverageOutputZipPath() android.OptionalPath {
	panic("baseCompiler does not implement coverageOutputZipPath()")
}
Loading