Merge changes I4efdf333,I4abaf8e7
* changes: Ensure hermetic device rust_bindgen. Generate deps file for rust_bindgen modules.
This commit is contained in:
@@ -86,7 +86,7 @@ func (binary *binaryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
|
|||||||
deps = binary.baseCompiler.compilerDeps(ctx, deps)
|
deps = binary.baseCompiler.compilerDeps(ctx, deps)
|
||||||
|
|
||||||
if ctx.toolchain().Bionic() {
|
if ctx.toolchain().Bionic() {
|
||||||
deps = binary.baseCompiler.bionicDeps(ctx, deps)
|
deps = bionicDeps(deps)
|
||||||
deps.CrtBegin = "crtbegin_dynamic"
|
deps.CrtBegin = "crtbegin_dynamic"
|
||||||
deps.CrtEnd = "crtend_android"
|
deps.CrtEnd = "crtend_android"
|
||||||
}
|
}
|
||||||
|
@@ -15,11 +15,11 @@
|
|||||||
package rust
|
package rust
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/blueprint"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/google/blueprint"
|
||||||
|
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
"android/soong/cc"
|
|
||||||
ccConfig "android/soong/cc/config"
|
ccConfig "android/soong/cc/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -41,8 +41,10 @@ var (
|
|||||||
bindgen = pctx.AndroidStaticRule("bindgen",
|
bindgen = pctx.AndroidStaticRule("bindgen",
|
||||||
blueprint.RuleParams{
|
blueprint.RuleParams{
|
||||||
Command: "CLANG_PATH=$bindgenClang LIBCLANG_PATH=$bindgenLibClang RUSTFMT=${config.RustBin}/rustfmt " +
|
Command: "CLANG_PATH=$bindgenClang LIBCLANG_PATH=$bindgenLibClang RUSTFMT=${config.RustBin}/rustfmt " +
|
||||||
"$bindgenCmd $flags $in -o $out -- $cflags",
|
"$bindgenCmd $flags $in -o $out -- -MD -MF $out.d $cflags",
|
||||||
CommandDeps: []string{"$bindgenCmd"},
|
CommandDeps: []string{"$bindgenCmd"},
|
||||||
|
Deps: blueprint.DepsGCC,
|
||||||
|
Depfile: "$out.d",
|
||||||
},
|
},
|
||||||
"flags", "cflags")
|
"flags", "cflags")
|
||||||
)
|
)
|
||||||
@@ -83,40 +85,39 @@ type bindgenDecorator struct {
|
|||||||
Properties BindgenProperties
|
Properties BindgenProperties
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *bindgenDecorator) libraryExports(ctx android.ModuleContext) (android.Paths, []string) {
|
func (b *bindgenDecorator) generateSource(ctx android.ModuleContext, deps PathDeps) android.Path {
|
||||||
var libraryPaths android.Paths
|
|
||||||
var libraryFlags []string
|
|
||||||
|
|
||||||
for _, static_lib := range b.Properties.Static_libs {
|
|
||||||
if dep, ok := ctx.GetDirectDepWithTag(static_lib, cc.StaticDepTag).(*cc.Module); ok {
|
|
||||||
libraryPaths = append(libraryPaths, dep.ExportedIncludeDirs()...)
|
|
||||||
libraryFlags = append(libraryFlags, dep.ExportedFlags()...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, shared_lib := range b.Properties.Shared_libs {
|
|
||||||
if dep, ok := ctx.GetDirectDepWithTag(shared_lib, cc.SharedDepTag).(*cc.Module); ok {
|
|
||||||
libraryPaths = append(libraryPaths, dep.ExportedIncludeDirs()...)
|
|
||||||
libraryFlags = append(libraryFlags, dep.ExportedFlags()...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return libraryPaths, libraryFlags
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *bindgenDecorator) generateSource(ctx android.ModuleContext) android.Path {
|
|
||||||
ccToolchain := ccConfig.FindToolchain(ctx.Os(), ctx.Arch())
|
ccToolchain := ccConfig.FindToolchain(ctx.Os(), ctx.Arch())
|
||||||
includes, exportedFlags := b.libraryExports(ctx)
|
|
||||||
|
|
||||||
var cflags []string
|
var cflags []string
|
||||||
cflags = append(cflags, b.Properties.Cflags...)
|
var implicits android.Paths
|
||||||
|
|
||||||
|
implicits = append(implicits, deps.depIncludePaths...)
|
||||||
|
implicits = append(implicits, deps.depSystemIncludePaths...)
|
||||||
|
|
||||||
|
// Default clang flags
|
||||||
|
cflags = append(cflags, "${ccConfig.CommonClangGlobalCflags}")
|
||||||
|
if ctx.Device() {
|
||||||
|
cflags = append(cflags, "${ccConfig.DeviceClangGlobalCflags}")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Toolchain clang flags
|
||||||
cflags = append(cflags, "-target "+ccToolchain.ClangTriple())
|
cflags = append(cflags, "-target "+ccToolchain.ClangTriple())
|
||||||
cflags = append(cflags, strings.ReplaceAll(ccToolchain.ToolchainClangCflags(), "${config.", "${ccConfig."))
|
cflags = append(cflags, strings.ReplaceAll(ccToolchain.ToolchainClangCflags(), "${config.", "${ccConfig."))
|
||||||
cflags = append(cflags, exportedFlags...)
|
|
||||||
for _, include := range includes {
|
// Dependency clang flags and include paths
|
||||||
|
cflags = append(cflags, deps.depClangFlags...)
|
||||||
|
for _, include := range deps.depIncludePaths {
|
||||||
cflags = append(cflags, "-I"+include.String())
|
cflags = append(cflags, "-I"+include.String())
|
||||||
}
|
}
|
||||||
|
for _, include := range deps.depSystemIncludePaths {
|
||||||
|
cflags = append(cflags, "-isystem "+include.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Module defined clang flags and include paths
|
||||||
|
cflags = append(cflags, b.Properties.Cflags...)
|
||||||
for _, include := range b.Properties.Local_include_dirs {
|
for _, include := range b.Properties.Local_include_dirs {
|
||||||
cflags = append(cflags, "-I"+android.PathForModuleSrc(ctx, include).String())
|
cflags = append(cflags, "-I"+android.PathForModuleSrc(ctx, include).String())
|
||||||
|
implicits = append(implicits, android.PathForModuleSrc(ctx, include))
|
||||||
}
|
}
|
||||||
|
|
||||||
bindgenFlags := defaultBindgenFlags
|
bindgenFlags := defaultBindgenFlags
|
||||||
@@ -134,7 +135,7 @@ func (b *bindgenDecorator) generateSource(ctx android.ModuleContext) android.Pat
|
|||||||
Description: "bindgen " + wrapperFile.Path().Rel(),
|
Description: "bindgen " + wrapperFile.Path().Rel(),
|
||||||
Output: outputFile,
|
Output: outputFile,
|
||||||
Input: wrapperFile.Path(),
|
Input: wrapperFile.Path(),
|
||||||
Implicits: includes,
|
Implicits: implicits,
|
||||||
Args: map[string]string{
|
Args: map[string]string{
|
||||||
"flags": strings.Join(bindgenFlags, " "),
|
"flags": strings.Join(bindgenFlags, " "),
|
||||||
"cflags": strings.Join(cflags, " "),
|
"cflags": strings.Join(cflags, " "),
|
||||||
@@ -176,6 +177,10 @@ func NewRustBindgen(hod android.HostOrDeviceSupported) (*Module, *bindgenDecorat
|
|||||||
|
|
||||||
func (b *bindgenDecorator) sourceProviderDeps(ctx DepsContext, deps Deps) Deps {
|
func (b *bindgenDecorator) sourceProviderDeps(ctx DepsContext, deps Deps) Deps {
|
||||||
deps = b.baseSourceProvider.sourceProviderDeps(ctx, deps)
|
deps = b.baseSourceProvider.sourceProviderDeps(ctx, deps)
|
||||||
|
if ctx.toolchain().Bionic() {
|
||||||
|
deps = bionicDeps(deps)
|
||||||
|
}
|
||||||
|
|
||||||
deps.SharedLibs = append(deps.SharedLibs, b.Properties.Shared_libs...)
|
deps.SharedLibs = append(deps.SharedLibs, b.Properties.Shared_libs...)
|
||||||
deps.StaticLibs = append(deps.StaticLibs, b.Properties.Static_libs...)
|
deps.StaticLibs = append(deps.StaticLibs, b.Properties.Static_libs...)
|
||||||
return deps
|
return deps
|
||||||
|
@@ -48,9 +48,9 @@ func TestRustBindgen(t *testing.T) {
|
|||||||
t.Errorf("missing clang cflags in rust_bindgen rule: cflags %#v", libbindgen.Args["cflags"])
|
t.Errorf("missing clang cflags in rust_bindgen rule: cflags %#v", libbindgen.Args["cflags"])
|
||||||
}
|
}
|
||||||
if !strings.Contains(libbindgen.Args["cflags"], "-Ishared_include") {
|
if !strings.Contains(libbindgen.Args["cflags"], "-Ishared_include") {
|
||||||
t.Errorf("missing clang cflags in rust_bindgen rule: cflags %#v", libbindgen.Args["cflags"])
|
t.Errorf("missing shared_libs exported includes in rust_bindgen rule: cflags %#v", libbindgen.Args["cflags"])
|
||||||
}
|
}
|
||||||
if !strings.Contains(libbindgen.Args["cflags"], "-Istatic_include") {
|
if !strings.Contains(libbindgen.Args["cflags"], "-Istatic_include") {
|
||||||
t.Errorf("missing clang cflags in rust_bindgen rule: cflags %#v", libbindgen.Args["cflags"])
|
t.Errorf("missing static_libs exported includes in rust_bindgen rule: cflags %#v", libbindgen.Args["cflags"])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -199,7 +199,7 @@ func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps {
|
|||||||
return deps
|
return deps
|
||||||
}
|
}
|
||||||
|
|
||||||
func (compiler *baseCompiler) bionicDeps(ctx DepsContext, deps Deps) Deps {
|
func bionicDeps(deps Deps) Deps {
|
||||||
deps.SharedLibs = append(deps.SharedLibs, "liblog")
|
deps.SharedLibs = append(deps.SharedLibs, "liblog")
|
||||||
deps.SharedLibs = append(deps.SharedLibs, "libc")
|
deps.SharedLibs = append(deps.SharedLibs, "libc")
|
||||||
deps.SharedLibs = append(deps.SharedLibs, "libm")
|
deps.SharedLibs = append(deps.SharedLibs, "libm")
|
||||||
|
@@ -340,7 +340,7 @@ func (library *libraryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
|
|||||||
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()) {
|
||||||
deps = library.baseCompiler.bionicDeps(ctx, deps)
|
deps = bionicDeps(deps)
|
||||||
deps.CrtBegin = "crtbegin_so"
|
deps.CrtBegin = "crtbegin_so"
|
||||||
deps.CrtEnd = "crtend_so"
|
deps.CrtEnd = "crtend_so"
|
||||||
}
|
}
|
||||||
|
20
rust/rust.go
20
rust/rust.go
@@ -256,6 +256,11 @@ type PathDeps struct {
|
|||||||
depFlags []string
|
depFlags []string
|
||||||
//ReexportedDeps android.Paths
|
//ReexportedDeps android.Paths
|
||||||
|
|
||||||
|
// Used by bindgen modules which call clang
|
||||||
|
depClangFlags []string
|
||||||
|
depIncludePaths android.Paths
|
||||||
|
depSystemIncludePaths android.Paths
|
||||||
|
|
||||||
coverageFiles android.Paths
|
coverageFiles android.Paths
|
||||||
|
|
||||||
CrtBegin android.OptionalPath
|
CrtBegin android.OptionalPath
|
||||||
@@ -671,7 +676,7 @@ func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
|
|||||||
mod.compiler.install(ctx, mod.outputFile.Path())
|
mod.compiler.install(ctx, mod.outputFile.Path())
|
||||||
}
|
}
|
||||||
} else if mod.sourceProvider != nil {
|
} else if mod.sourceProvider != nil {
|
||||||
outputFile := mod.sourceProvider.generateSource(ctx)
|
outputFile := mod.sourceProvider.generateSource(ctx, deps)
|
||||||
mod.outputFile = android.OptionalPathForPath(outputFile)
|
mod.outputFile = android.OptionalPathForPath(outputFile)
|
||||||
mod.subName = ctx.ModuleSubDir()
|
mod.subName = ctx.ModuleSubDir()
|
||||||
}
|
}
|
||||||
@@ -849,6 +854,11 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
|||||||
depFlag = "-lstatic=" + libName
|
depFlag = "-lstatic=" + libName
|
||||||
depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
|
depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
|
||||||
depPaths.depFlags = append(depPaths.depFlags, depFlag)
|
depPaths.depFlags = append(depPaths.depFlags, depFlag)
|
||||||
|
depPaths.depIncludePaths = append(depPaths.depIncludePaths, ccDep.IncludeDirs()...)
|
||||||
|
if mod, ok := ccDep.(*cc.Module); ok {
|
||||||
|
depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, mod.ExportedSystemIncludeDirs()...)
|
||||||
|
depPaths.depClangFlags = append(depPaths.depClangFlags, mod.ExportedFlags()...)
|
||||||
|
}
|
||||||
depPaths.coverageFiles = append(depPaths.coverageFiles, ccDep.CoverageFiles()...)
|
depPaths.coverageFiles = append(depPaths.coverageFiles, ccDep.CoverageFiles()...)
|
||||||
directStaticLibDeps = append(directStaticLibDeps, ccDep)
|
directStaticLibDeps = append(directStaticLibDeps, ccDep)
|
||||||
mod.Properties.AndroidMkStaticLibs = append(mod.Properties.AndroidMkStaticLibs, depName)
|
mod.Properties.AndroidMkStaticLibs = append(mod.Properties.AndroidMkStaticLibs, depName)
|
||||||
@@ -856,6 +866,11 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
|||||||
depFlag = "-ldylib=" + libName
|
depFlag = "-ldylib=" + libName
|
||||||
depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
|
depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
|
||||||
depPaths.depFlags = append(depPaths.depFlags, depFlag)
|
depPaths.depFlags = append(depPaths.depFlags, depFlag)
|
||||||
|
depPaths.depIncludePaths = append(depPaths.depIncludePaths, ccDep.IncludeDirs()...)
|
||||||
|
if mod, ok := ccDep.(*cc.Module); ok {
|
||||||
|
depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, mod.ExportedSystemIncludeDirs()...)
|
||||||
|
depPaths.depClangFlags = append(depPaths.depClangFlags, mod.ExportedFlags()...)
|
||||||
|
}
|
||||||
directSharedLibDeps = append(directSharedLibDeps, ccDep)
|
directSharedLibDeps = append(directSharedLibDeps, ccDep)
|
||||||
mod.Properties.AndroidMkSharedLibs = append(mod.Properties.AndroidMkSharedLibs, depName)
|
mod.Properties.AndroidMkSharedLibs = append(mod.Properties.AndroidMkSharedLibs, depName)
|
||||||
exportDep = true
|
exportDep = true
|
||||||
@@ -916,6 +931,9 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
|||||||
// Dedup exported flags from dependencies
|
// Dedup exported flags from dependencies
|
||||||
depPaths.linkDirs = android.FirstUniqueStrings(depPaths.linkDirs)
|
depPaths.linkDirs = android.FirstUniqueStrings(depPaths.linkDirs)
|
||||||
depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags)
|
depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags)
|
||||||
|
depPaths.depClangFlags = android.FirstUniqueStrings(depPaths.depClangFlags)
|
||||||
|
depPaths.depIncludePaths = android.FirstUniquePaths(depPaths.depIncludePaths)
|
||||||
|
depPaths.depSystemIncludePaths = android.FirstUniquePaths(depPaths.depSystemIncludePaths)
|
||||||
|
|
||||||
return depPaths
|
return depPaths
|
||||||
}
|
}
|
||||||
|
@@ -33,7 +33,7 @@ type baseSourceProvider struct {
|
|||||||
var _ SourceProvider = (*baseSourceProvider)(nil)
|
var _ SourceProvider = (*baseSourceProvider)(nil)
|
||||||
|
|
||||||
type SourceProvider interface {
|
type SourceProvider interface {
|
||||||
generateSource(ctx android.ModuleContext) android.Path
|
generateSource(ctx android.ModuleContext, deps PathDeps) android.Path
|
||||||
Srcs() android.Paths
|
Srcs() android.Paths
|
||||||
sourceProviderProps() []interface{}
|
sourceProviderProps() []interface{}
|
||||||
sourceProviderDeps(ctx DepsContext, deps Deps) Deps
|
sourceProviderDeps(ctx DepsContext, deps Deps) Deps
|
||||||
@@ -43,7 +43,7 @@ func (sp *baseSourceProvider) Srcs() android.Paths {
|
|||||||
return android.Paths{sp.outputFile}
|
return android.Paths{sp.outputFile}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sp *baseSourceProvider) generateSource(ctx android.ModuleContext) android.Path {
|
func (sp *baseSourceProvider) generateSource(ctx android.ModuleContext, deps PathDeps) android.Path {
|
||||||
panic("baseSourceProviderModule does not implement generateSource()")
|
panic("baseSourceProviderModule does not implement generateSource()")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user