From b2df9f88eb9767dd43e6eeee53181976cc9368c9 Mon Sep 17 00:00:00 2001 From: Ivan Lozano Date: Tue, 5 Nov 2019 12:16:46 -0800 Subject: [PATCH] Soong Rust source clean up. Break up some of the longer lines in the Rust source and refactor the TransformSrcto* functions to take fewer arguments. Bug: N/A Test: m -j crosvm.experimental Change-Id: Ia0deb8bfe3e1bfd07ef35633e9a7e6f5e799b3a3 --- rust/binary.go | 6 +++-- rust/builder.go | 67 +++++++++++++++++++++++++++---------------------- 2 files changed, 41 insertions(+), 32 deletions(-) diff --git a/rust/binary.go b/rust/binary.go index 52f840e7a..a909ea681 100644 --- a/rust/binary.go +++ b/rust/binary.go @@ -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", diff --git a/rust/builder.go b/rust/builder.go index d9e36dbbe..11510e174 100644 --- a/rust/builder.go +++ b/rust/builder.go @@ -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(), }, })