diff options
Diffstat (limited to 'rust/rust.go')
-rw-r--r-- | rust/rust.go | 62 |
1 files changed, 25 insertions, 37 deletions
diff --git a/rust/rust.go b/rust/rust.go index 7cc0b2c3b..61b51e547 100644 --- a/rust/rust.go +++ b/rust/rust.go @@ -29,28 +29,11 @@ var pctx = android.NewPackageContext("android/soong/rust") func init() { // Only allow rust modules to be defined for certain projects - rustModuleTypes := []string{ - "rust_binary", - "rust_binary_host", - "rust_library", - "rust_library_dylib", - "rust_library_rlib", - "rust_library_host", - "rust_library_host_dylib", - "rust_library_host_rlib", - "rust_proc_macro", - } - - rustAllowedPaths := []string{ - "external/rust/crates", - "external/crosvm", - "external/adhd", - } android.AddNeverAllowRules( android.NeverAllow(). - NotIn(rustAllowedPaths...). - ModuleType(rustModuleTypes...)) + NotIn(config.RustAllowedPaths...). + ModuleType(config.RustModuleTypes...)) android.RegisterModuleType("rust_defaults", defaultsFactory) android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { @@ -60,11 +43,12 @@ func init() { } type Flags struct { - GlobalFlags []string // Flags that apply globally - RustFlags []string // Flags that apply to rust - LinkFlags []string // Flags that apply to linker - RustFlagsDeps android.Paths // Files depended on by compiler flags - Toolchain config.Toolchain + GlobalRustFlags []string // Flags that apply globally to rust + GlobalLinkFlags []string // Flags that apply globally to linker + RustFlags []string // Flags that apply to rust + LinkFlags []string // Flags that apply to linker + RustFlagsDeps android.Paths // Files depended on by compiler flags + Toolchain config.Toolchain } type BaseProperties struct { @@ -109,6 +93,9 @@ type PathDeps struct { linkDirs []string depFlags []string //ReexportedDeps android.Paths + + CrtBegin android.OptionalPath + CrtEnd android.OptionalPath } type RustLibraries []RustLibrary @@ -338,15 +325,6 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { if rustDep, ok := dep.(*Module); ok { //Handle Rust Modules - if rustDep.Target().Os != ctx.Os() { - ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName) - return - } - if rustDep.Target().Arch.ArchType != ctx.Arch().ArchType { - ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName) - return - } - linkFile := rustDep.outputFile if !linkFile.Valid() { ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName()) @@ -378,9 +356,6 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { if lib, ok := rustDep.compiler.(*libraryDecorator); ok { depPaths.linkDirs = append(depPaths.linkDirs, lib.exportedDirs()...) depPaths.depFlags = append(depPaths.depFlags, lib.exportedDepFlags()...) - } else if procMacro, ok := rustDep.compiler.(*libraryDecorator); ok { - depPaths.linkDirs = append(depPaths.linkDirs, procMacro.exportedDirs()...) - depPaths.depFlags = append(depPaths.depFlags, procMacro.exportedDepFlags()...) } // Append this dependencies output to this mod's linkDirs so they can be exported to dependencies @@ -427,6 +402,10 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { directSharedLibDeps = append(directSharedLibDeps, ccDep) mod.Properties.AndroidMkSharedLibs = append(mod.Properties.AndroidMkSharedLibs, depName) exportDep = true + case cc.CrtBeginDepTag(): + depPaths.CrtBegin = linkFile + case cc.CrtEndDepTag(): + depPaths.CrtEnd = linkFile } // Make sure these dependencies are propagated @@ -508,7 +487,16 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) { } actx.AddVariationDependencies(append(ccDepVariations, blueprint.Variation{Mutator: "link", Variation: "shared"}), cc.SharedDepTag(), deps.SharedLibs...) actx.AddVariationDependencies(append(ccDepVariations, blueprint.Variation{Mutator: "link", Variation: "static"}), cc.StaticDepTag(), deps.StaticLibs...) - actx.AddDependency(mod, procMacroDepTag, deps.ProcMacros...) + + if deps.CrtBegin != "" { + actx.AddVariationDependencies(ccDepVariations, cc.CrtBeginDepTag(), deps.CrtBegin) + } + if deps.CrtEnd != "" { + actx.AddVariationDependencies(ccDepVariations, cc.CrtEndDepTag(), deps.CrtEnd) + } + + // proc_macros are compiler plugins, and so we need the host arch variant as a dependendcy. + actx.AddFarVariationDependencies([]blueprint.Variation{{Mutator: "arch", Variation: ctx.Config().BuildOsVariant}}, procMacroDepTag, deps.ProcMacros...) } func (mod *Module) Name() string { |