Merge "cc/rust: Alias ffi rlib variant for static_libs" into main
This commit is contained in:
@@ -798,9 +798,12 @@ func transformObjToStaticLib(ctx android.ModuleContext,
|
|||||||
// Generate a Rust staticlib from a list of rlibDeps. Returns nil if TransformRlibstoStaticlib is nil or rlibDeps is empty.
|
// Generate a Rust staticlib from a list of rlibDeps. Returns nil if TransformRlibstoStaticlib is nil or rlibDeps is empty.
|
||||||
func generateRustStaticlib(ctx android.ModuleContext, rlibDeps []RustRlibDep) android.Path {
|
func generateRustStaticlib(ctx android.ModuleContext, rlibDeps []RustRlibDep) android.Path {
|
||||||
if TransformRlibstoStaticlib == nil && len(rlibDeps) > 0 {
|
if TransformRlibstoStaticlib == nil && len(rlibDeps) > 0 {
|
||||||
// This should only be reachable if a module defines static_rlibs and
|
// This should only be reachable if a module defines Rust deps in static_libs and
|
||||||
// soong-rust hasn't been loaded alongside soong-cc (e.g. in soong-cc tests).
|
// soong-rust hasn't been loaded alongside soong-cc (e.g. in soong-cc tests).
|
||||||
panic(fmt.Errorf("TransformRlibstoStaticlib is not set and static_rlibs is defined in %s", ctx.ModuleName()))
|
panic(fmt.Errorf(
|
||||||
|
"TransformRlibstoStaticlib is not set and rust deps are defined in static_libs for %s",
|
||||||
|
ctx.ModuleName()))
|
||||||
|
|
||||||
} else if len(rlibDeps) == 0 {
|
} else if len(rlibDeps) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -829,6 +832,7 @@ func generateRustStaticlib(ctx android.ModuleContext, rlibDeps []RustRlibDep) an
|
|||||||
func genRustStaticlibSrcFile(crateNames []string) string {
|
func genRustStaticlibSrcFile(crateNames []string) string {
|
||||||
lines := []string{
|
lines := []string{
|
||||||
"// @Soong generated Source",
|
"// @Soong generated Source",
|
||||||
|
"#![no_std]", // pre-emptively set no_std to support both std and no_std.
|
||||||
}
|
}
|
||||||
for _, crate := range crateNames {
|
for _, crate := range crateNames {
|
||||||
lines = append(lines, fmt.Sprintf("extern crate %s;", crate))
|
lines = append(lines, fmt.Sprintf("extern crate %s;", crate))
|
||||||
|
177
cc/cc.go
177
cc/cc.go
@@ -99,7 +99,6 @@ type Deps struct {
|
|||||||
StaticLibs, LateStaticLibs, WholeStaticLibs []string
|
StaticLibs, LateStaticLibs, WholeStaticLibs []string
|
||||||
HeaderLibs []string
|
HeaderLibs []string
|
||||||
RuntimeLibs []string
|
RuntimeLibs []string
|
||||||
Rlibs []string
|
|
||||||
|
|
||||||
// UnexportedStaticLibs are static libraries that are also passed to -Wl,--exclude-libs= to
|
// UnexportedStaticLibs are static libraries that are also passed to -Wl,--exclude-libs= to
|
||||||
// prevent automatically exporting symbols.
|
// prevent automatically exporting symbols.
|
||||||
@@ -746,11 +745,6 @@ func (d libraryDependencyTag) static() bool {
|
|||||||
return d.Kind == staticLibraryDependency
|
return d.Kind == staticLibraryDependency
|
||||||
}
|
}
|
||||||
|
|
||||||
// rlib returns true if the libraryDependencyTag is tagging an rlib dependency.
|
|
||||||
func (d libraryDependencyTag) rlib() bool {
|
|
||||||
return d.Kind == rlibLibraryDependency
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d libraryDependencyTag) LicenseAnnotations() []android.LicenseAnnotation {
|
func (d libraryDependencyTag) LicenseAnnotations() []android.LicenseAnnotation {
|
||||||
if d.shared() {
|
if d.shared() {
|
||||||
return []android.LicenseAnnotation{android.LicenseAnnotationSharedDependency}
|
return []android.LicenseAnnotation{android.LicenseAnnotationSharedDependency}
|
||||||
@@ -917,6 +911,8 @@ type Module struct {
|
|||||||
hideApexVariantFromMake bool
|
hideApexVariantFromMake bool
|
||||||
|
|
||||||
logtagsPaths android.Paths
|
logtagsPaths android.Paths
|
||||||
|
|
||||||
|
WholeRustStaticlib bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Module) AddJSONData(d *map[string]interface{}) {
|
func (c *Module) AddJSONData(d *map[string]interface{}) {
|
||||||
@@ -1192,6 +1188,16 @@ func (c *Module) BuildSharedVariant() bool {
|
|||||||
panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
|
panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Module) BuildRlibVariant() bool {
|
||||||
|
// cc modules can never build rlib variants
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Module) IsRustFFI() bool {
|
||||||
|
// cc modules are not Rust modules
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Module) Module() android.Module {
|
func (c *Module) Module() android.Module {
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
@@ -2280,7 +2286,6 @@ func (c *Module) deps(ctx DepsContext) Deps {
|
|||||||
|
|
||||||
deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
|
deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
|
||||||
deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
|
deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
|
||||||
deps.Rlibs = android.LastUniqueStrings(deps.Rlibs)
|
|
||||||
deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
|
deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
|
||||||
deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
|
deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
|
||||||
deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
|
deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
|
||||||
@@ -2575,28 +2580,20 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, lib := range deps.StaticLibs {
|
for _, lib := range deps.StaticLibs {
|
||||||
|
// Some dependencies listed in static_libs might actually be rust_ffi rlib variants.
|
||||||
depTag := libraryDependencyTag{Kind: staticLibraryDependency}
|
depTag := libraryDependencyTag{Kind: staticLibraryDependency}
|
||||||
|
|
||||||
if inList(lib, deps.ReexportStaticLibHeaders) {
|
if inList(lib, deps.ReexportStaticLibHeaders) {
|
||||||
depTag.reexportFlags = true
|
depTag.reexportFlags = true
|
||||||
}
|
}
|
||||||
if inList(lib, deps.ExcludeLibsForApex) {
|
if inList(lib, deps.ExcludeLibsForApex) {
|
||||||
depTag.excludeInApex = true
|
depTag.excludeInApex = true
|
||||||
}
|
}
|
||||||
|
|
||||||
actx.AddVariationDependencies([]blueprint.Variation{
|
actx.AddVariationDependencies([]blueprint.Variation{
|
||||||
{Mutator: "link", Variation: "static"},
|
{Mutator: "link", Variation: "static"},
|
||||||
}, depTag, lib)
|
}, depTag, lib)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, lib := range deps.Rlibs {
|
|
||||||
depTag := libraryDependencyTag{Kind: rlibLibraryDependency}
|
|
||||||
actx.AddVariationDependencies([]blueprint.Variation{
|
|
||||||
{Mutator: "link", Variation: ""},
|
|
||||||
{Mutator: "rust_libraries", Variation: "rlib"},
|
|
||||||
{Mutator: "rust_stdlinkage", Variation: "rlib-std"},
|
|
||||||
}, depTag, lib)
|
|
||||||
}
|
|
||||||
|
|
||||||
// staticUnwinderDep is treated as staticDep for Q apexes
|
// staticUnwinderDep is treated as staticDep for Q apexes
|
||||||
// so that native libraries/binaries are linked with static unwinder
|
// so that native libraries/binaries are linked with static unwinder
|
||||||
// because Q libc doesn't have unwinder APIs
|
// because Q libc doesn't have unwinder APIs
|
||||||
@@ -3184,78 +3181,86 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
|||||||
panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
|
panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
|
||||||
}
|
}
|
||||||
|
|
||||||
case libDepTag.rlib():
|
|
||||||
rlibDep := RustRlibDep{LibPath: linkFile.Path(), CrateName: ccDep.CrateName(), LinkDirs: ccDep.ExportedCrateLinkDirs()}
|
|
||||||
depPaths.ReexportedRustRlibDeps = append(depPaths.ReexportedRustRlibDeps, rlibDep)
|
|
||||||
depPaths.RustRlibDeps = append(depPaths.RustRlibDeps, rlibDep)
|
|
||||||
depPaths.IncludeDirs = append(depPaths.IncludeDirs, depExporterInfo.IncludeDirs...)
|
|
||||||
depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, depExporterInfo.IncludeDirs...)
|
|
||||||
|
|
||||||
case libDepTag.static():
|
case libDepTag.static():
|
||||||
staticLibraryInfo, isStaticLib := android.OtherModuleProvider(ctx, dep, StaticLibraryInfoProvider)
|
if ccDep.RustLibraryInterface() {
|
||||||
if !isStaticLib {
|
rlibDep := RustRlibDep{LibPath: linkFile.Path(), CrateName: ccDep.CrateName(), LinkDirs: ccDep.ExportedCrateLinkDirs()}
|
||||||
if !ctx.Config().AllowMissingDependencies() {
|
depPaths.RustRlibDeps = append(depPaths.RustRlibDeps, rlibDep)
|
||||||
ctx.ModuleErrorf("module %q is not a static library", depName)
|
depPaths.IncludeDirs = append(depPaths.IncludeDirs, depExporterInfo.IncludeDirs...)
|
||||||
} else {
|
if libDepTag.wholeStatic {
|
||||||
ctx.AddMissingDependencies([]string{depName})
|
depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, depExporterInfo.IncludeDirs...)
|
||||||
}
|
depPaths.ReexportedRustRlibDeps = append(depPaths.ReexportedRustRlibDeps, rlibDep)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stubs lib doesn't link to the static lib dependencies. Don't set
|
// If whole_static, track this as we want to make sure that in a final linkage for a shared library,
|
||||||
// linkFile, depFile, and ptr.
|
// exported functions from the rust generated staticlib still exported.
|
||||||
if c.IsStubs() {
|
if c.CcLibrary() && c.Shared() {
|
||||||
break
|
c.WholeRustStaticlib = true
|
||||||
}
|
}
|
||||||
|
|
||||||
linkFile = android.OptionalPathForPath(staticLibraryInfo.StaticLibrary)
|
|
||||||
if libDepTag.wholeStatic {
|
|
||||||
ptr = &depPaths.WholeStaticLibs
|
|
||||||
if len(staticLibraryInfo.Objects.objFiles) > 0 {
|
|
||||||
depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLibraryInfo.Objects)
|
|
||||||
} else {
|
|
||||||
// This case normally catches prebuilt static
|
|
||||||
// libraries, but it can also occur when
|
|
||||||
// AllowMissingDependencies is on and the
|
|
||||||
// dependencies has no sources of its own
|
|
||||||
// but has a whole_static_libs dependency
|
|
||||||
// on a missing library. We want to depend
|
|
||||||
// on the .a file so that there is something
|
|
||||||
// in the dependency tree that contains the
|
|
||||||
// error rule for the missing transitive
|
|
||||||
// dependency.
|
|
||||||
depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
|
|
||||||
}
|
}
|
||||||
depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts,
|
|
||||||
staticLibraryInfo.WholeStaticLibsFromPrebuilts...)
|
|
||||||
} else {
|
} else {
|
||||||
switch libDepTag.Order {
|
staticLibraryInfo, isStaticLib := android.OtherModuleProvider(ctx, dep, StaticLibraryInfoProvider)
|
||||||
case earlyLibraryDependency:
|
if !isStaticLib {
|
||||||
panic(fmt.Errorf("early static libs not suppported"))
|
if !ctx.Config().AllowMissingDependencies() {
|
||||||
case normalLibraryDependency:
|
ctx.ModuleErrorf("module %q is not a static library", depName)
|
||||||
// static dependencies will be handled separately so they can be ordered
|
} else {
|
||||||
// using transitive dependencies.
|
ctx.AddMissingDependencies([]string{depName})
|
||||||
ptr = nil
|
}
|
||||||
directStaticDeps = append(directStaticDeps, staticLibraryInfo)
|
return
|
||||||
case lateLibraryDependency:
|
|
||||||
ptr = &depPaths.LateStaticLibs
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// We re-export the Rust static_rlibs so rlib dependencies don't need to be redeclared by cc_library_static dependents.
|
// Stubs lib doesn't link to the static lib dependencies. Don't set
|
||||||
// E.g. libfoo (cc_library_static) depends on libfoo.ffi (a rust_ffi rlib), libbar depending on libfoo shouldn't have to also add libfoo.ffi to static_rlibs.
|
// linkFile, depFile, and ptr.
|
||||||
depPaths.ReexportedRustRlibDeps = append(depPaths.ReexportedRustRlibDeps, depExporterInfo.RustRlibDeps...)
|
if c.IsStubs() {
|
||||||
depPaths.RustRlibDeps = append(depPaths.RustRlibDeps, depExporterInfo.RustRlibDeps...)
|
break
|
||||||
|
}
|
||||||
|
|
||||||
if libDepTag.unexportedSymbols {
|
linkFile = android.OptionalPathForPath(staticLibraryInfo.StaticLibrary)
|
||||||
depPaths.LdFlags = append(depPaths.LdFlags,
|
if libDepTag.wholeStatic {
|
||||||
"-Wl,--exclude-libs="+staticLibraryInfo.StaticLibrary.Base())
|
ptr = &depPaths.WholeStaticLibs
|
||||||
|
if len(staticLibraryInfo.Objects.objFiles) > 0 {
|
||||||
|
depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLibraryInfo.Objects)
|
||||||
|
} else {
|
||||||
|
// This case normally catches prebuilt static
|
||||||
|
// libraries, but it can also occur when
|
||||||
|
// AllowMissingDependencies is on and the
|
||||||
|
// dependencies has no sources of its own
|
||||||
|
// but has a whole_static_libs dependency
|
||||||
|
// on a missing library. We want to depend
|
||||||
|
// on the .a file so that there is something
|
||||||
|
// in the dependency tree that contains the
|
||||||
|
// error rule for the missing transitive
|
||||||
|
// dependency.
|
||||||
|
depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
|
||||||
|
}
|
||||||
|
depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts,
|
||||||
|
staticLibraryInfo.WholeStaticLibsFromPrebuilts...)
|
||||||
|
} else {
|
||||||
|
switch libDepTag.Order {
|
||||||
|
case earlyLibraryDependency:
|
||||||
|
panic(fmt.Errorf("early static libs not supported"))
|
||||||
|
case normalLibraryDependency:
|
||||||
|
// static dependencies will be handled separately so they can be ordered
|
||||||
|
// using transitive dependencies.
|
||||||
|
ptr = nil
|
||||||
|
directStaticDeps = append(directStaticDeps, staticLibraryInfo)
|
||||||
|
case lateLibraryDependency:
|
||||||
|
ptr = &depPaths.LateStaticLibs
|
||||||
|
default:
|
||||||
|
panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect any exported Rust rlib deps from static libraries which have been included as whole_static_libs
|
||||||
|
depPaths.RustRlibDeps = append(depPaths.RustRlibDeps, depExporterInfo.RustRlibDeps...)
|
||||||
|
|
||||||
|
if libDepTag.unexportedSymbols {
|
||||||
|
depPaths.LdFlags = append(depPaths.LdFlags,
|
||||||
|
"-Wl,--exclude-libs="+staticLibraryInfo.StaticLibrary.Base())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if libDepTag.static() && !libDepTag.wholeStatic {
|
if libDepTag.static() && !libDepTag.wholeStatic && !ccDep.RustLibraryInterface() {
|
||||||
if !ccDep.CcLibraryInterface() || !ccDep.Static() {
|
if !ccDep.CcLibraryInterface() || !ccDep.Static() {
|
||||||
ctx.ModuleErrorf("module %q not a static library", depName)
|
ctx.ModuleErrorf("module %q not a static library", depName)
|
||||||
return
|
return
|
||||||
@@ -3342,12 +3347,14 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
|||||||
c.Properties.AndroidMkSharedLibs = append(
|
c.Properties.AndroidMkSharedLibs = append(
|
||||||
c.Properties.AndroidMkSharedLibs, makeLibName)
|
c.Properties.AndroidMkSharedLibs, makeLibName)
|
||||||
case libDepTag.static():
|
case libDepTag.static():
|
||||||
if libDepTag.wholeStatic {
|
if !ccDep.RustLibraryInterface() {
|
||||||
c.Properties.AndroidMkWholeStaticLibs = append(
|
if libDepTag.wholeStatic {
|
||||||
c.Properties.AndroidMkWholeStaticLibs, makeLibName)
|
c.Properties.AndroidMkWholeStaticLibs = append(
|
||||||
} else {
|
c.Properties.AndroidMkWholeStaticLibs, makeLibName)
|
||||||
c.Properties.AndroidMkStaticLibs = append(
|
} else {
|
||||||
c.Properties.AndroidMkStaticLibs, makeLibName)
|
c.Properties.AndroidMkStaticLibs = append(
|
||||||
|
c.Properties.AndroidMkStaticLibs, makeLibName)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if !c.IsStubs() {
|
} else if !c.IsStubs() {
|
||||||
|
@@ -794,9 +794,6 @@ type RustBindgenClangProperties struct {
|
|||||||
// be added to the include path using -I
|
// be added to the include path using -I
|
||||||
Local_include_dirs []string `android:"arch_variant,variant_prepend"`
|
Local_include_dirs []string `android:"arch_variant,variant_prepend"`
|
||||||
|
|
||||||
// list of Rust static libraries.
|
|
||||||
Static_rlibs []string `android:"arch_variant,variant_prepend"`
|
|
||||||
|
|
||||||
// list of static libraries that provide headers for this binding.
|
// list of static libraries that provide headers for this binding.
|
||||||
Static_libs []string `android:"arch_variant,variant_prepend"`
|
Static_libs []string `android:"arch_variant,variant_prepend"`
|
||||||
|
|
||||||
|
@@ -1135,8 +1135,12 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext,
|
|||||||
linkerDeps = append(linkerDeps, deps.SharedLibsDeps...)
|
linkerDeps = append(linkerDeps, deps.SharedLibsDeps...)
|
||||||
linkerDeps = append(linkerDeps, deps.LateSharedLibsDeps...)
|
linkerDeps = append(linkerDeps, deps.LateSharedLibsDeps...)
|
||||||
|
|
||||||
if generatedLib := generateRustStaticlib(ctx, deps.RustRlibDeps); generatedLib != nil {
|
if generatedLib := generateRustStaticlib(ctx, deps.RustRlibDeps); generatedLib != nil && !library.buildStubs() {
|
||||||
deps.StaticLibs = append(deps.StaticLibs, generatedLib)
|
if ctx.Module().(*Module).WholeRustStaticlib {
|
||||||
|
deps.WholeStaticLibs = append(deps.WholeStaticLibs, generatedLib)
|
||||||
|
} else {
|
||||||
|
deps.StaticLibs = append(deps.StaticLibs, generatedLib)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
transformObjToDynamicBinary(ctx, objs.objFiles, sharedLibs,
|
transformObjToDynamicBinary(ctx, objs.objFiles, sharedLibs,
|
||||||
@@ -2149,7 +2153,6 @@ func LinkageMutator(mctx android.BottomUpMutatorContext) {
|
|||||||
modules := mctx.CreateLocalVariations(variations...)
|
modules := mctx.CreateLocalVariations(variations...)
|
||||||
static := modules[0].(LinkableInterface)
|
static := modules[0].(LinkableInterface)
|
||||||
shared := modules[1].(LinkableInterface)
|
shared := modules[1].(LinkableInterface)
|
||||||
|
|
||||||
static.SetStatic()
|
static.SetStatic()
|
||||||
shared.SetShared()
|
shared.SetShared()
|
||||||
|
|
||||||
@@ -2173,6 +2176,12 @@ func LinkageMutator(mctx android.BottomUpMutatorContext) {
|
|||||||
mctx.CreateLocalVariations(variations...)
|
mctx.CreateLocalVariations(variations...)
|
||||||
mctx.AliasVariation(variations[0])
|
mctx.AliasVariation(variations[0])
|
||||||
}
|
}
|
||||||
|
if library.BuildRlibVariant() && library.IsRustFFI() && !buildStatic {
|
||||||
|
// Rust modules do not build static libs, but rlibs are used as if they
|
||||||
|
// were via `static_libs`. Thus we need to alias the BuildRlibVariant
|
||||||
|
// to "static" for Rust FFI libraries.
|
||||||
|
mctx.CreateAliasVariation("static", "")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -94,12 +94,16 @@ type LinkableInterface interface {
|
|||||||
SelectedStl() string
|
SelectedStl() string
|
||||||
|
|
||||||
BuildStaticVariant() bool
|
BuildStaticVariant() bool
|
||||||
|
BuildRlibVariant() bool
|
||||||
BuildSharedVariant() bool
|
BuildSharedVariant() bool
|
||||||
SetStatic()
|
SetStatic()
|
||||||
SetShared()
|
SetShared()
|
||||||
IsPrebuilt() bool
|
IsPrebuilt() bool
|
||||||
Toc() android.OptionalPath
|
Toc() android.OptionalPath
|
||||||
|
|
||||||
|
// IsRustFFI returns true if this is a Rust FFI library.
|
||||||
|
IsRustFFI() bool
|
||||||
|
|
||||||
// IsFuzzModule returns true if this a *_fuzz module.
|
// IsFuzzModule returns true if this a *_fuzz module.
|
||||||
IsFuzzModule() bool
|
IsFuzzModule() bool
|
||||||
|
|
||||||
|
29
cc/linker.go
29
cc/linker.go
@@ -39,9 +39,6 @@ type BaseLinkerProperties struct {
|
|||||||
// the dependency's .a file will be linked into this module using -Wl,--whole-archive.
|
// the dependency's .a file will be linked into this module using -Wl,--whole-archive.
|
||||||
Whole_static_libs []string `android:"arch_variant,variant_prepend"`
|
Whole_static_libs []string `android:"arch_variant,variant_prepend"`
|
||||||
|
|
||||||
// list of Rust libs that should be statically linked into this module.
|
|
||||||
Static_rlibs []string `android:"arch_variant"`
|
|
||||||
|
|
||||||
// list of modules that should be statically linked into this module.
|
// list of modules that should be statically linked into this module.
|
||||||
Static_libs []string `android:"arch_variant,variant_prepend"`
|
Static_libs []string `android:"arch_variant,variant_prepend"`
|
||||||
|
|
||||||
@@ -127,10 +124,6 @@ type BaseLinkerProperties struct {
|
|||||||
// variant of the C/C++ module.
|
// variant of the C/C++ module.
|
||||||
Header_libs []string
|
Header_libs []string
|
||||||
|
|
||||||
// list of Rust libs that should be statically linked to build vendor or product
|
|
||||||
// variant.
|
|
||||||
Static_rlibs []string
|
|
||||||
|
|
||||||
// list of shared libs that should not be used to build vendor or
|
// list of shared libs that should not be used to build vendor or
|
||||||
// product variant of the C/C++ module.
|
// product variant of the C/C++ module.
|
||||||
Exclude_shared_libs []string
|
Exclude_shared_libs []string
|
||||||
@@ -159,10 +152,6 @@ type BaseLinkerProperties struct {
|
|||||||
// variant of the C/C++ module.
|
// variant of the C/C++ module.
|
||||||
Static_libs []string
|
Static_libs []string
|
||||||
|
|
||||||
// list of Rust libs that should be statically linked to build the recovery
|
|
||||||
// variant.
|
|
||||||
Static_rlibs []string
|
|
||||||
|
|
||||||
// list of shared libs that should not be used to build
|
// list of shared libs that should not be used to build
|
||||||
// the recovery variant of the C/C++ module.
|
// the recovery variant of the C/C++ module.
|
||||||
Exclude_shared_libs []string
|
Exclude_shared_libs []string
|
||||||
@@ -184,10 +173,6 @@ type BaseLinkerProperties struct {
|
|||||||
// variant of the C/C++ module.
|
// variant of the C/C++ module.
|
||||||
Static_libs []string
|
Static_libs []string
|
||||||
|
|
||||||
// list of Rust libs that should be statically linked to build the ramdisk
|
|
||||||
// variant.
|
|
||||||
Static_rlibs []string
|
|
||||||
|
|
||||||
// list of shared libs that should not be used to build
|
// list of shared libs that should not be used to build
|
||||||
// the ramdisk variant of the C/C++ module.
|
// the ramdisk variant of the C/C++ module.
|
||||||
Exclude_shared_libs []string
|
Exclude_shared_libs []string
|
||||||
@@ -205,10 +190,6 @@ type BaseLinkerProperties struct {
|
|||||||
// the vendor ramdisk variant of the C/C++ module.
|
// the vendor ramdisk variant of the C/C++ module.
|
||||||
Exclude_shared_libs []string
|
Exclude_shared_libs []string
|
||||||
|
|
||||||
// list of Rust libs that should be statically linked to build the vendor ramdisk
|
|
||||||
// variant.
|
|
||||||
Static_rlibs []string
|
|
||||||
|
|
||||||
// list of static libs that should not be used to build
|
// list of static libs that should not be used to build
|
||||||
// the vendor ramdisk variant of the C/C++ module.
|
// the vendor ramdisk variant of the C/C++ module.
|
||||||
Exclude_static_libs []string
|
Exclude_static_libs []string
|
||||||
@@ -224,10 +205,6 @@ type BaseLinkerProperties struct {
|
|||||||
// variants.
|
// variants.
|
||||||
Shared_libs []string
|
Shared_libs []string
|
||||||
|
|
||||||
// list of Rust libs that should be statically linked to build the vendor ramdisk
|
|
||||||
// variant.
|
|
||||||
Static_rlibs []string
|
|
||||||
|
|
||||||
// list of ehader libs that only should be used to build platform variant of
|
// list of ehader libs that only should be used to build platform variant of
|
||||||
// the C/C++ module.
|
// the C/C++ module.
|
||||||
Header_libs []string
|
Header_libs []string
|
||||||
@@ -322,7 +299,6 @@ func (linker *baseLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
|||||||
deps.WholeStaticLibs = append(deps.WholeStaticLibs, linker.Properties.Whole_static_libs...)
|
deps.WholeStaticLibs = append(deps.WholeStaticLibs, linker.Properties.Whole_static_libs...)
|
||||||
deps.HeaderLibs = append(deps.HeaderLibs, linker.Properties.Header_libs...)
|
deps.HeaderLibs = append(deps.HeaderLibs, linker.Properties.Header_libs...)
|
||||||
deps.StaticLibs = append(deps.StaticLibs, linker.Properties.Static_libs...)
|
deps.StaticLibs = append(deps.StaticLibs, linker.Properties.Static_libs...)
|
||||||
deps.Rlibs = append(deps.Rlibs, linker.Properties.Static_rlibs...)
|
|
||||||
deps.SharedLibs = append(deps.SharedLibs, linker.Properties.Shared_libs...)
|
deps.SharedLibs = append(deps.SharedLibs, linker.Properties.Shared_libs...)
|
||||||
deps.RuntimeLibs = append(deps.RuntimeLibs, linker.Properties.Runtime_libs...)
|
deps.RuntimeLibs = append(deps.RuntimeLibs, linker.Properties.Runtime_libs...)
|
||||||
|
|
||||||
@@ -366,7 +342,6 @@ func (linker *baseLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
|||||||
deps.ReexportStaticLibHeaders = removeListFromList(deps.ReexportStaticLibHeaders, linker.Properties.Target.Vendor.Exclude_static_libs)
|
deps.ReexportStaticLibHeaders = removeListFromList(deps.ReexportStaticLibHeaders, linker.Properties.Target.Vendor.Exclude_static_libs)
|
||||||
deps.WholeStaticLibs = removeListFromList(deps.WholeStaticLibs, linker.Properties.Target.Vendor.Exclude_static_libs)
|
deps.WholeStaticLibs = removeListFromList(deps.WholeStaticLibs, linker.Properties.Target.Vendor.Exclude_static_libs)
|
||||||
deps.RuntimeLibs = removeListFromList(deps.RuntimeLibs, linker.Properties.Target.Vendor.Exclude_runtime_libs)
|
deps.RuntimeLibs = removeListFromList(deps.RuntimeLibs, linker.Properties.Target.Vendor.Exclude_runtime_libs)
|
||||||
deps.Rlibs = append(deps.Rlibs, linker.Properties.Target.Vendor.Static_rlibs...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.inProduct() {
|
if ctx.inProduct() {
|
||||||
@@ -380,7 +355,6 @@ func (linker *baseLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
|||||||
deps.ReexportStaticLibHeaders = removeListFromList(deps.ReexportStaticLibHeaders, linker.Properties.Target.Product.Exclude_static_libs)
|
deps.ReexportStaticLibHeaders = removeListFromList(deps.ReexportStaticLibHeaders, linker.Properties.Target.Product.Exclude_static_libs)
|
||||||
deps.WholeStaticLibs = removeListFromList(deps.WholeStaticLibs, linker.Properties.Target.Product.Exclude_static_libs)
|
deps.WholeStaticLibs = removeListFromList(deps.WholeStaticLibs, linker.Properties.Target.Product.Exclude_static_libs)
|
||||||
deps.RuntimeLibs = removeListFromList(deps.RuntimeLibs, linker.Properties.Target.Product.Exclude_runtime_libs)
|
deps.RuntimeLibs = removeListFromList(deps.RuntimeLibs, linker.Properties.Target.Product.Exclude_runtime_libs)
|
||||||
deps.Rlibs = append(deps.Rlibs, linker.Properties.Target.Product.Static_rlibs...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.inRecovery() {
|
if ctx.inRecovery() {
|
||||||
@@ -394,7 +368,6 @@ func (linker *baseLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
|||||||
deps.ReexportStaticLibHeaders = removeListFromList(deps.ReexportStaticLibHeaders, linker.Properties.Target.Recovery.Exclude_static_libs)
|
deps.ReexportStaticLibHeaders = removeListFromList(deps.ReexportStaticLibHeaders, linker.Properties.Target.Recovery.Exclude_static_libs)
|
||||||
deps.WholeStaticLibs = removeListFromList(deps.WholeStaticLibs, linker.Properties.Target.Recovery.Exclude_static_libs)
|
deps.WholeStaticLibs = removeListFromList(deps.WholeStaticLibs, linker.Properties.Target.Recovery.Exclude_static_libs)
|
||||||
deps.RuntimeLibs = removeListFromList(deps.RuntimeLibs, linker.Properties.Target.Recovery.Exclude_runtime_libs)
|
deps.RuntimeLibs = removeListFromList(deps.RuntimeLibs, linker.Properties.Target.Recovery.Exclude_runtime_libs)
|
||||||
deps.Rlibs = append(deps.Rlibs, linker.Properties.Target.Recovery.Static_rlibs...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.inRamdisk() {
|
if ctx.inRamdisk() {
|
||||||
@@ -405,7 +378,6 @@ func (linker *baseLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
|||||||
deps.ReexportStaticLibHeaders = removeListFromList(deps.ReexportStaticLibHeaders, linker.Properties.Target.Ramdisk.Exclude_static_libs)
|
deps.ReexportStaticLibHeaders = removeListFromList(deps.ReexportStaticLibHeaders, linker.Properties.Target.Ramdisk.Exclude_static_libs)
|
||||||
deps.WholeStaticLibs = removeListFromList(deps.WholeStaticLibs, linker.Properties.Target.Ramdisk.Exclude_static_libs)
|
deps.WholeStaticLibs = removeListFromList(deps.WholeStaticLibs, linker.Properties.Target.Ramdisk.Exclude_static_libs)
|
||||||
deps.RuntimeLibs = removeListFromList(deps.RuntimeLibs, linker.Properties.Target.Ramdisk.Exclude_runtime_libs)
|
deps.RuntimeLibs = removeListFromList(deps.RuntimeLibs, linker.Properties.Target.Ramdisk.Exclude_runtime_libs)
|
||||||
deps.Rlibs = append(deps.Rlibs, linker.Properties.Target.Ramdisk.Static_rlibs...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.inVendorRamdisk() {
|
if ctx.inVendorRamdisk() {
|
||||||
@@ -415,7 +387,6 @@ func (linker *baseLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
|||||||
deps.ReexportStaticLibHeaders = removeListFromList(deps.ReexportStaticLibHeaders, linker.Properties.Target.Vendor_ramdisk.Exclude_static_libs)
|
deps.ReexportStaticLibHeaders = removeListFromList(deps.ReexportStaticLibHeaders, linker.Properties.Target.Vendor_ramdisk.Exclude_static_libs)
|
||||||
deps.WholeStaticLibs = removeListFromList(deps.WholeStaticLibs, linker.Properties.Target.Vendor_ramdisk.Exclude_static_libs)
|
deps.WholeStaticLibs = removeListFromList(deps.WholeStaticLibs, linker.Properties.Target.Vendor_ramdisk.Exclude_static_libs)
|
||||||
deps.RuntimeLibs = removeListFromList(deps.RuntimeLibs, linker.Properties.Target.Vendor_ramdisk.Exclude_runtime_libs)
|
deps.RuntimeLibs = removeListFromList(deps.RuntimeLibs, linker.Properties.Target.Vendor_ramdisk.Exclude_runtime_libs)
|
||||||
deps.Rlibs = append(deps.Rlibs, linker.Properties.Target.Vendor_ramdisk.Static_rlibs...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.useSdk() {
|
if !ctx.useSdk() {
|
||||||
|
@@ -134,6 +134,9 @@ func (binary *binaryDecorator) compile(ctx ModuleContext, flags Flags, deps Path
|
|||||||
ret := buildOutput{outputFile: outputFile}
|
ret := buildOutput{outputFile: outputFile}
|
||||||
crateRootPath := crateRootPath(ctx, binary)
|
crateRootPath := crateRootPath(ctx, binary)
|
||||||
|
|
||||||
|
// Ensure link dirs are not duplicated
|
||||||
|
deps.linkDirs = android.FirstUniqueStrings(deps.linkDirs)
|
||||||
|
|
||||||
flags.RustFlags = append(flags.RustFlags, deps.depFlags...)
|
flags.RustFlags = append(flags.RustFlags, deps.depFlags...)
|
||||||
flags.LinkFlags = append(flags.LinkFlags, deps.depLinkFlags...)
|
flags.LinkFlags = append(flags.LinkFlags, deps.depLinkFlags...)
|
||||||
flags.LinkFlags = append(flags.LinkFlags, deps.linkObjects...)
|
flags.LinkFlags = append(flags.LinkFlags, deps.linkObjects...)
|
||||||
|
@@ -65,6 +65,11 @@ func TestCompilationOutputFiles(t *testing.T) {
|
|||||||
crate_name: "rust_ffi",
|
crate_name: "rust_ffi",
|
||||||
srcs: ["lib.rs"],
|
srcs: ["lib.rs"],
|
||||||
}
|
}
|
||||||
|
rust_ffi_static {
|
||||||
|
name: "librust_ffi_static",
|
||||||
|
crate_name: "rust_ffi",
|
||||||
|
srcs: ["lib.rs"],
|
||||||
|
}
|
||||||
`)
|
`)
|
||||||
testcases := []struct {
|
testcases := []struct {
|
||||||
testName string
|
testName string
|
||||||
@@ -118,14 +123,14 @@ func TestCompilationOutputFiles(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testName: "rust_ffi static",
|
testName: "rust_ffi_static rlib",
|
||||||
moduleName: "librust_ffi",
|
moduleName: "librust_ffi_static",
|
||||||
variant: "android_arm64_armv8-a_static",
|
variant: "android_arm64_armv8-a_rlib_rlib-std",
|
||||||
expectedFiles: []string{
|
expectedFiles: []string{
|
||||||
"out/soong/.intermediates/librust_ffi/android_arm64_armv8-a_static/librust_ffi.a",
|
"out/soong/.intermediates/librust_ffi_static/android_arm64_armv8-a_rlib_rlib-std/librust_ffi_static.rlib",
|
||||||
"out/soong/.intermediates/librust_ffi/android_arm64_armv8-a_static/librust_ffi.a.clippy",
|
"out/soong/.intermediates/librust_ffi_static/android_arm64_armv8-a_rlib_rlib-std/librust_ffi_static.rlib.clippy",
|
||||||
"out/soong/.intermediates/librust_ffi/android_arm64_armv8-a_static/meta_lic",
|
"out/soong/.intermediates/librust_ffi_static/android_arm64_armv8-a_rlib_rlib-std/meta_lic",
|
||||||
"out/soong/.intermediates/librust_ffi/android_arm64_armv8-a_static/rustdoc.timestamp",
|
"out/soong/.intermediates/librust_ffi_static/android_arm64_armv8-a_rlib_rlib-std/rustdoc.timestamp",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -148,6 +153,7 @@ func TestCompilationOutputFiles(t *testing.T) {
|
|||||||
"out/soong/.intermediates/librust_ffi/android_arm64_armv8-a_shared/unstripped/librust_ffi.so",
|
"out/soong/.intermediates/librust_ffi/android_arm64_armv8-a_shared/unstripped/librust_ffi.so",
|
||||||
"out/soong/.intermediates/librust_ffi/android_arm64_armv8-a_shared/unstripped/librust_ffi.so.toc",
|
"out/soong/.intermediates/librust_ffi/android_arm64_armv8-a_shared/unstripped/librust_ffi.so.toc",
|
||||||
"out/soong/.intermediates/librust_ffi/android_arm64_armv8-a_shared/meta_lic",
|
"out/soong/.intermediates/librust_ffi/android_arm64_armv8-a_shared/meta_lic",
|
||||||
|
"out/soong/.intermediates/librust_ffi/android_arm64_armv8-a_shared/rustdoc.timestamp",
|
||||||
"out/soong/target/product/test_device/system/lib64/librust_ffi.so",
|
"out/soong/target/product/test_device/system/lib64/librust_ffi.so",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@@ -114,17 +114,23 @@ func TestCCFuzzDepBundling(t *testing.T) {
|
|||||||
srcs: ["foo.rs"],
|
srcs: ["foo.rs"],
|
||||||
shared_libs: ["libcc_transitive_dep"],
|
shared_libs: ["libcc_transitive_dep"],
|
||||||
}
|
}
|
||||||
|
rust_ffi_static {
|
||||||
|
name: "libtest_fuzzing_static",
|
||||||
|
crate_name: "test_fuzzing",
|
||||||
|
srcs: ["foo.rs"],
|
||||||
|
shared_libs: ["libcc_transitive_dep"],
|
||||||
|
}
|
||||||
cc_fuzz {
|
cc_fuzz {
|
||||||
name: "fuzz_shared_libtest",
|
name: "fuzz_shared_libtest",
|
||||||
shared_libs: ["libtest_fuzzing"],
|
shared_libs: ["libtest_fuzzing"],
|
||||||
}
|
}
|
||||||
cc_fuzz {
|
cc_fuzz {
|
||||||
name: "fuzz_static_libtest",
|
name: "fuzz_static_libtest",
|
||||||
static_rlibs: ["libtest_fuzzing"],
|
static_libs: ["libtest_fuzzing"],
|
||||||
}
|
}
|
||||||
cc_fuzz {
|
cc_fuzz {
|
||||||
name: "fuzz_staticffi_libtest",
|
name: "fuzz_staticffi_libtest",
|
||||||
static_libs: ["libtest_fuzzing"],
|
static_libs: ["libtest_fuzzing_static"],
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
|
||||||
|
@@ -22,18 +22,20 @@ import (
|
|||||||
"android/soong/cc"
|
"android/soong/cc"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Test that cc modules can link against vendor_available rust_ffi_rlib/rust_ffi_static libraries.
|
// Test that cc modules can depend on vendor_available rust_ffi_rlib/rust_ffi_static libraries.
|
||||||
func TestVendorLinkage(t *testing.T) {
|
func TestVendorLinkage(t *testing.T) {
|
||||||
ctx := testRust(t, `
|
ctx := testRust(t, `
|
||||||
cc_binary {
|
cc_binary {
|
||||||
name: "fizz_vendor_available",
|
name: "fizz_vendor_available",
|
||||||
static_libs: ["libfoo_vendor_static"],
|
static_libs: [
|
||||||
static_rlibs: ["libfoo_vendor"],
|
"libfoo_vendor",
|
||||||
|
"libfoo_vendor_static"
|
||||||
|
],
|
||||||
vendor_available: true,
|
vendor_available: true,
|
||||||
}
|
}
|
||||||
cc_binary {
|
cc_binary {
|
||||||
name: "fizz_soc_specific",
|
name: "fizz_soc_specific",
|
||||||
static_rlibs: ["libfoo_vendor"],
|
static_libs: ["libfoo_vendor"],
|
||||||
soc_specific: true,
|
soc_specific: true,
|
||||||
}
|
}
|
||||||
rust_ffi_rlib {
|
rust_ffi_rlib {
|
||||||
@@ -52,8 +54,8 @@ func TestVendorLinkage(t *testing.T) {
|
|||||||
|
|
||||||
vendorBinary := ctx.ModuleForTests("fizz_vendor_available", "android_vendor_arm64_armv8-a").Module().(*cc.Module)
|
vendorBinary := ctx.ModuleForTests("fizz_vendor_available", "android_vendor_arm64_armv8-a").Module().(*cc.Module)
|
||||||
|
|
||||||
if !android.InList("libfoo_vendor_static.vendor", vendorBinary.Properties.AndroidMkStaticLibs) {
|
if android.InList("libfoo_vendor_static.vendor", vendorBinary.Properties.AndroidMkStaticLibs) {
|
||||||
t.Errorf("vendorBinary should have a dependency on libfoo_vendor_static.vendor: %#v", vendorBinary.Properties.AndroidMkStaticLibs)
|
t.Errorf("vendorBinary should not have a staticlib dependency on libfoo_vendor_static.vendor: %#v", vendorBinary.Properties.AndroidMkStaticLibs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,8 +112,10 @@ func TestVendorRamdiskLinkage(t *testing.T) {
|
|||||||
ctx := testRust(t, `
|
ctx := testRust(t, `
|
||||||
cc_library_shared {
|
cc_library_shared {
|
||||||
name: "libcc_vendor_ramdisk",
|
name: "libcc_vendor_ramdisk",
|
||||||
static_rlibs: ["libfoo_vendor_ramdisk"],
|
static_libs: [
|
||||||
static_libs: ["libfoo_static_vendor_ramdisk"],
|
"libfoo_vendor_ramdisk",
|
||||||
|
"libfoo_static_vendor_ramdisk"
|
||||||
|
],
|
||||||
system_shared_libs: [],
|
system_shared_libs: [],
|
||||||
vendor_ramdisk_available: true,
|
vendor_ramdisk_available: true,
|
||||||
}
|
}
|
||||||
@@ -131,8 +135,8 @@ func TestVendorRamdiskLinkage(t *testing.T) {
|
|||||||
|
|
||||||
vendorRamdiskLibrary := ctx.ModuleForTests("libcc_vendor_ramdisk", "android_vendor_ramdisk_arm64_armv8-a_shared").Module().(*cc.Module)
|
vendorRamdiskLibrary := ctx.ModuleForTests("libcc_vendor_ramdisk", "android_vendor_ramdisk_arm64_armv8-a_shared").Module().(*cc.Module)
|
||||||
|
|
||||||
if !android.InList("libfoo_static_vendor_ramdisk.vendor_ramdisk", vendorRamdiskLibrary.Properties.AndroidMkStaticLibs) {
|
if android.InList("libfoo_static_vendor_ramdisk.vendor_ramdisk", vendorRamdiskLibrary.Properties.AndroidMkStaticLibs) {
|
||||||
t.Errorf("libcc_vendor_ramdisk should have a dependency on libfoo_static_vendor_ramdisk")
|
t.Errorf("libcc_vendor_ramdisk should not have a dependency on the libfoo_static_vendor_ramdisk static library")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -43,9 +43,9 @@ func init() {
|
|||||||
android.RegisterModuleType("rust_ffi_host_rlib", RustFFIRlibHostFactory)
|
android.RegisterModuleType("rust_ffi_host_rlib", RustFFIRlibHostFactory)
|
||||||
|
|
||||||
// TODO: Remove when all instances of rust_ffi_static have been switched to rust_ffi_rlib
|
// TODO: Remove when all instances of rust_ffi_static have been switched to rust_ffi_rlib
|
||||||
// Alias rust_ffi_static to the combined rust_ffi_rlib factory
|
// Alias rust_ffi_static to the rust_ffi_rlib factory
|
||||||
android.RegisterModuleType("rust_ffi_static", RustFFIStaticRlibFactory)
|
android.RegisterModuleType("rust_ffi_static", RustFFIRlibFactory)
|
||||||
android.RegisterModuleType("rust_ffi_host_static", RustFFIStaticRlibHostFactory)
|
android.RegisterModuleType("rust_ffi_host_static", RustFFIRlibHostFactory)
|
||||||
}
|
}
|
||||||
|
|
||||||
type VariantLibraryProperties struct {
|
type VariantLibraryProperties struct {
|
||||||
@@ -353,7 +353,7 @@ func RustFFISharedHostFactory() android.Module {
|
|||||||
// type "rlib").
|
// type "rlib").
|
||||||
func RustFFIRlibHostFactory() android.Module {
|
func RustFFIRlibHostFactory() android.Module {
|
||||||
module, library := NewRustLibrary(android.HostSupported)
|
module, library := NewRustLibrary(android.HostSupported)
|
||||||
library.BuildOnlyRlibStatic()
|
library.BuildOnlyRlib()
|
||||||
|
|
||||||
library.isFFI = true
|
library.isFFI = true
|
||||||
return module.Init()
|
return module.Init()
|
||||||
@@ -368,30 +368,12 @@ func RustFFIRlibFactory() android.Module {
|
|||||||
return module.Init()
|
return module.Init()
|
||||||
}
|
}
|
||||||
|
|
||||||
// rust_ffi_static produces a staticlib and an rlib variant
|
|
||||||
func RustFFIStaticRlibFactory() android.Module {
|
|
||||||
module, library := NewRustLibrary(android.HostAndDeviceSupported)
|
|
||||||
library.BuildOnlyRlibStatic()
|
|
||||||
|
|
||||||
library.isFFI = true
|
|
||||||
return module.Init()
|
|
||||||
}
|
|
||||||
|
|
||||||
// rust_ffi_static_host produces a staticlib and an rlib variant for the host
|
|
||||||
func RustFFIStaticRlibHostFactory() android.Module {
|
|
||||||
module, library := NewRustLibrary(android.HostSupported)
|
|
||||||
library.BuildOnlyRlibStatic()
|
|
||||||
|
|
||||||
library.isFFI = true
|
|
||||||
return module.Init()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (library *libraryDecorator) BuildOnlyFFI() {
|
func (library *libraryDecorator) BuildOnlyFFI() {
|
||||||
library.MutatedProperties.BuildDylib = false
|
library.MutatedProperties.BuildDylib = false
|
||||||
// we build rlibs for later static ffi linkage.
|
// we build rlibs for later static ffi linkage.
|
||||||
library.MutatedProperties.BuildRlib = true
|
library.MutatedProperties.BuildRlib = true
|
||||||
library.MutatedProperties.BuildShared = true
|
library.MutatedProperties.BuildShared = true
|
||||||
library.MutatedProperties.BuildStatic = true
|
library.MutatedProperties.BuildStatic = false
|
||||||
|
|
||||||
library.isFFI = true
|
library.isFFI = true
|
||||||
}
|
}
|
||||||
@@ -417,14 +399,6 @@ func (library *libraryDecorator) BuildOnlyRlib() {
|
|||||||
library.MutatedProperties.BuildStatic = false
|
library.MutatedProperties.BuildStatic = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (library *libraryDecorator) BuildOnlyRlibStatic() {
|
|
||||||
library.MutatedProperties.BuildDylib = false
|
|
||||||
library.MutatedProperties.BuildRlib = true
|
|
||||||
library.MutatedProperties.BuildShared = false
|
|
||||||
library.MutatedProperties.BuildStatic = true
|
|
||||||
library.isFFI = true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (library *libraryDecorator) BuildOnlyStatic() {
|
func (library *libraryDecorator) BuildOnlyStatic() {
|
||||||
library.MutatedProperties.BuildRlib = false
|
library.MutatedProperties.BuildRlib = false
|
||||||
library.MutatedProperties.BuildDylib = false
|
library.MutatedProperties.BuildDylib = false
|
||||||
@@ -766,10 +740,13 @@ func LibraryMutator(mctx android.BottomUpMutatorContext) {
|
|||||||
|
|
||||||
// The order of the variations (modules) matches the variant names provided. Iterate
|
// The order of the variations (modules) matches the variant names provided. Iterate
|
||||||
// through the new variation modules and set their mutated properties.
|
// through the new variation modules and set their mutated properties.
|
||||||
|
var emptyVariant = false
|
||||||
|
var rlibVariant = false
|
||||||
for i, v := range modules {
|
for i, v := range modules {
|
||||||
switch variants[i] {
|
switch variants[i] {
|
||||||
case rlibVariation:
|
case rlibVariation:
|
||||||
v.(*Module).compiler.(libraryInterface).setRlib()
|
v.(*Module).compiler.(libraryInterface).setRlib()
|
||||||
|
rlibVariant = true
|
||||||
case dylibVariation:
|
case dylibVariation:
|
||||||
v.(*Module).compiler.(libraryInterface).setDylib()
|
v.(*Module).compiler.(libraryInterface).setDylib()
|
||||||
if v.(*Module).ModuleBase.ImageVariation().Variation == android.VendorRamdiskVariation {
|
if v.(*Module).ModuleBase.ImageVariation().Variation == android.VendorRamdiskVariation {
|
||||||
@@ -784,11 +761,19 @@ func LibraryMutator(mctx android.BottomUpMutatorContext) {
|
|||||||
// Disable the compilation steps.
|
// Disable the compilation steps.
|
||||||
v.(*Module).compiler.SetDisabled()
|
v.(*Module).compiler.SetDisabled()
|
||||||
case "":
|
case "":
|
||||||
// if there's an empty variant, alias it so it is the default variant
|
emptyVariant = true
|
||||||
mctx.AliasVariation("")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if rlibVariant && library.isFFILibrary() {
|
||||||
|
// If an rlib variant is set and this is an FFI library, make it the
|
||||||
|
// default variant so CC can link against it appropriately.
|
||||||
|
mctx.AliasVariation(rlibVariation)
|
||||||
|
} else if emptyVariant {
|
||||||
|
// If there's an empty variant, alias it so it is the default variant
|
||||||
|
mctx.AliasVariation("")
|
||||||
|
}
|
||||||
|
|
||||||
// If a source variant is created, add an inter-variant dependency
|
// If a source variant is created, add an inter-variant dependency
|
||||||
// between the other variants and the source variant.
|
// between the other variants and the source variant.
|
||||||
if sourceVariant {
|
if sourceVariant {
|
||||||
@@ -817,6 +802,7 @@ func LibstdMutator(mctx android.BottomUpMutatorContext) {
|
|||||||
rlib := modules[0].(*Module)
|
rlib := modules[0].(*Module)
|
||||||
rlib.compiler.(libraryInterface).setRlibStd()
|
rlib.compiler.(libraryInterface).setRlibStd()
|
||||||
rlib.Properties.RustSubName += RlibStdlibSuffix
|
rlib.Properties.RustSubName += RlibStdlibSuffix
|
||||||
|
mctx.AliasVariation("rlib-std")
|
||||||
} else {
|
} else {
|
||||||
variants := []string{"rlib-std", "dylib-std"}
|
variants := []string{"rlib-std", "dylib-std"}
|
||||||
modules := mctx.CreateLocalVariations(variants...)
|
modules := mctx.CreateLocalVariations(variants...)
|
||||||
|
@@ -34,10 +34,14 @@ func TestLibraryVariants(t *testing.T) {
|
|||||||
name: "libfoo.ffi",
|
name: "libfoo.ffi",
|
||||||
srcs: ["foo.rs"],
|
srcs: ["foo.rs"],
|
||||||
crate_name: "foo"
|
crate_name: "foo"
|
||||||
|
}
|
||||||
|
rust_ffi_host_static {
|
||||||
|
name: "libfoo.ffi_static",
|
||||||
|
srcs: ["foo.rs"],
|
||||||
|
crate_name: "foo"
|
||||||
}`)
|
}`)
|
||||||
|
|
||||||
// Test all variants are being built.
|
// Test all variants are being built.
|
||||||
libfooStatic := ctx.ModuleForTests("libfoo.ffi", "linux_glibc_x86_64_static").Rule("rustc")
|
|
||||||
libfooRlib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_rlib_rlib-std").Rule("rustc")
|
libfooRlib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_rlib_rlib-std").Rule("rustc")
|
||||||
libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Rule("rustc")
|
libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Rule("rustc")
|
||||||
libfooFFIRlib := ctx.ModuleForTests("libfoo.ffi", "linux_glibc_x86_64_rlib_rlib-std").Rule("rustc")
|
libfooFFIRlib := ctx.ModuleForTests("libfoo.ffi", "linux_glibc_x86_64_rlib_rlib-std").Rule("rustc")
|
||||||
@@ -46,7 +50,6 @@ func TestLibraryVariants(t *testing.T) {
|
|||||||
rlibCrateType := "rlib"
|
rlibCrateType := "rlib"
|
||||||
dylibCrateType := "dylib"
|
dylibCrateType := "dylib"
|
||||||
sharedCrateType := "cdylib"
|
sharedCrateType := "cdylib"
|
||||||
staticCrateType := "staticlib"
|
|
||||||
|
|
||||||
// Test crate type for rlib is correct.
|
// Test crate type for rlib is correct.
|
||||||
if !strings.Contains(libfooRlib.Args["rustcFlags"], "crate-type="+rlibCrateType) {
|
if !strings.Contains(libfooRlib.Args["rustcFlags"], "crate-type="+rlibCrateType) {
|
||||||
@@ -58,11 +61,6 @@ func TestLibraryVariants(t *testing.T) {
|
|||||||
t.Errorf("missing crate-type for static variant, expecting %#v, rustcFlags: %#v", dylibCrateType, libfooDylib.Args["rustcFlags"])
|
t.Errorf("missing crate-type for static variant, expecting %#v, rustcFlags: %#v", dylibCrateType, libfooDylib.Args["rustcFlags"])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test crate type for C static libraries is correct.
|
|
||||||
if !strings.Contains(libfooStatic.Args["rustcFlags"], "crate-type="+staticCrateType) {
|
|
||||||
t.Errorf("missing crate-type for static variant, expecting %#v, rustcFlags: %#v", staticCrateType, libfooStatic.Args["rustcFlags"])
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test crate type for FFI rlibs is correct
|
// Test crate type for FFI rlibs is correct
|
||||||
if !strings.Contains(libfooFFIRlib.Args["rustcFlags"], "crate-type="+rlibCrateType) {
|
if !strings.Contains(libfooFFIRlib.Args["rustcFlags"], "crate-type="+rlibCrateType) {
|
||||||
t.Errorf("missing crate-type for static variant, expecting %#v, rustcFlags: %#v", rlibCrateType, libfooFFIRlib.Args["rustcFlags"])
|
t.Errorf("missing crate-type for static variant, expecting %#v, rustcFlags: %#v", rlibCrateType, libfooFFIRlib.Args["rustcFlags"])
|
||||||
@@ -188,23 +186,18 @@ func TestSharedLibraryToc(t *testing.T) {
|
|||||||
|
|
||||||
func TestStaticLibraryLinkage(t *testing.T) {
|
func TestStaticLibraryLinkage(t *testing.T) {
|
||||||
ctx := testRust(t, `
|
ctx := testRust(t, `
|
||||||
rust_ffi {
|
rust_ffi_static {
|
||||||
name: "libfoo",
|
name: "libfoo",
|
||||||
srcs: ["foo.rs"],
|
srcs: ["foo.rs"],
|
||||||
crate_name: "foo",
|
crate_name: "foo",
|
||||||
}`)
|
}`)
|
||||||
|
|
||||||
libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_rlib_rlib-std")
|
libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_rlib_rlib-std")
|
||||||
libfooStatic := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static")
|
|
||||||
|
|
||||||
if !android.InList("libstd", libfoo.Module().(*Module).Properties.AndroidMkRlibs) {
|
if !android.InList("libstd", libfoo.Module().(*Module).Properties.AndroidMkRlibs) {
|
||||||
t.Errorf("Static libstd rlib expected to be a dependency of Rust rlib libraries. Rlib deps are: %#v",
|
t.Errorf("Static libstd rlib expected to be a dependency of Rust rlib libraries. Rlib deps are: %#v",
|
||||||
libfoo.Module().(*Module).Properties.AndroidMkDylibs)
|
libfoo.Module().(*Module).Properties.AndroidMkDylibs)
|
||||||
}
|
}
|
||||||
if !android.InList("libstd", libfooStatic.Module().(*Module).Properties.AndroidMkRlibs) {
|
|
||||||
t.Errorf("Static libstd rlib expected to be a dependency of Rust static libraries. Rlib deps are: %#v",
|
|
||||||
libfoo.Module().(*Module).Properties.AndroidMkDylibs)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNativeDependencyOfRlib(t *testing.T) {
|
func TestNativeDependencyOfRlib(t *testing.T) {
|
||||||
@@ -215,39 +208,31 @@ func TestNativeDependencyOfRlib(t *testing.T) {
|
|||||||
rlibs: ["librust_rlib"],
|
rlibs: ["librust_rlib"],
|
||||||
srcs: ["foo.rs"],
|
srcs: ["foo.rs"],
|
||||||
}
|
}
|
||||||
rust_ffi_static {
|
|
||||||
name: "libffi_static",
|
|
||||||
crate_name: "ffi_static",
|
|
||||||
rlibs: ["librust_rlib"],
|
|
||||||
srcs: ["foo.rs"],
|
|
||||||
}
|
|
||||||
rust_library_rlib {
|
rust_library_rlib {
|
||||||
name: "librust_rlib",
|
name: "librust_rlib",
|
||||||
crate_name: "rust_rlib",
|
crate_name: "rust_rlib",
|
||||||
srcs: ["foo.rs"],
|
srcs: ["foo.rs"],
|
||||||
shared_libs: ["shared_cc_dep"],
|
shared_libs: ["libshared_cc_dep"],
|
||||||
static_libs: ["static_cc_dep"],
|
static_libs: ["libstatic_cc_dep"],
|
||||||
}
|
}
|
||||||
cc_library_shared {
|
cc_library_shared {
|
||||||
name: "shared_cc_dep",
|
name: "libshared_cc_dep",
|
||||||
srcs: ["foo.cpp"],
|
srcs: ["foo.cpp"],
|
||||||
}
|
}
|
||||||
cc_library_static {
|
cc_library_static {
|
||||||
name: "static_cc_dep",
|
name: "libstatic_cc_dep",
|
||||||
srcs: ["foo.cpp"],
|
srcs: ["foo.cpp"],
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
|
||||||
rustRlibRlibStd := ctx.ModuleForTests("librust_rlib", "android_arm64_armv8-a_rlib_rlib-std")
|
rustRlibRlibStd := ctx.ModuleForTests("librust_rlib", "android_arm64_armv8-a_rlib_rlib-std")
|
||||||
rustRlibDylibStd := ctx.ModuleForTests("librust_rlib", "android_arm64_armv8-a_rlib_dylib-std")
|
rustRlibDylibStd := ctx.ModuleForTests("librust_rlib", "android_arm64_armv8-a_rlib_dylib-std")
|
||||||
ffiStatic := ctx.ModuleForTests("libffi_static", "android_arm64_armv8-a_static")
|
|
||||||
ffiRlib := ctx.ModuleForTests("libffi_rlib", "android_arm64_armv8-a_rlib_rlib-std")
|
ffiRlib := ctx.ModuleForTests("libffi_rlib", "android_arm64_armv8-a_rlib_rlib-std")
|
||||||
|
|
||||||
modules := []android.TestingModule{
|
modules := []android.TestingModule{
|
||||||
rustRlibRlibStd,
|
rustRlibRlibStd,
|
||||||
rustRlibDylibStd,
|
rustRlibDylibStd,
|
||||||
ffiRlib,
|
ffiRlib,
|
||||||
ffiStatic,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// librust_rlib specifies -L flag to cc deps output directory on rustc command
|
// librust_rlib specifies -L flag to cc deps output directory on rustc command
|
||||||
@@ -258,17 +243,17 @@ func TestNativeDependencyOfRlib(t *testing.T) {
|
|||||||
// TODO: We could consider removing these flags
|
// TODO: We could consider removing these flags
|
||||||
for _, module := range modules {
|
for _, module := range modules {
|
||||||
if !strings.Contains(module.Rule("rustc").Args["libFlags"],
|
if !strings.Contains(module.Rule("rustc").Args["libFlags"],
|
||||||
"-L out/soong/.intermediates/shared_cc_dep/android_arm64_armv8-a_shared/") {
|
"-L out/soong/.intermediates/libshared_cc_dep/android_arm64_armv8-a_shared/") {
|
||||||
t.Errorf(
|
t.Errorf(
|
||||||
"missing -L flag for shared_cc_dep, rustcFlags: %#v",
|
"missing -L flag for libshared_cc_dep of %s, rustcFlags: %#v",
|
||||||
rustRlibRlibStd.Rule("rustc").Args["libFlags"],
|
module.Module().Name(), rustRlibRlibStd.Rule("rustc").Args["libFlags"],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if !strings.Contains(module.Rule("rustc").Args["libFlags"],
|
if !strings.Contains(module.Rule("rustc").Args["libFlags"],
|
||||||
"-L out/soong/.intermediates/static_cc_dep/android_arm64_armv8-a_static/") {
|
"-L out/soong/.intermediates/libstatic_cc_dep/android_arm64_armv8-a_static/") {
|
||||||
t.Errorf(
|
t.Errorf(
|
||||||
"missing -L flag for static_cc_dep, rustcFlags: %#v",
|
"missing -L flag for libstatic_cc_dep of %s, rustcFlags: %#v",
|
||||||
rustRlibRlibStd.Rule("rustc").Args["libFlags"],
|
module.Module().Name(), rustRlibRlibStd.Rule("rustc").Args["libFlags"],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -305,15 +290,23 @@ func TestAutoDeps(t *testing.T) {
|
|||||||
"libbar",
|
"libbar",
|
||||||
"librlib_only",
|
"librlib_only",
|
||||||
],
|
],
|
||||||
|
}
|
||||||
|
rust_ffi_host_static {
|
||||||
|
name: "libfoo.ffi.static",
|
||||||
|
srcs: ["foo.rs"],
|
||||||
|
crate_name: "foo",
|
||||||
|
rustlibs: [
|
||||||
|
"libbar",
|
||||||
|
"librlib_only",
|
||||||
|
],
|
||||||
}`)
|
}`)
|
||||||
|
|
||||||
libfooRlib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_rlib_rlib-std")
|
libfooRlib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_rlib_rlib-std")
|
||||||
libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib")
|
libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib")
|
||||||
libfooFFIRlib := ctx.ModuleForTests("libfoo.ffi", "linux_glibc_x86_64_rlib_rlib-std")
|
libfooFFIRlib := ctx.ModuleForTests("libfoo.ffi", "linux_glibc_x86_64_rlib_rlib-std")
|
||||||
libfooStatic := ctx.ModuleForTests("libfoo.ffi", "linux_glibc_x86_64_static")
|
|
||||||
libfooShared := ctx.ModuleForTests("libfoo.ffi", "linux_glibc_x86_64_shared")
|
libfooShared := ctx.ModuleForTests("libfoo.ffi", "linux_glibc_x86_64_shared")
|
||||||
|
|
||||||
for _, static := range []android.TestingModule{libfooRlib, libfooStatic, libfooFFIRlib} {
|
for _, static := range []android.TestingModule{libfooRlib, libfooFFIRlib} {
|
||||||
if !android.InList("libbar.rlib-std", static.Module().(*Module).Properties.AndroidMkRlibs) {
|
if !android.InList("libbar.rlib-std", static.Module().(*Module).Properties.AndroidMkRlibs) {
|
||||||
t.Errorf("libbar not present as rlib dependency in static lib: %s", static.Module().Name())
|
t.Errorf("libbar not present as rlib dependency in static lib: %s", static.Module().Name())
|
||||||
}
|
}
|
||||||
@@ -381,6 +374,12 @@ func TestLibstdLinkage(t *testing.T) {
|
|||||||
crate_name: "bar",
|
crate_name: "bar",
|
||||||
rustlibs: ["libfoo"],
|
rustlibs: ["libfoo"],
|
||||||
}
|
}
|
||||||
|
rust_ffi_static {
|
||||||
|
name: "libbar_static",
|
||||||
|
srcs: ["foo.rs"],
|
||||||
|
crate_name: "bar",
|
||||||
|
rustlibs: ["libfoo"],
|
||||||
|
}
|
||||||
rust_ffi {
|
rust_ffi {
|
||||||
name: "libbar.prefer_rlib",
|
name: "libbar.prefer_rlib",
|
||||||
srcs: ["foo.rs"],
|
srcs: ["foo.rs"],
|
||||||
@@ -394,7 +393,6 @@ func TestLibstdLinkage(t *testing.T) {
|
|||||||
libfooRlibDynamic := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_rlib_dylib-std").Module().(*Module)
|
libfooRlibDynamic := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_rlib_dylib-std").Module().(*Module)
|
||||||
|
|
||||||
libbarShared := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module().(*Module)
|
libbarShared := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module().(*Module)
|
||||||
libbarStatic := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_static").Module().(*Module)
|
|
||||||
libbarFFIRlib := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_rlib_rlib-std").Module().(*Module)
|
libbarFFIRlib := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_rlib_rlib-std").Module().(*Module)
|
||||||
|
|
||||||
// prefer_rlib works the same for both rust_library and rust_ffi, so a single check is sufficient here.
|
// prefer_rlib works the same for both rust_library and rust_ffi, so a single check is sufficient here.
|
||||||
@@ -413,12 +411,6 @@ func TestLibstdLinkage(t *testing.T) {
|
|||||||
if !android.InList("libstd", libbarShared.Properties.AndroidMkDylibs) {
|
if !android.InList("libstd", libbarShared.Properties.AndroidMkDylibs) {
|
||||||
t.Errorf("Device rust_ffi_shared does not link libstd as an dylib")
|
t.Errorf("Device rust_ffi_shared does not link libstd as an dylib")
|
||||||
}
|
}
|
||||||
if !android.InList("libstd", libbarStatic.Properties.AndroidMkRlibs) {
|
|
||||||
t.Errorf("Device rust_ffi_static does not link libstd as an rlib")
|
|
||||||
}
|
|
||||||
if !android.InList("libfoo.rlib-std", libbarStatic.Properties.AndroidMkRlibs) {
|
|
||||||
t.Errorf("Device rust_ffi_static does not link dependent rustlib rlib-std variant")
|
|
||||||
}
|
|
||||||
if !android.InList("libstd", libbarFFIRlib.Properties.AndroidMkRlibs) {
|
if !android.InList("libstd", libbarFFIRlib.Properties.AndroidMkRlibs) {
|
||||||
t.Errorf("Device rust_ffi_rlib does not link libstd as an rlib")
|
t.Errorf("Device rust_ffi_rlib does not link libstd as an rlib")
|
||||||
}
|
}
|
||||||
|
45
rust/rust.go
45
rust/rust.go
@@ -420,7 +420,7 @@ type PathDeps struct {
|
|||||||
depFlags []string
|
depFlags []string
|
||||||
depLinkFlags []string
|
depLinkFlags []string
|
||||||
|
|
||||||
// linkDirs are link paths passed via -L to rustc. linkObjects are objects passed directly to the linker.
|
// linkDirs are link paths passed via -L to rustc. linkObjects are objects passed directly to the linker
|
||||||
// Both of these are exported and propagate to dependencies.
|
// Both of these are exported and propagate to dependencies.
|
||||||
linkDirs []string
|
linkDirs []string
|
||||||
linkObjects []string
|
linkObjects []string
|
||||||
@@ -442,9 +442,6 @@ type PathDeps struct {
|
|||||||
// Paths to generated source files
|
// Paths to generated source files
|
||||||
SrcDeps android.Paths
|
SrcDeps android.Paths
|
||||||
srcProviderFiles android.Paths
|
srcProviderFiles android.Paths
|
||||||
|
|
||||||
// Used by Generated Libraries
|
|
||||||
depExportedRlibs []cc.RustRlibDep
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type RustLibraries []RustLibrary
|
type RustLibraries []RustLibrary
|
||||||
@@ -465,6 +462,7 @@ type xref interface {
|
|||||||
|
|
||||||
type flagExporter struct {
|
type flagExporter struct {
|
||||||
linkDirs []string
|
linkDirs []string
|
||||||
|
ccLinkDirs []string
|
||||||
linkObjects []string
|
linkObjects []string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -658,6 +656,24 @@ func (mod *Module) BuildStaticVariant() bool {
|
|||||||
panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", mod.BaseModuleName()))
|
panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", mod.BaseModuleName()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (mod *Module) BuildRlibVariant() bool {
|
||||||
|
if mod.compiler != nil {
|
||||||
|
if library, ok := mod.compiler.(libraryInterface); ok {
|
||||||
|
return library.buildRlib()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panic(fmt.Errorf("BuildRlibVariant called on non-library module: %q", mod.BaseModuleName()))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mod *Module) IsRustFFI() bool {
|
||||||
|
if mod.compiler != nil {
|
||||||
|
if library, ok := mod.compiler.(libraryInterface); ok {
|
||||||
|
return library.isFFILibrary()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (mod *Module) BuildSharedVariant() bool {
|
func (mod *Module) BuildSharedVariant() bool {
|
||||||
if mod.compiler != nil {
|
if mod.compiler != nil {
|
||||||
if library, ok := mod.compiler.(libraryInterface); ok {
|
if library, ok := mod.compiler.(libraryInterface); ok {
|
||||||
@@ -1237,7 +1253,6 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
|||||||
ctx.VisitDirectDeps(func(dep android.Module) {
|
ctx.VisitDirectDeps(func(dep android.Module) {
|
||||||
depName := ctx.OtherModuleName(dep)
|
depName := ctx.OtherModuleName(dep)
|
||||||
depTag := ctx.OtherModuleDependencyTag(dep)
|
depTag := ctx.OtherModuleDependencyTag(dep)
|
||||||
|
|
||||||
if _, exists := skipModuleList[depName]; exists {
|
if _, exists := skipModuleList[depName]; exists {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -1250,8 +1265,8 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
|||||||
//Handle Rust Modules
|
//Handle Rust Modules
|
||||||
makeLibName := rustMakeLibName(ctx, mod, rustDep, depName+rustDep.Properties.RustSubName)
|
makeLibName := rustMakeLibName(ctx, mod, rustDep, depName+rustDep.Properties.RustSubName)
|
||||||
|
|
||||||
switch depTag {
|
switch {
|
||||||
case dylibDepTag:
|
case depTag == dylibDepTag:
|
||||||
dylib, ok := rustDep.compiler.(libraryInterface)
|
dylib, ok := rustDep.compiler.(libraryInterface)
|
||||||
if !ok || !dylib.dylib() {
|
if !ok || !dylib.dylib() {
|
||||||
ctx.ModuleErrorf("mod %q not an dylib library", depName)
|
ctx.ModuleErrorf("mod %q not an dylib library", depName)
|
||||||
@@ -1261,8 +1276,7 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
|||||||
mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, makeLibName)
|
mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, makeLibName)
|
||||||
mod.Properties.SnapshotDylibs = append(mod.Properties.SnapshotDylibs, cc.BaseLibName(depName))
|
mod.Properties.SnapshotDylibs = append(mod.Properties.SnapshotDylibs, cc.BaseLibName(depName))
|
||||||
|
|
||||||
case rlibDepTag:
|
case depTag == rlibDepTag:
|
||||||
|
|
||||||
rlib, ok := rustDep.compiler.(libraryInterface)
|
rlib, ok := rustDep.compiler.(libraryInterface)
|
||||||
if !ok || !rlib.rlib() {
|
if !ok || !rlib.rlib() {
|
||||||
ctx.ModuleErrorf("mod %q not an rlib library", makeLibName)
|
ctx.ModuleErrorf("mod %q not an rlib library", makeLibName)
|
||||||
@@ -1277,16 +1291,25 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
|||||||
depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
|
depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
|
||||||
depPaths.exportedLinkDirs = append(depPaths.exportedLinkDirs, linkPathFromFilePath(rustDep.OutputFile().Path()))
|
depPaths.exportedLinkDirs = append(depPaths.exportedLinkDirs, linkPathFromFilePath(rustDep.OutputFile().Path()))
|
||||||
|
|
||||||
case procMacroDepTag:
|
case depTag == procMacroDepTag:
|
||||||
directProcMacroDeps = append(directProcMacroDeps, rustDep)
|
directProcMacroDeps = append(directProcMacroDeps, rustDep)
|
||||||
mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, makeLibName)
|
mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, makeLibName)
|
||||||
// proc_macro link dirs need to be exported, so collect those here.
|
// proc_macro link dirs need to be exported, so collect those here.
|
||||||
depPaths.exportedLinkDirs = append(depPaths.exportedLinkDirs, linkPathFromFilePath(rustDep.OutputFile().Path()))
|
depPaths.exportedLinkDirs = append(depPaths.exportedLinkDirs, linkPathFromFilePath(rustDep.OutputFile().Path()))
|
||||||
|
|
||||||
case sourceDepTag:
|
case depTag == sourceDepTag:
|
||||||
if _, ok := mod.sourceProvider.(*protobufDecorator); ok {
|
if _, ok := mod.sourceProvider.(*protobufDecorator); ok {
|
||||||
collectIncludedProtos(mod, rustDep)
|
collectIncludedProtos(mod, rustDep)
|
||||||
}
|
}
|
||||||
|
case cc.IsStaticDepTag(depTag):
|
||||||
|
// Rust FFI rlibs should not be declared in a Rust modules
|
||||||
|
// "static_libs" list as we can't handle them properly at the
|
||||||
|
// moment (for example, they only produce an rlib-std variant).
|
||||||
|
// Instead, a normal rust_library variant should be used.
|
||||||
|
ctx.PropertyErrorf("static_libs",
|
||||||
|
"found '%s' in static_libs; use a rust_library module in rustlibs instead of a rust_ffi module in static_libs",
|
||||||
|
depName)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
transitiveAndroidMkSharedLibs = append(transitiveAndroidMkSharedLibs, rustDep.transitiveAndroidMkSharedLibs)
|
transitiveAndroidMkSharedLibs = append(transitiveAndroidMkSharedLibs, rustDep.transitiveAndroidMkSharedLibs)
|
||||||
|
@@ -447,23 +447,30 @@ func TestRustRlibs(t *testing.T) {
|
|||||||
export_include_dirs: ["foo_includes"]
|
export_include_dirs: ["foo_includes"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rust_ffi_rlib {
|
||||||
|
name: "libbuzz",
|
||||||
|
crate_name: "buzz",
|
||||||
|
srcs: ["src/lib.rs"],
|
||||||
|
export_include_dirs: ["buzz_includes"]
|
||||||
|
}
|
||||||
|
|
||||||
cc_library_shared {
|
cc_library_shared {
|
||||||
name: "libcc_shared",
|
name: "libcc_shared",
|
||||||
srcs:["foo.c"],
|
srcs:["foo.c"],
|
||||||
static_rlibs: ["libbar"],
|
static_libs: ["libbar"],
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_library_static {
|
cc_library_static {
|
||||||
name: "libcc_static",
|
name: "libcc_static",
|
||||||
srcs:["foo.c"],
|
srcs:["foo.c"],
|
||||||
static_rlibs: ["libfoo"],
|
static_libs: ["libbuzz"],
|
||||||
|
whole_static_libs: ["libfoo"],
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_binary {
|
cc_binary {
|
||||||
name: "ccBin",
|
name: "ccBin",
|
||||||
srcs:["foo.c"],
|
srcs:["foo.c"],
|
||||||
static_rlibs: ["libbar"],
|
static_libs: ["libcc_static", "libbar"],
|
||||||
static_libs: ["libcc_static"],
|
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
|
||||||
@@ -514,10 +521,13 @@ func TestRustRlibs(t *testing.T) {
|
|||||||
"-Ibar_includes", ccbin_cc.Args)
|
"-Ibar_includes", ccbin_cc.Args)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure that direct dependencies and indirect dependencies are
|
// Make sure that direct dependencies and indirect whole static dependencies are
|
||||||
// propagating correctly to the generated rlib.
|
// propagating correctly to the generated rlib.
|
||||||
if !strings.Contains(ccbin_rustc.Args["libFlags"], "--extern foo=") {
|
if !strings.Contains(ccbin_rustc.Args["libFlags"], "--extern foo=") {
|
||||||
t.Errorf("Missing indirect dependency libfoo when writing generated Rust staticlib: %#v", ccbin_rustc.Args["libFlags"])
|
t.Errorf("Missing indirect whole_static_lib dependency libfoo when writing generated Rust staticlib: %#v", ccbin_rustc.Args["libFlags"])
|
||||||
|
}
|
||||||
|
if strings.Contains(ccbin_rustc.Args["libFlags"], "--extern buzz=") {
|
||||||
|
t.Errorf("Indirect static_lib dependency libbuzz found when writing generated Rust staticlib: %#v", ccbin_rustc.Args["libFlags"])
|
||||||
}
|
}
|
||||||
if !strings.Contains(ccbin_rustc.Args["libFlags"], "--extern bar=") {
|
if !strings.Contains(ccbin_rustc.Args["libFlags"], "--extern bar=") {
|
||||||
t.Errorf("Missing direct dependency libbar when writing generated Rust staticlib: %#v", ccbin_rustc.Args["libFlags"])
|
t.Errorf("Missing direct dependency libbar when writing generated Rust staticlib: %#v", ccbin_rustc.Args["libFlags"])
|
||||||
|
@@ -189,11 +189,11 @@ func registerRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
|
|||||||
ctx.RegisterModuleType("rust_ffi", RustFFIFactory)
|
ctx.RegisterModuleType("rust_ffi", RustFFIFactory)
|
||||||
ctx.RegisterModuleType("rust_ffi_shared", RustFFISharedFactory)
|
ctx.RegisterModuleType("rust_ffi_shared", RustFFISharedFactory)
|
||||||
ctx.RegisterModuleType("rust_ffi_rlib", RustFFIRlibFactory)
|
ctx.RegisterModuleType("rust_ffi_rlib", RustFFIRlibFactory)
|
||||||
ctx.RegisterModuleType("rust_ffi_static", RustFFIStaticRlibFactory)
|
ctx.RegisterModuleType("rust_ffi_static", RustFFIRlibFactory)
|
||||||
ctx.RegisterModuleType("rust_ffi_host", RustFFIHostFactory)
|
ctx.RegisterModuleType("rust_ffi_host", RustFFIHostFactory)
|
||||||
ctx.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory)
|
ctx.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory)
|
||||||
ctx.RegisterModuleType("rust_ffi_host_rlib", RustFFIRlibHostFactory)
|
ctx.RegisterModuleType("rust_ffi_host_rlib", RustFFIRlibHostFactory)
|
||||||
ctx.RegisterModuleType("rust_ffi_host_static", RustFFIStaticRlibHostFactory)
|
ctx.RegisterModuleType("rust_ffi_host_static", RustFFIRlibHostFactory)
|
||||||
ctx.RegisterModuleType("rust_proc_macro", ProcMacroFactory)
|
ctx.RegisterModuleType("rust_proc_macro", ProcMacroFactory)
|
||||||
ctx.RegisterModuleType("rust_protobuf", RustProtobufFactory)
|
ctx.RegisterModuleType("rust_protobuf", RustProtobufFactory)
|
||||||
ctx.RegisterModuleType("rust_protobuf_host", RustProtobufHostFactory)
|
ctx.RegisterModuleType("rust_protobuf_host", RustProtobufHostFactory)
|
||||||
|
Reference in New Issue
Block a user