Merge changes from topic "rust-flex" am: 367c01b19b
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1353062 Change-Id: Ia79b3e0dc51ae55431e55b22b1329421e2678c9e
This commit is contained in:
@@ -70,37 +70,37 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TransformSrcToBinary(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
|
func TransformSrcToBinary(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
|
||||||
outputFile android.WritablePath, includeDirs []string) buildOutput {
|
outputFile android.WritablePath, linkDirs []string) buildOutput {
|
||||||
flags.RustFlags = append(flags.RustFlags, "-C lto")
|
flags.RustFlags = append(flags.RustFlags, "-C lto")
|
||||||
|
|
||||||
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "bin", includeDirs)
|
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "bin", linkDirs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TransformSrctoRlib(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
|
func TransformSrctoRlib(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
|
||||||
outputFile android.WritablePath, includeDirs []string) buildOutput {
|
outputFile android.WritablePath, linkDirs []string) buildOutput {
|
||||||
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "rlib", includeDirs)
|
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "rlib", linkDirs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TransformSrctoDylib(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
|
func TransformSrctoDylib(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
|
||||||
outputFile android.WritablePath, includeDirs []string) buildOutput {
|
outputFile android.WritablePath, linkDirs []string) buildOutput {
|
||||||
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "dylib", includeDirs)
|
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "dylib", linkDirs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TransformSrctoStatic(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
|
func TransformSrctoStatic(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
|
||||||
outputFile android.WritablePath, includeDirs []string) buildOutput {
|
outputFile android.WritablePath, linkDirs []string) buildOutput {
|
||||||
flags.RustFlags = append(flags.RustFlags, "-C lto")
|
flags.RustFlags = append(flags.RustFlags, "-C lto")
|
||||||
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "staticlib", includeDirs)
|
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "staticlib", linkDirs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TransformSrctoShared(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
|
func TransformSrctoShared(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
|
||||||
outputFile android.WritablePath, includeDirs []string) buildOutput {
|
outputFile android.WritablePath, linkDirs []string) buildOutput {
|
||||||
flags.RustFlags = append(flags.RustFlags, "-C lto")
|
flags.RustFlags = append(flags.RustFlags, "-C lto")
|
||||||
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "cdylib", includeDirs)
|
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "cdylib", linkDirs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TransformSrctoProcMacro(ctx ModuleContext, mainSrc android.Path, deps PathDeps,
|
func TransformSrctoProcMacro(ctx ModuleContext, mainSrc android.Path, deps PathDeps,
|
||||||
flags Flags, outputFile android.WritablePath, includeDirs []string) buildOutput {
|
flags Flags, outputFile android.WritablePath, linkDirs []string) buildOutput {
|
||||||
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "proc-macro", includeDirs)
|
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "proc-macro", linkDirs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func rustLibsToPaths(libs RustLibraries) android.Paths {
|
func rustLibsToPaths(libs RustLibraries) android.Paths {
|
||||||
@@ -112,7 +112,7 @@ func rustLibsToPaths(libs RustLibraries) android.Paths {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, flags Flags,
|
func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, flags Flags,
|
||||||
outputFile android.WritablePath, crate_type string, includeDirs []string) buildOutput {
|
outputFile android.WritablePath, crate_type string, linkDirs []string) buildOutput {
|
||||||
|
|
||||||
var inputs android.Paths
|
var inputs android.Paths
|
||||||
var implicits android.Paths
|
var implicits android.Paths
|
||||||
@@ -137,16 +137,10 @@ func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, fl
|
|||||||
rustcFlags = append(rustcFlags, "--target="+targetTriple)
|
rustcFlags = append(rustcFlags, "--target="+targetTriple)
|
||||||
linkFlags = append(linkFlags, "-target "+targetTriple)
|
linkFlags = append(linkFlags, "-target "+targetTriple)
|
||||||
}
|
}
|
||||||
// TODO(b/159718669): Once we have defined static libraries in the host
|
|
||||||
// prebuilts Blueprint file, sysroot should be unconditionally sourced
|
// Suppress an implicit sysroot
|
||||||
// from /dev/null. Explicitly set sysroot to avoid clippy-driver to
|
rustcFlags = append(rustcFlags, "--sysroot=/dev/null")
|
||||||
// internally call rustc.
|
|
||||||
if ctx.Host() && ctx.TargetPrimary() {
|
|
||||||
rustcFlags = append(rustcFlags, "--sysroot=${config.RustPath}")
|
|
||||||
} else {
|
|
||||||
// If we're not targeting the host primary arch, do not use a sysroot.
|
|
||||||
rustcFlags = append(rustcFlags, "--sysroot=/dev/null")
|
|
||||||
}
|
|
||||||
// Collect linker flags
|
// Collect linker flags
|
||||||
linkFlags = append(linkFlags, flags.GlobalLinkFlags...)
|
linkFlags = append(linkFlags, flags.GlobalLinkFlags...)
|
||||||
linkFlags = append(linkFlags, flags.LinkFlags...)
|
linkFlags = append(linkFlags, flags.LinkFlags...)
|
||||||
@@ -162,7 +156,7 @@ func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, fl
|
|||||||
libFlags = append(libFlags, "--extern "+proc_macro.CrateName+"="+proc_macro.Path.String())
|
libFlags = append(libFlags, "--extern "+proc_macro.CrateName+"="+proc_macro.Path.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, path := range includeDirs {
|
for _, path := range linkDirs {
|
||||||
libFlags = append(libFlags, "-L "+path)
|
libFlags = append(libFlags, "-L "+path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -103,8 +103,6 @@ type BaseCompilerProperties struct {
|
|||||||
|
|
||||||
type baseCompiler struct {
|
type baseCompiler struct {
|
||||||
Properties BaseCompilerProperties
|
Properties BaseCompilerProperties
|
||||||
depFlags []string
|
|
||||||
linkDirs []string
|
|
||||||
coverageFile android.Path //rustc generates a single gcno file
|
coverageFile android.Path //rustc generates a single gcno file
|
||||||
|
|
||||||
// Install related
|
// Install related
|
||||||
|
@@ -19,7 +19,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
"android/soong/rust/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -74,6 +73,7 @@ type LibraryMutatedProperties struct {
|
|||||||
|
|
||||||
type libraryDecorator struct {
|
type libraryDecorator struct {
|
||||||
*baseCompiler
|
*baseCompiler
|
||||||
|
*flagExporter
|
||||||
|
|
||||||
Properties LibraryCompilerProperties
|
Properties LibraryCompilerProperties
|
||||||
MutatedProperties LibraryMutatedProperties
|
MutatedProperties LibraryMutatedProperties
|
||||||
@@ -111,22 +111,6 @@ func (library *libraryDecorator) nativeCoverage() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (library *libraryDecorator) exportedDirs() []string {
|
|
||||||
return library.linkDirs
|
|
||||||
}
|
|
||||||
|
|
||||||
func (library *libraryDecorator) exportedDepFlags() []string {
|
|
||||||
return library.depFlags
|
|
||||||
}
|
|
||||||
|
|
||||||
func (library *libraryDecorator) reexportDirs(dirs ...string) {
|
|
||||||
library.linkDirs = android.FirstUniqueStrings(append(library.linkDirs, dirs...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (library *libraryDecorator) reexportDepFlags(flags ...string) {
|
|
||||||
library.depFlags = android.FirstUniqueStrings(append(library.depFlags, flags...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (library *libraryDecorator) rlib() bool {
|
func (library *libraryDecorator) rlib() bool {
|
||||||
return library.MutatedProperties.VariantIsRlib
|
return library.MutatedProperties.VariantIsRlib
|
||||||
}
|
}
|
||||||
@@ -199,6 +183,7 @@ func (library *libraryDecorator) autoDep() autoDep {
|
|||||||
|
|
||||||
var _ compiler = (*libraryDecorator)(nil)
|
var _ compiler = (*libraryDecorator)(nil)
|
||||||
var _ libraryInterface = (*libraryDecorator)(nil)
|
var _ libraryInterface = (*libraryDecorator)(nil)
|
||||||
|
var _ exportedFlagsProducer = (*libraryDecorator)(nil)
|
||||||
|
|
||||||
// rust_library produces all rust variants.
|
// rust_library produces all rust variants.
|
||||||
func RustLibraryFactory() android.Module {
|
func RustLibraryFactory() android.Module {
|
||||||
@@ -337,6 +322,7 @@ func NewRustLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorat
|
|||||||
BuildStatic: false,
|
BuildStatic: false,
|
||||||
},
|
},
|
||||||
baseCompiler: NewBaseCompiler("lib", "lib64", InstallInSystem),
|
baseCompiler: NewBaseCompiler("lib", "lib64", InstallInSystem),
|
||||||
|
flagExporter: NewFlagExporter(),
|
||||||
}
|
}
|
||||||
|
|
||||||
module.compiler = library
|
module.compiler = library
|
||||||
@@ -351,15 +337,6 @@ func (library *libraryDecorator) compilerProps() []interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (library *libraryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
|
func (library *libraryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
|
||||||
|
|
||||||
// TODO(b/155498724) Remove if C static libraries no longer require libstd as an rlib dependency.
|
|
||||||
if !ctx.Host() && library.static() {
|
|
||||||
library.setNoStdlibs()
|
|
||||||
for _, stdlib := range config.Stdlibs {
|
|
||||||
deps.Rlibs = append(deps.Rlibs, stdlib)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
deps = library.baseCompiler.compilerDeps(ctx, deps)
|
deps = library.baseCompiler.compilerDeps(ctx, deps)
|
||||||
|
|
||||||
if ctx.toolchain().Bionic() && (library.dylib() || library.shared()) {
|
if ctx.toolchain().Bionic() && (library.dylib() || library.shared()) {
|
||||||
@@ -438,8 +415,8 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa
|
|||||||
library.coverageOutputZipFile = TransformCoverageFilesToZip(ctx, coverageFiles, library.getStem(ctx))
|
library.coverageOutputZipFile = TransformCoverageFilesToZip(ctx, coverageFiles, library.getStem(ctx))
|
||||||
|
|
||||||
if library.rlib() || library.dylib() {
|
if library.rlib() || library.dylib() {
|
||||||
library.reexportDirs(deps.linkDirs...)
|
library.exportLinkDirs(deps.linkDirs...)
|
||||||
library.reexportDepFlags(deps.depFlags...)
|
library.exportDepFlags(deps.depFlags...)
|
||||||
}
|
}
|
||||||
library.unstrippedOutputFile = outputFile
|
library.unstrippedOutputFile = outputFile
|
||||||
|
|
||||||
|
@@ -27,6 +27,8 @@ func init() {
|
|||||||
type PrebuiltProperties struct {
|
type PrebuiltProperties struct {
|
||||||
// path to the prebuilt file
|
// path to the prebuilt file
|
||||||
Srcs []string `android:"path,arch_variant"`
|
Srcs []string `android:"path,arch_variant"`
|
||||||
|
// directories containing associated rlib dependencies
|
||||||
|
Link_dirs []string `android:"path,arch_variant"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type prebuiltLibraryDecorator struct {
|
type prebuiltLibraryDecorator struct {
|
||||||
@@ -35,6 +37,7 @@ type prebuiltLibraryDecorator struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var _ compiler = (*prebuiltLibraryDecorator)(nil)
|
var _ compiler = (*prebuiltLibraryDecorator)(nil)
|
||||||
|
var _ exportedFlagsProducer = (*prebuiltLibraryDecorator)(nil)
|
||||||
|
|
||||||
func PrebuiltLibraryFactory() android.Module {
|
func PrebuiltLibraryFactory() android.Module {
|
||||||
module, _ := NewPrebuiltLibrary(android.HostAndDeviceSupported)
|
module, _ := NewPrebuiltLibrary(android.HostAndDeviceSupported)
|
||||||
@@ -90,6 +93,8 @@ func (prebuilt *prebuiltLibraryDecorator) compilerProps() []interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (prebuilt *prebuiltLibraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path {
|
func (prebuilt *prebuiltLibraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path {
|
||||||
|
prebuilt.exportLinkDirs(android.PathsForModuleSrc(ctx, prebuilt.Properties.Link_dirs).Strings()...)
|
||||||
|
|
||||||
srcPath := srcPathFromModuleSrcs(ctx, prebuilt.prebuiltSrcs())
|
srcPath := srcPathFromModuleSrcs(ctx, prebuilt.prebuiltSrcs())
|
||||||
|
|
||||||
prebuilt.unstrippedOutputFile = srcPath
|
prebuilt.unstrippedOutputFile = srcPath
|
||||||
|
@@ -27,6 +27,7 @@ type ProcMacroCompilerProperties struct {
|
|||||||
|
|
||||||
type procMacroDecorator struct {
|
type procMacroDecorator struct {
|
||||||
*baseCompiler
|
*baseCompiler
|
||||||
|
*flagExporter
|
||||||
|
|
||||||
Properties ProcMacroCompilerProperties
|
Properties ProcMacroCompilerProperties
|
||||||
}
|
}
|
||||||
@@ -35,6 +36,7 @@ type procMacroInterface interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var _ compiler = (*procMacroDecorator)(nil)
|
var _ compiler = (*procMacroDecorator)(nil)
|
||||||
|
var _ exportedFlagsProducer = (*procMacroDecorator)(nil)
|
||||||
|
|
||||||
func ProcMacroFactory() android.Module {
|
func ProcMacroFactory() android.Module {
|
||||||
module, _ := NewProcMacro(android.HostSupportedNoCross)
|
module, _ := NewProcMacro(android.HostSupportedNoCross)
|
||||||
@@ -46,6 +48,7 @@ func NewProcMacro(hod android.HostOrDeviceSupported) (*Module, *procMacroDecorat
|
|||||||
|
|
||||||
procMacro := &procMacroDecorator{
|
procMacro := &procMacroDecorator{
|
||||||
baseCompiler: NewBaseCompiler("lib", "lib64", InstallInSystem),
|
baseCompiler: NewBaseCompiler("lib", "lib64", InstallInSystem),
|
||||||
|
flagExporter: NewFlagExporter(),
|
||||||
}
|
}
|
||||||
|
|
||||||
module.compiler = procMacro
|
module.compiler = procMacro
|
||||||
|
61
rust/rust.go
61
rust/rust.go
@@ -262,6 +262,43 @@ type compiler interface {
|
|||||||
nativeCoverage() bool
|
nativeCoverage() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type exportedFlagsProducer interface {
|
||||||
|
exportedLinkDirs() []string
|
||||||
|
exportedDepFlags() []string
|
||||||
|
exportLinkDirs(...string)
|
||||||
|
exportDepFlags(...string)
|
||||||
|
}
|
||||||
|
|
||||||
|
type flagExporter struct {
|
||||||
|
depFlags []string
|
||||||
|
linkDirs []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (flagExporter *flagExporter) exportedLinkDirs() []string {
|
||||||
|
return flagExporter.linkDirs
|
||||||
|
}
|
||||||
|
|
||||||
|
func (flagExporter *flagExporter) exportedDepFlags() []string {
|
||||||
|
return flagExporter.depFlags
|
||||||
|
}
|
||||||
|
|
||||||
|
func (flagExporter *flagExporter) exportLinkDirs(dirs ...string) {
|
||||||
|
flagExporter.linkDirs = android.FirstUniqueStrings(append(flagExporter.linkDirs, dirs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (flagExporter *flagExporter) exportDepFlags(flags ...string) {
|
||||||
|
flagExporter.depFlags = android.FirstUniqueStrings(append(flagExporter.depFlags, flags...))
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ exportedFlagsProducer = (*flagExporter)(nil)
|
||||||
|
|
||||||
|
func NewFlagExporter() *flagExporter {
|
||||||
|
return &flagExporter{
|
||||||
|
depFlags: []string{},
|
||||||
|
linkDirs: []string{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (mod *Module) isCoverageVariant() bool {
|
func (mod *Module) isCoverageVariant() bool {
|
||||||
return mod.coverage.Properties.IsCoverageVariant
|
return mod.coverage.Properties.IsCoverageVariant
|
||||||
}
|
}
|
||||||
@@ -416,7 +453,7 @@ func (mod *Module) Module() android.Module {
|
|||||||
func (mod *Module) StubsVersions() []string {
|
func (mod *Module) StubsVersions() []string {
|
||||||
// For now, Rust has no stubs versions.
|
// For now, Rust has no stubs versions.
|
||||||
if mod.compiler != nil {
|
if mod.compiler != nil {
|
||||||
if _, ok := mod.compiler.(*libraryDecorator); ok {
|
if _, ok := mod.compiler.(libraryInterface); ok {
|
||||||
return []string{}
|
return []string{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -708,19 +745,15 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Append the dependencies exportedDirs
|
//Append the dependencies exportedDirs
|
||||||
if lib, ok := rustDep.compiler.(*libraryDecorator); ok {
|
if lib, ok := rustDep.compiler.(exportedFlagsProducer); ok {
|
||||||
depPaths.linkDirs = append(depPaths.linkDirs, lib.exportedDirs()...)
|
depPaths.linkDirs = append(depPaths.linkDirs, lib.exportedLinkDirs()...)
|
||||||
depPaths.depFlags = append(depPaths.depFlags, lib.exportedDepFlags()...)
|
depPaths.depFlags = append(depPaths.depFlags, lib.exportedDepFlags()...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append this dependencies output to this mod's linkDirs so they can be exported to dependencies
|
|
||||||
// This can be probably be refactored by defining a common exporter interface similar to cc's
|
|
||||||
if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag {
|
if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag {
|
||||||
linkDir := linkPathFromFilePath(linkFile.Path())
|
linkDir := linkPathFromFilePath(linkFile.Path())
|
||||||
if lib, ok := mod.compiler.(*libraryDecorator); ok {
|
if lib, ok := mod.compiler.(exportedFlagsProducer); ok {
|
||||||
lib.linkDirs = append(lib.linkDirs, linkDir)
|
lib.exportLinkDirs(linkDir)
|
||||||
} else if procMacro, ok := mod.compiler.(*procMacroDecorator); ok {
|
|
||||||
procMacro.linkDirs = append(procMacro.linkDirs, linkDir)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -771,14 +804,10 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Make sure these dependencies are propagated
|
// Make sure these dependencies are propagated
|
||||||
if lib, ok := mod.compiler.(*libraryDecorator); ok && exportDep {
|
if lib, ok := mod.compiler.(exportedFlagsProducer); ok && exportDep {
|
||||||
lib.linkDirs = append(lib.linkDirs, linkPath)
|
lib.exportLinkDirs(linkPath)
|
||||||
lib.depFlags = append(lib.depFlags, depFlag)
|
lib.exportDepFlags(depFlag)
|
||||||
} else if procMacro, ok := mod.compiler.(*procMacroDecorator); ok && exportDep {
|
|
||||||
procMacro.linkDirs = append(procMacro.linkDirs, linkPath)
|
|
||||||
procMacro.depFlags = append(procMacro.depFlags, depFlag)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user