diff options
author | ThiƩbaud Weksteen <tweek@google.com> | 2020-09-29 09:53:21 +0200 |
---|---|---|
committer | ThiƩbaud Weksteen <tweek@google.com> | 2020-09-29 20:23:49 +0200 |
commit | a6351caf1220538a61d03ab17efa8d85572d4bf9 (patch) | |
tree | e3f0a4caac014981cd018382762ccb787cdf4b5b /rust/project_json.go | |
parent | 3805f5cd2e0a2e6b5cfc1dfa14931b99af6bdcab (diff) |
rust: Add ref to generated sources (aidl, bindgen)
Test: SOONG_GEN_RUST_PROJECT=1 m nothing; Edit
system/security/keystore2/selinux/src/lib.rs;
Check name resolution in IDE.
Bug: 168263887
Change-Id: Icbbf176c4355c3043807ce3fe0c3967c4a1374e2
Diffstat (limited to 'rust/project_json.go')
-rw-r--r-- | rust/project_json.go | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/rust/project_json.go b/rust/project_json.go index 0d25a2f86..8d161b2d7 100644 --- a/rust/project_json.go +++ b/rust/project_json.go @@ -75,6 +75,32 @@ func init() { android.RegisterSingletonType("rust_project_generator", rustProjectGeneratorSingleton) } +// librarySource finds the main source file (.rs) for a crate. +func librarySource(ctx android.SingletonContext, rModule *Module, rustLib *libraryDecorator) (string, bool) { + srcs := rustLib.baseCompiler.Properties.Srcs + if len(srcs) != 0 { + return path.Join(ctx.ModuleDir(rModule), srcs[0]), true + } + if !rustLib.source() { + return "", false + } + // It is a SourceProvider module. If this module is host only, uses the variation for the host. + // Otherwise, use the variation for the primary target. + switch rModule.hod { + case android.HostSupported: + case android.HostSupportedNoCross: + if rModule.Target().String() != ctx.Config().BuildOSTarget.String() { + return "", false + } + default: + if rModule.Target().String() != ctx.Config().Targets[android.Android][0].String() { + return "", false + } + } + src := rustLib.sourceProvider.Srcs()[0] + return src.String(), true +} + func (singleton *projectGeneratorSingleton) mergeDependencies(ctx android.SingletonContext, module android.Module, crate *rustProjectCrate, deps map[string]int) { @@ -116,11 +142,11 @@ func (singleton *projectGeneratorSingleton) appendLibraryAndDeps(ctx android.Sin return cInfo.ID, crateName, true } crate := rustProjectCrate{Deps: make([]rustProjectDep, 0), Cfgs: make([]string, 0)} - srcs := rustLib.baseCompiler.Properties.Srcs - if len(srcs) == 0 { + rootModule, ok := librarySource(ctx, rModule, rustLib) + if !ok { return 0, "", false } - crate.RootModule = path.Join(ctx.ModuleDir(rModule), srcs[0]) + crate.RootModule = rootModule crate.Edition = rustLib.baseCompiler.edition() deps := make(map[string]int) |