Merge "rust ffi libraries can be included in APEX"

This commit is contained in:
Jiyong Park
2020-12-10 23:54:34 +00:00
committed by Gerrit Code Review
2 changed files with 36 additions and 7 deletions

View File

@@ -530,11 +530,8 @@ func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, nativeM
if ctx.Device() { if ctx.Device() {
binVariations = append(binVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation}) binVariations = append(binVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
libVariations = append(libVariations, libVariations = append(libVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
blueprint.Variation{Mutator: "image", Variation: imageVariation}, rustLibVariations = append(rustLibVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation})
blueprint.Variation{Mutator: "version", Variation: ""}) // "" is the non-stub variant
rustLibVariations = append(rustLibVariations,
blueprint.Variation{Mutator: "image", Variation: imageVariation})
} }
// Use *FarVariation* to be able to depend on modules having conflicting variations with // Use *FarVariation* to be able to depend on modules having conflicting variations with
@@ -1530,6 +1527,9 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
provideNativeLibs = append(provideNativeLibs, fi.stem()) provideNativeLibs = append(provideNativeLibs, fi.stem())
} }
return true // track transitive dependencies return true // track transitive dependencies
} else if r, ok := child.(*rust.Module); ok {
fi := apexFileForRustLibrary(ctx, r)
filesInfo = append(filesInfo, fi)
} else { } else {
propertyName := "native_shared_libs" propertyName := "native_shared_libs"
if isJniLib { if isJniLib {
@@ -1702,6 +1702,11 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
return false return false
} }
filesInfo = append(filesInfo, af)
return true // track transitive dependencies
} else if rm, ok := child.(*rust.Module); ok {
af := apexFileForRustLibrary(ctx, rm)
af.transitiveDep = true
filesInfo = append(filesInfo, af) filesInfo = append(filesInfo, af)
return true // track transitive dependencies return true // track transitive dependencies
} }

View File

@@ -362,7 +362,10 @@ func TestBasicApex(t *testing.T) {
androidManifest: ":myapex.androidmanifest", androidManifest: ":myapex.androidmanifest",
key: "myapex.key", key: "myapex.key",
binaries: ["foo.rust"], binaries: ["foo.rust"],
native_shared_libs: ["mylib"], native_shared_libs: [
"mylib",
"libfoo.ffi",
],
rust_dyn_libs: ["libfoo.dylib.rust"], rust_dyn_libs: ["libfoo.dylib.rust"],
multilib: { multilib: {
both: { both: {
@@ -399,7 +402,10 @@ func TestBasicApex(t *testing.T) {
cc_library { cc_library {
name: "mylib", name: "mylib",
srcs: ["mylib.cpp"], srcs: ["mylib.cpp"],
shared_libs: ["mylib2"], shared_libs: [
"mylib2",
"libbar.ffi",
],
system_shared_libs: [], system_shared_libs: [],
stl: "none", stl: "none",
// TODO: remove //apex_available:platform // TODO: remove //apex_available:platform
@@ -451,6 +457,20 @@ func TestBasicApex(t *testing.T) {
apex_available: ["myapex"], apex_available: ["myapex"],
} }
rust_ffi_shared {
name: "libfoo.ffi",
srcs: ["foo.rs"],
crate_name: "foo",
apex_available: ["myapex"],
}
rust_ffi_shared {
name: "libbar.ffi",
srcs: ["foo.rs"],
crate_name: "bar",
apex_available: ["myapex"],
}
apex { apex {
name: "com.android.gki.fake", name: "com.android.gki.fake",
binaries: ["foo"], binaries: ["foo"],
@@ -566,12 +586,14 @@ func TestBasicApex(t *testing.T) {
ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_apex10000") ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_apex10000")
ensureListContains(t, ctx.ModuleVariantsForTests("myjar_dex"), "android_common_apex10000") ensureListContains(t, ctx.ModuleVariantsForTests("myjar_dex"), "android_common_apex10000")
ensureListContains(t, ctx.ModuleVariantsForTests("foo.rust"), "android_arm64_armv8-a_apex10000") ensureListContains(t, ctx.ModuleVariantsForTests("foo.rust"), "android_arm64_armv8-a_apex10000")
ensureListContains(t, ctx.ModuleVariantsForTests("libfoo.ffi"), "android_arm64_armv8-a_shared_apex10000")
// Ensure that apex variant is created for the indirect dep // Ensure that apex variant is created for the indirect dep
ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000")
ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_apex10000") ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_apex10000")
ensureListContains(t, ctx.ModuleVariantsForTests("libfoo.rlib.rust"), "android_arm64_armv8-a_rlib_dylib-std_apex10000") ensureListContains(t, ctx.ModuleVariantsForTests("libfoo.rlib.rust"), "android_arm64_armv8-a_rlib_dylib-std_apex10000")
ensureListContains(t, ctx.ModuleVariantsForTests("libfoo.dylib.rust"), "android_arm64_armv8-a_dylib_apex10000") ensureListContains(t, ctx.ModuleVariantsForTests("libfoo.dylib.rust"), "android_arm64_armv8-a_dylib_apex10000")
ensureListContains(t, ctx.ModuleVariantsForTests("libbar.ffi"), "android_arm64_armv8-a_shared_apex10000")
// Ensure that both direct and indirect deps are copied into apex // Ensure that both direct and indirect deps are copied into apex
ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
@@ -579,6 +601,8 @@ func TestBasicApex(t *testing.T) {
ensureContains(t, copyCmds, "image.apex/javalib/myjar_stem.jar") ensureContains(t, copyCmds, "image.apex/javalib/myjar_stem.jar")
ensureContains(t, copyCmds, "image.apex/javalib/myjar_dex.jar") ensureContains(t, copyCmds, "image.apex/javalib/myjar_dex.jar")
ensureContains(t, copyCmds, "image.apex/lib64/libfoo.dylib.rust.dylib.so") ensureContains(t, copyCmds, "image.apex/lib64/libfoo.dylib.rust.dylib.so")
ensureContains(t, copyCmds, "image.apex/lib64/libfoo.ffi.so")
ensureContains(t, copyCmds, "image.apex/lib64/libbar.ffi.so")
// .. but not for java libs // .. but not for java libs
ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar") ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar")
ensureNotContains(t, copyCmds, "image.apex/javalib/msharedjar.jar") ensureNotContains(t, copyCmds, "image.apex/javalib/msharedjar.jar")