Merge "Soong Rust source clean up."

This commit is contained in:
Ivan Lozano 2019-11-14 14:07:55 +00:00 committed by Gerrit Code Review
commit 263dcb7397
2 changed files with 41 additions and 32 deletions

View file

@ -28,7 +28,8 @@ type BinaryCompilerProperties struct {
// path to the main source file that contains the program entry point (e.g. src/main.rs)
Srcs []string `android:"path,arch_variant"`
// passes -C prefer-dynamic to rustc, which tells it to dynamically link the stdlib (assuming it has no dylib dependencies already)
// passes -C prefer-dynamic to rustc, which tells it to dynamically link the stdlib
// (assuming it has no dylib dependencies already)
Prefer_dynamic *bool
}
@ -73,7 +74,8 @@ func (binary *binaryDecorator) compilerFlags(ctx ModuleContext, flags Flags) Fla
flags = binary.baseCompiler.compilerFlags(ctx, flags)
if ctx.toolchain().Bionic() {
// no-undefined-version breaks dylib compilation since __rust_*alloc* functions aren't defined, but we can apply this to binaries.
// no-undefined-version breaks dylib compilation since __rust_*alloc* functions aren't defined,
// but we can apply this to binaries.
flags.LinkFlags = append(flags.LinkFlags,
"-Wl,--gc-sections",
"-Wl,-z,nocopyreloc",

View file

@ -31,8 +31,9 @@ var (
"-C link-args=\"${crtBegin} ${config.RustLinkerArgs} ${linkFlags} ${crtEnd}\" " +
"--emit link -o $out --emit dep-info=$out.d $in ${libFlags} $rustcFlags",
CommandDeps: []string{"$rustcCmd"},
Depfile: "$out.d",
Deps: blueprint.DepsGCC, // Rustc deps-info writes out make compatible dep files: https://github.com/rust-lang/rust/issues/7633
// Rustc deps-info writes out make compatible dep files: https://github.com/rust-lang/rust/issues/7633
Deps: blueprint.DepsGCC,
Depfile: "$out.d",
},
"rustcFlags", "linkFlags", "libFlags", "crtBegin", "crtEnd")
)
@ -41,28 +42,34 @@ func init() {
}
func TransformSrcToBinary(ctx android.ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags, outputFile android.WritablePath, includeDirs []string) {
transformSrctoCrate(ctx, mainSrc, deps.RLibs, deps.DyLibs, deps.ProcMacros, deps.StaticLibs, deps.SharedLibs, deps.CrtBegin, deps.CrtEnd, flags, outputFile, "bin", includeDirs)
func TransformSrcToBinary(ctx android.ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
outputFile android.WritablePath, includeDirs []string) {
transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "bin", includeDirs)
}
func TransformSrctoRlib(ctx android.ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags, outputFile android.WritablePath, includeDirs []string) {
transformSrctoCrate(ctx, mainSrc, deps.RLibs, deps.DyLibs, deps.ProcMacros, deps.StaticLibs, deps.SharedLibs, deps.CrtBegin, deps.CrtEnd, flags, outputFile, "rlib", includeDirs)
func TransformSrctoRlib(ctx android.ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
outputFile android.WritablePath, includeDirs []string) {
transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "rlib", includeDirs)
}
func TransformSrctoDylib(ctx android.ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags, outputFile android.WritablePath, includeDirs []string) {
transformSrctoCrate(ctx, mainSrc, deps.RLibs, deps.DyLibs, deps.ProcMacros, deps.StaticLibs, deps.SharedLibs, deps.CrtBegin, deps.CrtEnd, flags, outputFile, "dylib", includeDirs)
func TransformSrctoDylib(ctx android.ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
outputFile android.WritablePath, includeDirs []string) {
transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "dylib", includeDirs)
}
func TransformSrctoStatic(ctx android.ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags, outputFile android.WritablePath, includeDirs []string) {
transformSrctoCrate(ctx, mainSrc, deps.RLibs, deps.DyLibs, deps.ProcMacros, deps.StaticLibs, deps.SharedLibs, deps.CrtBegin, deps.CrtEnd, flags, outputFile, "staticlib", includeDirs)
func TransformSrctoStatic(ctx android.ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
outputFile android.WritablePath, includeDirs []string) {
transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "staticlib", includeDirs)
}
func TransformSrctoShared(ctx android.ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags, outputFile android.WritablePath, includeDirs []string) {
transformSrctoCrate(ctx, mainSrc, deps.RLibs, deps.DyLibs, deps.ProcMacros, deps.StaticLibs, deps.SharedLibs, deps.CrtBegin, deps.CrtEnd, flags, outputFile, "cdylib", includeDirs)
func TransformSrctoShared(ctx android.ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
outputFile android.WritablePath, includeDirs []string) {
transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "cdylib", includeDirs)
}
func TransformSrctoProcMacro(ctx android.ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags, outputFile android.WritablePath, includeDirs []string) {
transformSrctoCrate(ctx, mainSrc, deps.RLibs, deps.DyLibs, deps.ProcMacros, deps.StaticLibs, deps.SharedLibs, deps.CrtBegin, deps.CrtEnd, flags, outputFile, "proc-macro", includeDirs)
func TransformSrctoProcMacro(ctx android.ModuleContext, mainSrc android.Path, deps PathDeps,
flags Flags, outputFile android.WritablePath, includeDirs []string) {
transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "proc-macro", includeDirs)
}
func rustLibsToPaths(libs RustLibraries) android.Paths {
@ -73,11 +80,11 @@ func rustLibsToPaths(libs RustLibraries) android.Paths {
return paths
}
func transformSrctoCrate(ctx android.ModuleContext, main android.Path,
rlibs, dylibs, proc_macros RustLibraries, static_libs, shared_libs android.Paths, crtBegin, crtEnd android.OptionalPath, flags Flags, outputFile android.WritablePath, crate_type string, includeDirs []string) {
func transformSrctoCrate(ctx android.ModuleContext, main android.Path, deps PathDeps, flags Flags,
outputFile android.WritablePath, crate_type string, includeDirs []string) {
var inputs android.Paths
var deps android.Paths
var implicits android.Paths
var libFlags, rustcFlags, linkFlags []string
crate_name := ctx.(ModuleContext).CrateName()
targetTriple := ctx.(ModuleContext).toolchain().RustTriple()
@ -100,13 +107,13 @@ func transformSrctoCrate(ctx android.ModuleContext, main android.Path,
linkFlags = append(linkFlags, flags.LinkFlags...)
// Collect library/crate flags
for _, lib := range rlibs {
for _, lib := range deps.RLibs {
libFlags = append(libFlags, "--extern "+lib.CrateName+"="+lib.Path.String())
}
for _, lib := range dylibs {
for _, lib := range deps.DyLibs {
libFlags = append(libFlags, "--extern "+lib.CrateName+"="+lib.Path.String())
}
for _, proc_macro := range proc_macros {
for _, proc_macro := range deps.ProcMacros {
libFlags = append(libFlags, "--extern "+proc_macro.CrateName+"="+proc_macro.Path.String())
}
@ -115,13 +122,13 @@ func transformSrctoCrate(ctx android.ModuleContext, main android.Path,
}
// Collect dependencies
deps = append(deps, rustLibsToPaths(rlibs)...)
deps = append(deps, rustLibsToPaths(dylibs)...)
deps = append(deps, rustLibsToPaths(proc_macros)...)
deps = append(deps, static_libs...)
deps = append(deps, shared_libs...)
if crtBegin.Valid() {
deps = append(deps, crtBegin.Path(), crtEnd.Path())
implicits = append(implicits, rustLibsToPaths(deps.RLibs)...)
implicits = append(implicits, rustLibsToPaths(deps.DyLibs)...)
implicits = append(implicits, rustLibsToPaths(deps.ProcMacros)...)
implicits = append(implicits, deps.StaticLibs...)
implicits = append(implicits, deps.SharedLibs...)
if deps.CrtBegin.Valid() {
implicits = append(implicits, deps.CrtBegin.Path(), deps.CrtEnd.Path())
}
ctx.Build(pctx, android.BuildParams{
@ -129,13 +136,13 @@ func transformSrctoCrate(ctx android.ModuleContext, main android.Path,
Description: "rustc " + main.Rel(),
Output: outputFile,
Inputs: inputs,
Implicits: deps,
Implicits: implicits,
Args: map[string]string{
"rustcFlags": strings.Join(rustcFlags, " "),
"linkFlags": strings.Join(linkFlags, " "),
"libFlags": strings.Join(libFlags, " "),
"crtBegin": crtBegin.String(),
"crtEnd": crtEnd.String(),
"crtBegin": deps.CrtBegin.String(),
"crtEnd": deps.CrtEnd.String(),
},
})