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

Commit 83a12d1f authored by Matthew Maurer's avatar Matthew Maurer Committed by Gerrit Code Review
Browse files

Merge "[rust] Add android_dylib cfg flag"

parents 2d805692 0dbfc565
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -431,6 +431,12 @@ func (library *libraryDecorator) sharedLibFilename(ctx ModuleContext) string {

func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags) Flags {
	flags.RustFlags = append(flags.RustFlags, "-C metadata="+ctx.ModuleName())
	if library.dylib() {
		// We need to add a dependency on std in order to link crates as dylibs.
		// The hack to add this dependency is guarded by the following cfg so
		// that we don't force a dependency when it isn't needed.
		library.baseCompiler.Properties.Cfgs = append(library.baseCompiler.Properties.Cfgs, "android_dylib")
	}
	flags = library.baseCompiler.compilerFlags(ctx, flags)
	if library.shared() || library.static() {
		library.includeDirs = append(library.includeDirs, android.PathsForModuleSrc(ctx, library.Properties.Include_dirs)...)
+16 −0
Original line number Diff line number Diff line
@@ -85,6 +85,22 @@ func TestDylibPreferDynamic(t *testing.T) {
	}
}

// Check that we are passing the android_dylib config flag
func TestAndroidDylib(t *testing.T) {
	ctx := testRust(t, `
		rust_library_host_dylib {
			name: "libfoo",
			srcs: ["foo.rs"],
			crate_name: "foo",
		}`)

	libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Output("libfoo.dylib.so")

	if !strings.Contains(libfooDylib.Args["rustcFlags"], "--cfg 'android_dylib'") {
		t.Errorf("missing android_dylib cfg flag for libfoo dylib, rustcFlags: %#v", libfooDylib.Args["rustcFlags"])
	}
}

func TestValidateLibraryStem(t *testing.T) {
	testRustError(t, "crate_name must be defined.", `
			rust_library_host {