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) // path to the main source file that contains the program entry point (e.g. src/main.rs)
Srcs []string `android:"path,arch_variant"` 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 Prefer_dynamic *bool
} }
@ -73,7 +74,8 @@ func (binary *binaryDecorator) compilerFlags(ctx ModuleContext, flags Flags) Fla
flags = binary.baseCompiler.compilerFlags(ctx, flags) flags = binary.baseCompiler.compilerFlags(ctx, flags)
if ctx.toolchain().Bionic() { 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, flags.LinkFlags = append(flags.LinkFlags,
"-Wl,--gc-sections", "-Wl,--gc-sections",
"-Wl,-z,nocopyreloc", "-Wl,-z,nocopyreloc",

View File

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