rust: refactored transformSrctoCrate
Refactor transformSrctoCrate and the functions it calls to not rely on rust.ModuleContext, preparing it to be callable from soong-cc context to build a Rust staticlib. This also refactors out common default flags used when building libraries, again to prepare for building a Rust staticlib from a soong-cc context. Bug: 254469782 Test: m blueprint_tests && m Change-Id: I678f6fee989c61bb15c340b9887e4d1934991907
This commit is contained in:
110
rust/builder.go
110
rust/builder.go
@@ -120,40 +120,74 @@ func init() {
|
|||||||
pctx.HostBinToolVariable("SoongZipCmd", "soong_zip")
|
pctx.HostBinToolVariable("SoongZipCmd", "soong_zip")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type transformProperties struct {
|
||||||
|
crateName string
|
||||||
|
targetTriple string
|
||||||
|
is64Bit bool
|
||||||
|
bootstrap bool
|
||||||
|
inRecovery bool
|
||||||
|
inRamdisk bool
|
||||||
|
inVendorRamdisk bool
|
||||||
|
cargoOutDir android.OptionalPath
|
||||||
|
synthetic bool
|
||||||
|
crateType string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Populates a standard transformProperties struct for Rust modules
|
||||||
|
func getTransformProperties(ctx ModuleContext, crateType string) transformProperties {
|
||||||
|
module := ctx.RustModule()
|
||||||
|
return transformProperties{
|
||||||
|
crateName: module.CrateName(),
|
||||||
|
is64Bit: ctx.toolchain().Is64Bit(),
|
||||||
|
targetTriple: ctx.toolchain().RustTriple(),
|
||||||
|
bootstrap: module.Bootstrap(),
|
||||||
|
inRecovery: module.InRecovery(),
|
||||||
|
inRamdisk: module.InRamdisk(),
|
||||||
|
inVendorRamdisk: module.InVendorRamdisk(),
|
||||||
|
cargoOutDir: module.compiler.cargoOutDir(),
|
||||||
|
|
||||||
|
// crateType indicates what type of crate to build
|
||||||
|
crateType: crateType,
|
||||||
|
|
||||||
|
// synthetic indicates whether this is an actual Rust module or not
|
||||||
|
synthetic: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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) buildOutput {
|
outputFile android.WritablePath) buildOutput {
|
||||||
flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
|
flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
|
||||||
|
|
||||||
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "bin")
|
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, getTransformProperties(ctx, "bin"))
|
||||||
}
|
}
|
||||||
|
|
||||||
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) buildOutput {
|
outputFile android.WritablePath) buildOutput {
|
||||||
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "rlib")
|
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, getTransformProperties(ctx, "rlib"))
|
||||||
}
|
}
|
||||||
|
|
||||||
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) buildOutput {
|
outputFile android.WritablePath) buildOutput {
|
||||||
flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
|
flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
|
||||||
|
|
||||||
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "dylib")
|
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, getTransformProperties(ctx, "dylib"))
|
||||||
}
|
}
|
||||||
|
|
||||||
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) buildOutput {
|
outputFile android.WritablePath) buildOutput {
|
||||||
flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
|
flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
|
||||||
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "staticlib")
|
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, getTransformProperties(ctx, "staticlib"))
|
||||||
}
|
}
|
||||||
|
|
||||||
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) buildOutput {
|
outputFile android.WritablePath) buildOutput {
|
||||||
flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
|
flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
|
||||||
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "cdylib")
|
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, getTransformProperties(ctx, "cdylib"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TransformSrctoProcMacro(ctx ModuleContext, mainSrc android.Path, deps PathDeps,
|
func TransformSrctoProcMacro(ctx ModuleContext, mainSrc android.Path, deps PathDeps,
|
||||||
flags Flags, outputFile android.WritablePath) buildOutput {
|
flags Flags, outputFile android.WritablePath) buildOutput {
|
||||||
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "proc-macro")
|
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, getTransformProperties(ctx, "proc-macro"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func rustLibsToPaths(libs RustLibraries) android.Paths {
|
func rustLibsToPaths(libs RustLibraries) android.Paths {
|
||||||
@@ -185,18 +219,18 @@ func makeLibFlags(deps PathDeps) []string {
|
|||||||
return libFlags
|
return libFlags
|
||||||
}
|
}
|
||||||
|
|
||||||
func rustEnvVars(ctx ModuleContext, deps PathDeps) []string {
|
func rustEnvVars(ctx android.ModuleContext, deps PathDeps, crateName string, cargoOutDir android.OptionalPath) []string {
|
||||||
var envVars []string
|
var envVars []string
|
||||||
|
|
||||||
// libstd requires a specific environment variable to be set. This is
|
// libstd requires a specific environment variable to be set. This is
|
||||||
// not officially documented and may be removed in the future. See
|
// not officially documented and may be removed in the future. See
|
||||||
// https://github.com/rust-lang/rust/blob/master/library/std/src/env.rs#L866.
|
// https://github.com/rust-lang/rust/blob/master/library/std/src/env.rs#L866.
|
||||||
if ctx.RustModule().CrateName() == "std" {
|
if crateName == "std" {
|
||||||
envVars = append(envVars, "STD_ENV_ARCH="+config.StdEnvArch[ctx.RustModule().Arch().ArchType])
|
envVars = append(envVars, "STD_ENV_ARCH="+config.StdEnvArch[ctx.Arch().ArchType])
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(deps.SrcDeps) > 0 {
|
if len(deps.SrcDeps) > 0 && cargoOutDir.Valid() {
|
||||||
moduleGenDir := ctx.RustModule().compiler.cargoOutDir()
|
moduleGenDir := cargoOutDir
|
||||||
// We must calculate an absolute path for OUT_DIR since Rust's include! macro (which normally consumes this)
|
// We must calculate an absolute path for OUT_DIR since Rust's include! macro (which normally consumes this)
|
||||||
// assumes that paths are relative to the source file.
|
// assumes that paths are relative to the source file.
|
||||||
var outDirPrefix string
|
var outDirPrefix string
|
||||||
@@ -215,13 +249,15 @@ func rustEnvVars(ctx ModuleContext, deps PathDeps) []string {
|
|||||||
|
|
||||||
envVars = append(envVars, "ANDROID_RUST_VERSION="+config.GetRustVersion(ctx))
|
envVars = append(envVars, "ANDROID_RUST_VERSION="+config.GetRustVersion(ctx))
|
||||||
|
|
||||||
if ctx.RustModule().compiler.cargoEnvCompat() {
|
if rustMod, ok := ctx.Module().(*Module); ok && rustMod.compiler.cargoEnvCompat() {
|
||||||
if bin, ok := ctx.RustModule().compiler.(*binaryDecorator); ok {
|
// We only emulate cargo environment variables for 3p code, which is only ever built
|
||||||
|
// by defining a Rust module, so we only need to set these for true Rust modules.
|
||||||
|
if bin, ok := rustMod.compiler.(*binaryDecorator); ok {
|
||||||
envVars = append(envVars, "CARGO_BIN_NAME="+bin.getStem(ctx))
|
envVars = append(envVars, "CARGO_BIN_NAME="+bin.getStem(ctx))
|
||||||
}
|
}
|
||||||
envVars = append(envVars, "CARGO_CRATE_NAME="+ctx.RustModule().CrateName())
|
envVars = append(envVars, "CARGO_CRATE_NAME="+crateName)
|
||||||
envVars = append(envVars, "CARGO_PKG_NAME="+ctx.RustModule().CrateName())
|
envVars = append(envVars, "CARGO_PKG_NAME="+crateName)
|
||||||
pkgVersion := ctx.RustModule().compiler.cargoPkgVersion()
|
pkgVersion := rustMod.compiler.cargoPkgVersion()
|
||||||
if pkgVersion != "" {
|
if pkgVersion != "" {
|
||||||
envVars = append(envVars, "CARGO_PKG_VERSION="+pkgVersion)
|
envVars = append(envVars, "CARGO_PKG_VERSION="+pkgVersion)
|
||||||
|
|
||||||
@@ -245,8 +281,8 @@ func rustEnvVars(ctx ModuleContext, deps PathDeps) []string {
|
|||||||
return envVars
|
return envVars
|
||||||
}
|
}
|
||||||
|
|
||||||
func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, flags Flags,
|
func transformSrctoCrate(ctx android.ModuleContext, main android.Path, deps PathDeps, flags Flags,
|
||||||
outputFile android.WritablePath, crateType string) buildOutput {
|
outputFile android.WritablePath, t transformProperties) buildOutput {
|
||||||
|
|
||||||
var inputs android.Paths
|
var inputs android.Paths
|
||||||
var implicits android.Paths
|
var implicits android.Paths
|
||||||
@@ -256,23 +292,21 @@ func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, fl
|
|||||||
var earlyLinkFlags string
|
var earlyLinkFlags string
|
||||||
|
|
||||||
output.outputFile = outputFile
|
output.outputFile = outputFile
|
||||||
crateName := ctx.RustModule().CrateName()
|
|
||||||
targetTriple := ctx.toolchain().RustTriple()
|
|
||||||
|
|
||||||
envVars := rustEnvVars(ctx, deps)
|
envVars := rustEnvVars(ctx, deps, t.crateName, t.cargoOutDir)
|
||||||
|
|
||||||
inputs = append(inputs, main)
|
inputs = append(inputs, main)
|
||||||
|
|
||||||
// Collect rustc flags
|
// Collect rustc flags
|
||||||
rustcFlags = append(rustcFlags, flags.GlobalRustFlags...)
|
rustcFlags = append(rustcFlags, flags.GlobalRustFlags...)
|
||||||
rustcFlags = append(rustcFlags, flags.RustFlags...)
|
rustcFlags = append(rustcFlags, flags.RustFlags...)
|
||||||
rustcFlags = append(rustcFlags, "--crate-type="+crateType)
|
rustcFlags = append(rustcFlags, "--crate-type="+t.crateType)
|
||||||
if crateName != "" {
|
if t.crateName != "" {
|
||||||
rustcFlags = append(rustcFlags, "--crate-name="+crateName)
|
rustcFlags = append(rustcFlags, "--crate-name="+t.crateName)
|
||||||
}
|
}
|
||||||
if targetTriple != "" {
|
if t.targetTriple != "" {
|
||||||
rustcFlags = append(rustcFlags, "--target="+targetTriple)
|
rustcFlags = append(rustcFlags, "--target="+t.targetTriple)
|
||||||
linkFlags = append(linkFlags, "-target "+targetTriple)
|
linkFlags = append(linkFlags, "-target "+t.targetTriple)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Suppress an implicit sysroot
|
// Suppress an implicit sysroot
|
||||||
@@ -302,9 +336,9 @@ func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, fl
|
|||||||
linkFlags = append(linkFlags, flags.LinkFlags...)
|
linkFlags = append(linkFlags, flags.LinkFlags...)
|
||||||
|
|
||||||
// Check if this module needs to use the bootstrap linker
|
// Check if this module needs to use the bootstrap linker
|
||||||
if ctx.RustModule().Bootstrap() && !ctx.RustModule().InRecovery() && !ctx.RustModule().InRamdisk() && !ctx.RustModule().InVendorRamdisk() {
|
if t.bootstrap && !t.inRecovery && !t.inRamdisk && !t.inVendorRamdisk {
|
||||||
dynamicLinker := "-Wl,-dynamic-linker,/system/bin/bootstrap/linker"
|
dynamicLinker := "-Wl,-dynamic-linker,/system/bin/bootstrap/linker"
|
||||||
if ctx.toolchain().Is64Bit() {
|
if t.is64Bit {
|
||||||
dynamicLinker += "64"
|
dynamicLinker += "64"
|
||||||
}
|
}
|
||||||
linkFlags = append(linkFlags, dynamicLinker)
|
linkFlags = append(linkFlags, dynamicLinker)
|
||||||
@@ -326,8 +360,10 @@ func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, fl
|
|||||||
|
|
||||||
orderOnly = append(orderOnly, deps.SharedLibs...)
|
orderOnly = append(orderOnly, deps.SharedLibs...)
|
||||||
|
|
||||||
|
if !t.synthetic {
|
||||||
|
// Only worry about OUT_DIR for actual Rust modules.
|
||||||
|
// Libraries built from cc use generated source, and do not utilize OUT_DIR.
|
||||||
if len(deps.SrcDeps) > 0 {
|
if len(deps.SrcDeps) > 0 {
|
||||||
moduleGenDir := ctx.RustModule().compiler.cargoOutDir()
|
|
||||||
var outputs android.WritablePaths
|
var outputs android.WritablePaths
|
||||||
|
|
||||||
for _, genSrc := range deps.SrcDeps {
|
for _, genSrc := range deps.SrcDeps {
|
||||||
@@ -340,16 +376,20 @@ func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, fl
|
|||||||
|
|
||||||
ctx.Build(pctx, android.BuildParams{
|
ctx.Build(pctx, android.BuildParams{
|
||||||
Rule: cp,
|
Rule: cp,
|
||||||
Description: "cp " + moduleGenDir.Path().Rel(),
|
Description: "cp " + t.cargoOutDir.Path().Rel(),
|
||||||
Outputs: outputs,
|
Outputs: outputs,
|
||||||
Inputs: deps.SrcDeps,
|
Inputs: deps.SrcDeps,
|
||||||
Args: map[string]string{
|
Args: map[string]string{
|
||||||
"outDir": moduleGenDir.String(),
|
"outDir": t.cargoOutDir.String(),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
implicits = append(implicits, outputs.Paths()...)
|
implicits = append(implicits, outputs.Paths()...)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !t.synthetic {
|
||||||
|
// Only worry about clippy for actual Rust modules.
|
||||||
|
// Libraries built from cc use generated source, and don't need to run clippy.
|
||||||
if flags.Clippy {
|
if flags.Clippy {
|
||||||
clippyFile := android.PathForModuleOut(ctx, outputFile.Base()+".clippy")
|
clippyFile := android.PathForModuleOut(ctx, outputFile.Base()+".clippy")
|
||||||
ctx.Build(pctx, android.BuildParams{
|
ctx.Build(pctx, android.BuildParams{
|
||||||
@@ -370,6 +410,7 @@ func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, fl
|
|||||||
// Declare the clippy build as an implicit dependency of the original crate.
|
// Declare the clippy build as an implicit dependency of the original crate.
|
||||||
implicits = append(implicits, clippyFile)
|
implicits = append(implicits, clippyFile)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ctx.Build(pctx, android.BuildParams{
|
ctx.Build(pctx, android.BuildParams{
|
||||||
Rule: rustc,
|
Rule: rustc,
|
||||||
@@ -389,6 +430,8 @@ func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, fl
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if !t.synthetic {
|
||||||
|
// Only emit xrefs for true Rust modules.
|
||||||
if flags.EmitXrefs {
|
if flags.EmitXrefs {
|
||||||
kytheFile := android.PathForModuleOut(ctx, outputFile.Base()+".kzip")
|
kytheFile := android.PathForModuleOut(ctx, outputFile.Base()+".kzip")
|
||||||
ctx.Build(pctx, android.BuildParams{
|
ctx.Build(pctx, android.BuildParams{
|
||||||
@@ -409,6 +452,7 @@ func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, fl
|
|||||||
})
|
})
|
||||||
output.kytheFile = kytheFile
|
output.kytheFile = kytheFile
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -457,7 +501,7 @@ func Rustdoc(ctx ModuleContext, main android.Path, deps PathDeps,
|
|||||||
Args: map[string]string{
|
Args: map[string]string{
|
||||||
"rustdocFlags": strings.Join(rustdocFlags, " "),
|
"rustdocFlags": strings.Join(rustdocFlags, " "),
|
||||||
"outDir": docDir.String(),
|
"outDir": docDir.String(),
|
||||||
"envVars": strings.Join(rustEnvVars(ctx, deps), " "),
|
"envVars": strings.Join(rustEnvVars(ctx, deps, crateName, ctx.RustModule().compiler.cargoOutDir()), " "),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -322,9 +322,9 @@ func (compiler *baseCompiler) compilerProps() []interface{} {
|
|||||||
return []interface{}{&compiler.Properties}
|
return []interface{}{&compiler.Properties}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (compiler *baseCompiler) cfgsToFlags() []string {
|
func cfgsToFlags(cfgs []string) []string {
|
||||||
flags := []string{}
|
flags := []string{}
|
||||||
for _, cfg := range compiler.Properties.Cfgs {
|
for _, cfg := range cfgs {
|
||||||
flags = append(flags, "--cfg '"+cfg+"'")
|
flags = append(flags, "--cfg '"+cfg+"'")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -351,23 +351,61 @@ func (compiler *baseCompiler) featureFlags(ctx ModuleContext, flags Flags) Flags
|
|||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
|
|
||||||
func (compiler *baseCompiler) cfgFlags(ctx ModuleContext, flags Flags) Flags {
|
func CommonDefaultCfgFlags(flags Flags, vendor bool, product bool) Flags {
|
||||||
if ctx.RustModule().InVendorOrProduct() {
|
var cfgs []string
|
||||||
compiler.Properties.Cfgs = append(compiler.Properties.Cfgs, "android_vndk")
|
if vendor || product {
|
||||||
if ctx.RustModule().InVendor() {
|
cfgs = append(cfgs, "android_vndk")
|
||||||
compiler.Properties.Cfgs = append(compiler.Properties.Cfgs, "android_vendor")
|
if vendor {
|
||||||
} else if ctx.RustModule().InProduct() {
|
cfgs = append(cfgs, "android_vendor")
|
||||||
compiler.Properties.Cfgs = append(compiler.Properties.Cfgs, "android_product")
|
} else if product {
|
||||||
|
cfgs = append(cfgs, "android_product")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
flags.RustFlags = append(flags.RustFlags, compiler.cfgsToFlags()...)
|
flags.RustFlags = append(flags.RustFlags, cfgsToFlags(cfgs)...)
|
||||||
flags.RustdocFlags = append(flags.RustdocFlags, compiler.cfgsToFlags()...)
|
flags.RustdocFlags = append(flags.RustdocFlags, cfgsToFlags(cfgs)...)
|
||||||
|
return flags
|
||||||
|
}
|
||||||
|
|
||||||
|
func (compiler *baseCompiler) cfgFlags(ctx ModuleContext, flags Flags) Flags {
|
||||||
|
flags = CommonDefaultCfgFlags(flags, ctx.RustModule().InVendor(), ctx.RustModule().InProduct())
|
||||||
|
|
||||||
|
flags.RustFlags = append(flags.RustFlags, cfgsToFlags(compiler.Properties.Cfgs)...)
|
||||||
|
flags.RustdocFlags = append(flags.RustdocFlags, cfgsToFlags(compiler.Properties.Cfgs)...)
|
||||||
|
|
||||||
|
return flags
|
||||||
|
}
|
||||||
|
|
||||||
|
func CommonDefaultFlags(ctx android.ModuleContext, toolchain config.Toolchain, flags Flags) Flags {
|
||||||
|
flags.GlobalRustFlags = append(flags.GlobalRustFlags, config.GlobalRustFlags...)
|
||||||
|
flags.GlobalRustFlags = append(flags.GlobalRustFlags, toolchain.ToolchainRustFlags())
|
||||||
|
flags.GlobalLinkFlags = append(flags.GlobalLinkFlags, toolchain.ToolchainLinkFlags())
|
||||||
|
flags.EmitXrefs = ctx.Config().EmitXrefRules()
|
||||||
|
|
||||||
|
if ctx.Host() && !ctx.Windows() {
|
||||||
|
flags.LinkFlags = append(flags.LinkFlags, cc.RpathFlags(ctx)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
if ctx.Os() == android.Linux {
|
||||||
|
// Add -lc, -lrt, -ldl, -lpthread, -lm and -lgcc_s to glibc builds to match
|
||||||
|
// the default behavior of device builds.
|
||||||
|
flags.LinkFlags = append(flags.LinkFlags, config.LinuxHostGlobalLinkFlags...)
|
||||||
|
} else if ctx.Os() == android.Darwin {
|
||||||
|
// Add -lc, -ldl, -lpthread and -lm to glibc darwin builds to match the default
|
||||||
|
// behavior of device builds.
|
||||||
|
flags.LinkFlags = append(flags.LinkFlags,
|
||||||
|
"-lc",
|
||||||
|
"-ldl",
|
||||||
|
"-lpthread",
|
||||||
|
"-lm",
|
||||||
|
)
|
||||||
|
}
|
||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
|
|
||||||
func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flags {
|
func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flags {
|
||||||
|
|
||||||
|
flags = CommonDefaultFlags(ctx, ctx.toolchain(), flags)
|
||||||
lintFlags, err := config.RustcLintsForDir(ctx.ModuleDir(), compiler.Properties.Lints)
|
lintFlags, err := config.RustcLintsForDir(ctx.ModuleDir(), compiler.Properties.Lints)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.PropertyErrorf("lints", err.Error())
|
ctx.PropertyErrorf("lints", err.Error())
|
||||||
@@ -396,29 +434,7 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flag
|
|||||||
flags.RustFlags = append(flags.RustFlags, "--edition="+compiler.edition())
|
flags.RustFlags = append(flags.RustFlags, "--edition="+compiler.edition())
|
||||||
flags.RustdocFlags = append(flags.RustdocFlags, "--edition="+compiler.edition())
|
flags.RustdocFlags = append(flags.RustdocFlags, "--edition="+compiler.edition())
|
||||||
flags.LinkFlags = append(flags.LinkFlags, compiler.Properties.Ld_flags...)
|
flags.LinkFlags = append(flags.LinkFlags, compiler.Properties.Ld_flags...)
|
||||||
flags.GlobalRustFlags = append(flags.GlobalRustFlags, config.GlobalRustFlags...)
|
|
||||||
flags.GlobalRustFlags = append(flags.GlobalRustFlags, ctx.toolchain().ToolchainRustFlags())
|
|
||||||
flags.GlobalLinkFlags = append(flags.GlobalLinkFlags, ctx.toolchain().ToolchainLinkFlags())
|
|
||||||
flags.EmitXrefs = ctx.Config().EmitXrefRules()
|
|
||||||
|
|
||||||
if ctx.Host() && !ctx.Windows() {
|
|
||||||
flags.LinkFlags = append(flags.LinkFlags, cc.RpathFlags(ctx)...)
|
|
||||||
}
|
|
||||||
|
|
||||||
if ctx.Os() == android.Linux {
|
|
||||||
// Add -lc, -lrt, -ldl, -lpthread, -lm and -lgcc_s to glibc builds to match
|
|
||||||
// the default behavior of device builds.
|
|
||||||
flags.LinkFlags = append(flags.LinkFlags, config.LinuxHostGlobalLinkFlags...)
|
|
||||||
} else if ctx.Os() == android.Darwin {
|
|
||||||
// Add -lc, -ldl, -lpthread and -lm to glibc darwin builds to match the default
|
|
||||||
// behavior of device builds.
|
|
||||||
flags.LinkFlags = append(flags.LinkFlags,
|
|
||||||
"-lc",
|
|
||||||
"-ldl",
|
|
||||||
"-lpthread",
|
|
||||||
"-lm",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -568,11 +584,11 @@ func (compiler *baseCompiler) installTestData(ctx ModuleContext, data []android.
|
|||||||
compiler.installDeps = append(compiler.installDeps, installedData...)
|
compiler.installDeps = append(compiler.installDeps, installedData...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (compiler *baseCompiler) getStem(ctx ModuleContext) string {
|
func (compiler *baseCompiler) getStem(ctx android.ModuleContext) string {
|
||||||
return compiler.getStemWithoutSuffix(ctx) + String(compiler.Properties.Suffix)
|
return compiler.getStemWithoutSuffix(ctx) + String(compiler.Properties.Suffix)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (compiler *baseCompiler) getStemWithoutSuffix(ctx BaseModuleContext) string {
|
func (compiler *baseCompiler) getStemWithoutSuffix(ctx android.BaseModuleContext) string {
|
||||||
stem := ctx.ModuleName()
|
stem := ctx.ModuleName()
|
||||||
if String(compiler.Properties.Stem) != "" {
|
if String(compiler.Properties.Stem) != "" {
|
||||||
stem = String(compiler.Properties.Stem)
|
stem = String(compiler.Properties.Stem)
|
||||||
|
@@ -446,8 +446,15 @@ func (library *libraryDecorator) sharedLibFilename(ctx ModuleContext) string {
|
|||||||
return library.getStem(ctx) + ctx.toolchain().SharedLibSuffix()
|
return library.getStem(ctx) + ctx.toolchain().SharedLibSuffix()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Library cfg flags common to all variants
|
||||||
|
func CommonLibraryCfgFlags(ctx android.ModuleContext, flags Flags) Flags {
|
||||||
|
return flags
|
||||||
|
}
|
||||||
|
|
||||||
func (library *libraryDecorator) cfgFlags(ctx ModuleContext, flags Flags) Flags {
|
func (library *libraryDecorator) cfgFlags(ctx ModuleContext, flags Flags) Flags {
|
||||||
flags = library.baseCompiler.cfgFlags(ctx, flags)
|
flags = library.baseCompiler.cfgFlags(ctx, flags)
|
||||||
|
flags = CommonLibraryCfgFlags(ctx, flags)
|
||||||
|
|
||||||
if library.dylib() {
|
if library.dylib() {
|
||||||
// We need to add a dependency on std in order to link crates as dylibs.
|
// We need to add a dependency on std in order to link crates as dylibs.
|
||||||
// The hack to add this dependency is guarded by the following cfg so
|
// The hack to add this dependency is guarded by the following cfg so
|
||||||
@@ -455,8 +462,15 @@ func (library *libraryDecorator) cfgFlags(ctx ModuleContext, flags Flags) Flags
|
|||||||
library.baseCompiler.Properties.Cfgs = append(library.baseCompiler.Properties.Cfgs, "android_dylib")
|
library.baseCompiler.Properties.Cfgs = append(library.baseCompiler.Properties.Cfgs, "android_dylib")
|
||||||
}
|
}
|
||||||
|
|
||||||
flags.RustFlags = append(flags.RustFlags, library.baseCompiler.cfgsToFlags()...)
|
flags.RustFlags = append(flags.RustFlags, cfgsToFlags(library.baseCompiler.Properties.Cfgs)...)
|
||||||
flags.RustdocFlags = append(flags.RustdocFlags, library.baseCompiler.cfgsToFlags()...)
|
flags.RustdocFlags = append(flags.RustdocFlags, cfgsToFlags(library.baseCompiler.Properties.Cfgs)...)
|
||||||
|
|
||||||
|
return flags
|
||||||
|
}
|
||||||
|
|
||||||
|
// Common flags applied to all libraries irrespective of properties or variant should be included here
|
||||||
|
func CommonLibraryCompilerFlags(ctx android.ModuleContext, flags Flags) Flags {
|
||||||
|
flags.RustFlags = append(flags.RustFlags, "-C metadata="+ctx.ModuleName())
|
||||||
|
|
||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
@@ -464,7 +478,8 @@ func (library *libraryDecorator) cfgFlags(ctx ModuleContext, flags Flags) Flags
|
|||||||
func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags) Flags {
|
func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags) Flags {
|
||||||
flags = library.baseCompiler.compilerFlags(ctx, flags)
|
flags = library.baseCompiler.compilerFlags(ctx, flags)
|
||||||
|
|
||||||
flags.RustFlags = append(flags.RustFlags, "-C metadata="+ctx.ModuleName())
|
flags = CommonLibraryCompilerFlags(ctx, flags)
|
||||||
|
|
||||||
if library.shared() || library.static() {
|
if library.shared() || library.static() {
|
||||||
library.includeDirs = append(library.includeDirs, android.PathsForModuleSrc(ctx, library.Properties.Include_dirs)...)
|
library.includeDirs = append(library.includeDirs, android.PathsForModuleSrc(ctx, library.Properties.Include_dirs)...)
|
||||||
library.includeDirs = append(library.includeDirs, android.PathsForModuleSrc(ctx, library.Properties.Export_include_dirs)...)
|
library.includeDirs = append(library.includeDirs, android.PathsForModuleSrc(ctx, library.Properties.Export_include_dirs)...)
|
||||||
|
Reference in New Issue
Block a user