rust.go 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791
  1. // Copyright 2019 The Android Open Source Project
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package rust
  15. import (
  16. "android/soong/bloaty"
  17. "fmt"
  18. "strings"
  19. "github.com/google/blueprint"
  20. "github.com/google/blueprint/proptools"
  21. "android/soong/android"
  22. "android/soong/cc"
  23. cc_config "android/soong/cc/config"
  24. "android/soong/fuzz"
  25. "android/soong/multitree"
  26. "android/soong/rust/config"
  27. "android/soong/snapshot"
  28. )
  29. var pctx = android.NewPackageContext("android/soong/rust")
  30. func init() {
  31. android.RegisterModuleType("rust_defaults", defaultsFactory)
  32. android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
  33. ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
  34. ctx.BottomUp("rust_stdlinkage", LibstdMutator).Parallel()
  35. ctx.BottomUp("rust_begin", BeginMutator).Parallel()
  36. })
  37. android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
  38. ctx.BottomUp("rust_sanitizers", rustSanitizerRuntimeMutator).Parallel()
  39. })
  40. pctx.Import("android/soong/rust/config")
  41. pctx.ImportAs("cc_config", "android/soong/cc/config")
  42. android.InitRegistrationContext.RegisterSingletonType("kythe_rust_extract", kytheExtractRustFactory)
  43. }
  44. type Flags struct {
  45. GlobalRustFlags []string // Flags that apply globally to rust
  46. GlobalLinkFlags []string // Flags that apply globally to linker
  47. RustFlags []string // Flags that apply to rust
  48. LinkFlags []string // Flags that apply to linker
  49. ClippyFlags []string // Flags that apply to clippy-driver, during the linting
  50. RustdocFlags []string // Flags that apply to rustdoc
  51. Toolchain config.Toolchain
  52. Coverage bool
  53. Clippy bool
  54. EmitXrefs bool // If true, emit rules to aid cross-referencing
  55. }
  56. type BaseProperties struct {
  57. AndroidMkRlibs []string `blueprint:"mutated"`
  58. AndroidMkDylibs []string `blueprint:"mutated"`
  59. AndroidMkProcMacroLibs []string `blueprint:"mutated"`
  60. AndroidMkSharedLibs []string `blueprint:"mutated"`
  61. AndroidMkStaticLibs []string `blueprint:"mutated"`
  62. ImageVariationPrefix string `blueprint:"mutated"`
  63. VndkVersion string `blueprint:"mutated"`
  64. SubName string `blueprint:"mutated"`
  65. // SubName is used by CC for tracking image variants / SDK versions. RustSubName is used for Rust-specific
  66. // subnaming which shouldn't be visible to CC modules (such as the rlib stdlinkage subname). This should be
  67. // appended before SubName.
  68. RustSubName string `blueprint:"mutated"`
  69. // Set by imageMutator
  70. CoreVariantNeeded bool `blueprint:"mutated"`
  71. VendorRamdiskVariantNeeded bool `blueprint:"mutated"`
  72. RamdiskVariantNeeded bool `blueprint:"mutated"`
  73. RecoveryVariantNeeded bool `blueprint:"mutated"`
  74. ExtraVariants []string `blueprint:"mutated"`
  75. // Allows this module to use non-APEX version of libraries. Useful
  76. // for building binaries that are started before APEXes are activated.
  77. Bootstrap *bool
  78. // Used by vendor snapshot to record dependencies from snapshot modules.
  79. SnapshotSharedLibs []string `blueprint:"mutated"`
  80. SnapshotStaticLibs []string `blueprint:"mutated"`
  81. // Make this module available when building for ramdisk.
  82. // On device without a dedicated recovery partition, the module is only
  83. // available after switching root into
  84. // /first_stage_ramdisk. To expose the module before switching root, install
  85. // the recovery variant instead.
  86. Ramdisk_available *bool
  87. // Make this module available when building for vendor ramdisk.
  88. // On device without a dedicated recovery partition, the module is only
  89. // available after switching root into
  90. // /first_stage_ramdisk. To expose the module before switching root, install
  91. // the recovery variant instead
  92. Vendor_ramdisk_available *bool
  93. // Normally Soong uses the directory structure to decide which modules
  94. // should be included (framework) or excluded (non-framework) from the
  95. // different snapshots (vendor, recovery, etc.), but this property
  96. // allows a partner to exclude a module normally thought of as a
  97. // framework module from the vendor snapshot.
  98. Exclude_from_vendor_snapshot *bool
  99. // Normally Soong uses the directory structure to decide which modules
  100. // should be included (framework) or excluded (non-framework) from the
  101. // different snapshots (vendor, recovery, etc.), but this property
  102. // allows a partner to exclude a module normally thought of as a
  103. // framework module from the recovery snapshot.
  104. Exclude_from_recovery_snapshot *bool
  105. // Make this module available when building for recovery
  106. Recovery_available *bool
  107. // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
  108. Min_sdk_version *string
  109. HideFromMake bool `blueprint:"mutated"`
  110. PreventInstall bool `blueprint:"mutated"`
  111. Installable *bool
  112. }
  113. type Module struct {
  114. fuzz.FuzzModule
  115. VendorProperties cc.VendorProperties
  116. Properties BaseProperties
  117. hod android.HostOrDeviceSupported
  118. multilib android.Multilib
  119. makeLinkType string
  120. afdo *afdo
  121. compiler compiler
  122. coverage *coverage
  123. clippy *clippy
  124. sanitize *sanitize
  125. cachedToolchain config.Toolchain
  126. sourceProvider SourceProvider
  127. subAndroidMkOnce map[SubAndroidMkProvider]bool
  128. // Output file to be installed, may be stripped or unstripped.
  129. outputFile android.OptionalPath
  130. // Cross-reference input file
  131. kytheFiles android.Paths
  132. docTimestampFile android.OptionalPath
  133. hideApexVariantFromMake bool
  134. // For apex variants, this is set as apex.min_sdk_version
  135. apexSdkVersion android.ApiLevel
  136. }
  137. func (mod *Module) Header() bool {
  138. //TODO: If Rust libraries provide header variants, this needs to be updated.
  139. return false
  140. }
  141. func (mod *Module) SetPreventInstall() {
  142. mod.Properties.PreventInstall = true
  143. }
  144. func (mod *Module) SetHideFromMake() {
  145. mod.Properties.HideFromMake = true
  146. }
  147. func (mod *Module) HiddenFromMake() bool {
  148. return mod.Properties.HideFromMake
  149. }
  150. func (mod *Module) SanitizePropDefined() bool {
  151. // Because compiler is not set for some Rust modules where sanitize might be set, check that compiler is also not
  152. // nil since we need compiler to actually sanitize.
  153. return mod.sanitize != nil && mod.compiler != nil
  154. }
  155. func (mod *Module) IsPrebuilt() bool {
  156. if _, ok := mod.compiler.(*prebuiltLibraryDecorator); ok {
  157. return true
  158. }
  159. return false
  160. }
  161. func (mod *Module) OutputFiles(tag string) (android.Paths, error) {
  162. switch tag {
  163. case "":
  164. if mod.sourceProvider != nil && (mod.compiler == nil || mod.compiler.Disabled()) {
  165. return mod.sourceProvider.Srcs(), nil
  166. } else {
  167. if mod.OutputFile().Valid() {
  168. return android.Paths{mod.OutputFile().Path()}, nil
  169. }
  170. return android.Paths{}, nil
  171. }
  172. case "unstripped":
  173. if mod.compiler != nil {
  174. return android.PathsIfNonNil(mod.compiler.unstrippedOutputFilePath()), nil
  175. }
  176. return nil, nil
  177. default:
  178. return nil, fmt.Errorf("unsupported module reference tag %q", tag)
  179. }
  180. }
  181. func (mod *Module) SelectedStl() string {
  182. return ""
  183. }
  184. func (mod *Module) NonCcVariants() bool {
  185. if mod.compiler != nil {
  186. if _, ok := mod.compiler.(libraryInterface); ok {
  187. return false
  188. }
  189. }
  190. panic(fmt.Errorf("NonCcVariants called on non-library module: %q", mod.BaseModuleName()))
  191. }
  192. func (mod *Module) Static() bool {
  193. if mod.compiler != nil {
  194. if library, ok := mod.compiler.(libraryInterface); ok {
  195. return library.static()
  196. }
  197. }
  198. return false
  199. }
  200. func (mod *Module) Shared() bool {
  201. if mod.compiler != nil {
  202. if library, ok := mod.compiler.(libraryInterface); ok {
  203. return library.shared()
  204. }
  205. }
  206. return false
  207. }
  208. func (mod *Module) Dylib() bool {
  209. if mod.compiler != nil {
  210. if library, ok := mod.compiler.(libraryInterface); ok {
  211. return library.dylib()
  212. }
  213. }
  214. return false
  215. }
  216. func (mod *Module) Rlib() bool {
  217. if mod.compiler != nil {
  218. if library, ok := mod.compiler.(libraryInterface); ok {
  219. return library.rlib()
  220. }
  221. }
  222. return false
  223. }
  224. func (mod *Module) Binary() bool {
  225. if binary, ok := mod.compiler.(binaryInterface); ok {
  226. return binary.binary()
  227. }
  228. return false
  229. }
  230. func (mod *Module) StaticExecutable() bool {
  231. if !mod.Binary() {
  232. return false
  233. }
  234. return mod.StaticallyLinked()
  235. }
  236. func (mod *Module) Object() bool {
  237. // Rust has no modules which produce only object files.
  238. return false
  239. }
  240. func (mod *Module) Toc() android.OptionalPath {
  241. if mod.compiler != nil {
  242. if lib, ok := mod.compiler.(libraryInterface); ok {
  243. return lib.toc()
  244. }
  245. }
  246. panic(fmt.Errorf("Toc() called on non-library module: %q", mod.BaseModuleName()))
  247. }
  248. func (mod *Module) UseSdk() bool {
  249. return false
  250. }
  251. func (mod *Module) RelativeInstallPath() string {
  252. if mod.compiler != nil {
  253. return mod.compiler.relativeInstallPath()
  254. }
  255. return ""
  256. }
  257. func (mod *Module) UseVndk() bool {
  258. return mod.Properties.VndkVersion != ""
  259. }
  260. func (mod *Module) Bootstrap() bool {
  261. return Bool(mod.Properties.Bootstrap)
  262. }
  263. func (mod *Module) MustUseVendorVariant() bool {
  264. return true
  265. }
  266. func (mod *Module) SubName() string {
  267. return mod.Properties.SubName
  268. }
  269. func (mod *Module) IsVndk() bool {
  270. // TODO(b/165791368)
  271. return false
  272. }
  273. func (mod *Module) IsVndkExt() bool {
  274. return false
  275. }
  276. func (mod *Module) IsVndkSp() bool {
  277. return false
  278. }
  279. func (mod *Module) IsVndkPrebuiltLibrary() bool {
  280. // Rust modules do not provide VNDK prebuilts
  281. return false
  282. }
  283. func (mod *Module) IsVendorPublicLibrary() bool {
  284. return mod.VendorProperties.IsVendorPublicLibrary
  285. }
  286. func (mod *Module) SdkAndPlatformVariantVisibleToMake() bool {
  287. // Rust modules to not provide Sdk variants
  288. return false
  289. }
  290. func (c *Module) IsVndkPrivate() bool {
  291. return false
  292. }
  293. func (c *Module) IsLlndk() bool {
  294. return false
  295. }
  296. func (c *Module) IsLlndkPublic() bool {
  297. return false
  298. }
  299. func (mod *Module) KernelHeadersDecorator() bool {
  300. return false
  301. }
  302. func (m *Module) NeedsLlndkVariants() bool {
  303. return false
  304. }
  305. func (m *Module) NeedsVendorPublicLibraryVariants() bool {
  306. return false
  307. }
  308. func (mod *Module) HasLlndkStubs() bool {
  309. return false
  310. }
  311. func (mod *Module) StubsVersion() string {
  312. panic(fmt.Errorf("StubsVersion called on non-versioned module: %q", mod.BaseModuleName()))
  313. }
  314. func (mod *Module) SdkVersion() string {
  315. return ""
  316. }
  317. func (mod *Module) AlwaysSdk() bool {
  318. return false
  319. }
  320. func (mod *Module) IsSdkVariant() bool {
  321. return false
  322. }
  323. func (mod *Module) SplitPerApiLevel() bool {
  324. return false
  325. }
  326. func (mod *Module) XrefRustFiles() android.Paths {
  327. return mod.kytheFiles
  328. }
  329. type Deps struct {
  330. Dylibs []string
  331. Rlibs []string
  332. Rustlibs []string
  333. Stdlibs []string
  334. ProcMacros []string
  335. SharedLibs []string
  336. StaticLibs []string
  337. WholeStaticLibs []string
  338. HeaderLibs []string
  339. // Used for data dependencies adjacent to tests
  340. DataLibs []string
  341. DataBins []string
  342. CrtBegin, CrtEnd []string
  343. }
  344. type PathDeps struct {
  345. DyLibs RustLibraries
  346. RLibs RustLibraries
  347. LibDeps android.Paths
  348. WholeStaticLibs android.Paths
  349. ProcMacros RustLibraries
  350. AfdoProfiles android.Paths
  351. // depFlags and depLinkFlags are rustc and linker (clang) flags.
  352. depFlags []string
  353. depLinkFlags []string
  354. // linkDirs are link paths passed via -L to rustc. linkObjects are objects passed directly to the linker.
  355. // Both of these are exported and propagate to dependencies.
  356. linkDirs []string
  357. linkObjects android.Paths
  358. // Used by bindgen modules which call clang
  359. depClangFlags []string
  360. depIncludePaths android.Paths
  361. depGeneratedHeaders android.Paths
  362. depSystemIncludePaths android.Paths
  363. CrtBegin android.Paths
  364. CrtEnd android.Paths
  365. // Paths to generated source files
  366. SrcDeps android.Paths
  367. srcProviderFiles android.Paths
  368. }
  369. type RustLibraries []RustLibrary
  370. type RustLibrary struct {
  371. Path android.Path
  372. CrateName string
  373. }
  374. type compiler interface {
  375. initialize(ctx ModuleContext)
  376. compilerFlags(ctx ModuleContext, flags Flags) Flags
  377. cfgFlags(ctx ModuleContext, flags Flags) Flags
  378. featureFlags(ctx ModuleContext, flags Flags) Flags
  379. compilerProps() []interface{}
  380. compile(ctx ModuleContext, flags Flags, deps PathDeps) buildOutput
  381. compilerDeps(ctx DepsContext, deps Deps) Deps
  382. crateName() string
  383. rustdoc(ctx ModuleContext, flags Flags, deps PathDeps) android.OptionalPath
  384. // Output directory in which source-generated code from dependencies is
  385. // copied. This is equivalent to Cargo's OUT_DIR variable.
  386. CargoOutDir() android.OptionalPath
  387. // CargoPkgVersion returns the value of the Cargo_pkg_version property.
  388. CargoPkgVersion() string
  389. // CargoEnvCompat returns whether Cargo environment variables should be used.
  390. CargoEnvCompat() bool
  391. inData() bool
  392. install(ctx ModuleContext)
  393. relativeInstallPath() string
  394. everInstallable() bool
  395. nativeCoverage() bool
  396. Disabled() bool
  397. SetDisabled()
  398. stdLinkage(ctx *depsContext) RustLinkage
  399. noStdlibs() bool
  400. unstrippedOutputFilePath() android.Path
  401. strippedOutputFilePath() android.OptionalPath
  402. }
  403. type exportedFlagsProducer interface {
  404. exportLinkDirs(...string)
  405. exportLinkObjects(...android.Path)
  406. }
  407. type xref interface {
  408. XrefRustFiles() android.Paths
  409. }
  410. type flagExporter struct {
  411. linkDirs []string
  412. linkObjects android.Paths
  413. libDeps android.Paths
  414. }
  415. func (flagExporter *flagExporter) exportLinkDirs(dirs ...string) {
  416. flagExporter.linkDirs = android.FirstUniqueStrings(append(flagExporter.linkDirs, dirs...))
  417. }
  418. func (flagExporter *flagExporter) exportLinkObjects(flags ...android.Path) {
  419. flagExporter.linkObjects = android.FirstUniquePaths(append(flagExporter.linkObjects, flags...))
  420. }
  421. func (flagExporter *flagExporter) exportLibDeps(paths ...android.Path) {
  422. flagExporter.libDeps = android.FirstUniquePaths(append(flagExporter.libDeps, paths...))
  423. }
  424. func (flagExporter *flagExporter) setProvider(ctx ModuleContext) {
  425. ctx.SetProvider(FlagExporterInfoProvider, FlagExporterInfo{
  426. LinkDirs: flagExporter.linkDirs,
  427. LinkObjects: flagExporter.linkObjects,
  428. LibDeps: flagExporter.libDeps,
  429. })
  430. }
  431. var _ exportedFlagsProducer = (*flagExporter)(nil)
  432. func NewFlagExporter() *flagExporter {
  433. return &flagExporter{}
  434. }
  435. type FlagExporterInfo struct {
  436. Flags []string
  437. LinkDirs []string // TODO: this should be android.Paths
  438. LinkObjects android.Paths
  439. LibDeps android.Paths
  440. }
  441. var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{})
  442. func (mod *Module) isCoverageVariant() bool {
  443. return mod.coverage.Properties.IsCoverageVariant
  444. }
  445. var _ cc.Coverage = (*Module)(nil)
  446. func (mod *Module) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
  447. return mod.coverage != nil && mod.coverage.Properties.NeedCoverageVariant
  448. }
  449. func (mod *Module) VndkVersion() string {
  450. return mod.Properties.VndkVersion
  451. }
  452. func (mod *Module) PreventInstall() bool {
  453. return mod.Properties.PreventInstall
  454. }
  455. func (mod *Module) MarkAsCoverageVariant(coverage bool) {
  456. mod.coverage.Properties.IsCoverageVariant = coverage
  457. }
  458. func (mod *Module) EnableCoverageIfNeeded() {
  459. mod.coverage.Properties.CoverageEnabled = mod.coverage.Properties.NeedCoverageBuild
  460. }
  461. func defaultsFactory() android.Module {
  462. return DefaultsFactory()
  463. }
  464. type Defaults struct {
  465. android.ModuleBase
  466. android.DefaultsModuleBase
  467. }
  468. func DefaultsFactory(props ...interface{}) android.Module {
  469. module := &Defaults{}
  470. module.AddProperties(props...)
  471. module.AddProperties(
  472. &BaseProperties{},
  473. &cc.AfdoProperties{},
  474. &cc.VendorProperties{},
  475. &BenchmarkProperties{},
  476. &BindgenProperties{},
  477. &BaseCompilerProperties{},
  478. &BinaryCompilerProperties{},
  479. &LibraryCompilerProperties{},
  480. &ProcMacroCompilerProperties{},
  481. &PrebuiltProperties{},
  482. &SourceProviderProperties{},
  483. &TestProperties{},
  484. &cc.CoverageProperties{},
  485. &cc.RustBindgenClangProperties{},
  486. &ClippyProperties{},
  487. &SanitizeProperties{},
  488. )
  489. android.InitDefaultsModule(module)
  490. return module
  491. }
  492. func (mod *Module) CrateName() string {
  493. return mod.compiler.crateName()
  494. }
  495. func (mod *Module) CcLibrary() bool {
  496. if mod.compiler != nil {
  497. if _, ok := mod.compiler.(libraryInterface); ok {
  498. return true
  499. }
  500. }
  501. return false
  502. }
  503. func (mod *Module) CcLibraryInterface() bool {
  504. if mod.compiler != nil {
  505. // use build{Static,Shared}() instead of {static,shared}() here because this might be called before
  506. // VariantIs{Static,Shared} is set.
  507. if lib, ok := mod.compiler.(libraryInterface); ok && (lib.buildShared() || lib.buildStatic()) {
  508. return true
  509. }
  510. }
  511. return false
  512. }
  513. func (mod *Module) IsFuzzModule() bool {
  514. if _, ok := mod.compiler.(*fuzzDecorator); ok {
  515. return true
  516. }
  517. return false
  518. }
  519. func (mod *Module) FuzzModuleStruct() fuzz.FuzzModule {
  520. return mod.FuzzModule
  521. }
  522. func (mod *Module) FuzzPackagedModule() fuzz.FuzzPackagedModule {
  523. if fuzzer, ok := mod.compiler.(*fuzzDecorator); ok {
  524. return fuzzer.fuzzPackagedModule
  525. }
  526. panic(fmt.Errorf("FuzzPackagedModule called on non-fuzz module: %q", mod.BaseModuleName()))
  527. }
  528. func (mod *Module) FuzzSharedLibraries() android.RuleBuilderInstalls {
  529. if fuzzer, ok := mod.compiler.(*fuzzDecorator); ok {
  530. return fuzzer.sharedLibraries
  531. }
  532. panic(fmt.Errorf("FuzzSharedLibraries called on non-fuzz module: %q", mod.BaseModuleName()))
  533. }
  534. func (mod *Module) UnstrippedOutputFile() android.Path {
  535. if mod.compiler != nil {
  536. return mod.compiler.unstrippedOutputFilePath()
  537. }
  538. return nil
  539. }
  540. func (mod *Module) IncludeDirs() android.Paths {
  541. if mod.compiler != nil {
  542. if library, ok := mod.compiler.(*libraryDecorator); ok {
  543. return library.includeDirs
  544. }
  545. }
  546. panic(fmt.Errorf("IncludeDirs called on non-library module: %q", mod.BaseModuleName()))
  547. }
  548. func (mod *Module) SetStatic() {
  549. if mod.compiler != nil {
  550. if library, ok := mod.compiler.(libraryInterface); ok {
  551. library.setStatic()
  552. return
  553. }
  554. }
  555. panic(fmt.Errorf("SetStatic called on non-library module: %q", mod.BaseModuleName()))
  556. }
  557. func (mod *Module) SetShared() {
  558. if mod.compiler != nil {
  559. if library, ok := mod.compiler.(libraryInterface); ok {
  560. library.setShared()
  561. return
  562. }
  563. }
  564. panic(fmt.Errorf("SetShared called on non-library module: %q", mod.BaseModuleName()))
  565. }
  566. func (mod *Module) BuildStaticVariant() bool {
  567. if mod.compiler != nil {
  568. if library, ok := mod.compiler.(libraryInterface); ok {
  569. return library.buildStatic()
  570. }
  571. }
  572. panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", mod.BaseModuleName()))
  573. }
  574. func (mod *Module) BuildSharedVariant() bool {
  575. if mod.compiler != nil {
  576. if library, ok := mod.compiler.(libraryInterface); ok {
  577. return library.buildShared()
  578. }
  579. }
  580. panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", mod.BaseModuleName()))
  581. }
  582. func (mod *Module) Module() android.Module {
  583. return mod
  584. }
  585. func (mod *Module) OutputFile() android.OptionalPath {
  586. return mod.outputFile
  587. }
  588. func (mod *Module) CoverageFiles() android.Paths {
  589. if mod.compiler != nil {
  590. return android.Paths{}
  591. }
  592. panic(fmt.Errorf("CoverageFiles called on non-library module: %q", mod.BaseModuleName()))
  593. }
  594. // Rust does not produce gcno files, and therefore does not produce a coverage archive.
  595. func (mod *Module) CoverageOutputFile() android.OptionalPath {
  596. return android.OptionalPath{}
  597. }
  598. func (mod *Module) IsNdk(config android.Config) bool {
  599. return false
  600. }
  601. func (mod *Module) IsStubs() bool {
  602. return false
  603. }
  604. func (mod *Module) installable(apexInfo android.ApexInfo) bool {
  605. if !proptools.BoolDefault(mod.Installable(), mod.EverInstallable()) {
  606. return false
  607. }
  608. // The apex variant is not installable because it is included in the APEX and won't appear
  609. // in the system partition as a standalone file.
  610. if !apexInfo.IsForPlatform() {
  611. return false
  612. }
  613. return mod.OutputFile().Valid() && !mod.Properties.PreventInstall
  614. }
  615. func (ctx moduleContext) apexVariationName() string {
  616. return ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).ApexVariationName
  617. }
  618. var _ cc.LinkableInterface = (*Module)(nil)
  619. func (mod *Module) Init() android.Module {
  620. mod.AddProperties(&mod.Properties)
  621. mod.AddProperties(&mod.VendorProperties)
  622. if mod.afdo != nil {
  623. mod.AddProperties(mod.afdo.props()...)
  624. }
  625. if mod.compiler != nil {
  626. mod.AddProperties(mod.compiler.compilerProps()...)
  627. }
  628. if mod.coverage != nil {
  629. mod.AddProperties(mod.coverage.props()...)
  630. }
  631. if mod.clippy != nil {
  632. mod.AddProperties(mod.clippy.props()...)
  633. }
  634. if mod.sourceProvider != nil {
  635. mod.AddProperties(mod.sourceProvider.SourceProviderProps()...)
  636. }
  637. if mod.sanitize != nil {
  638. mod.AddProperties(mod.sanitize.props()...)
  639. }
  640. android.InitAndroidArchModule(mod, mod.hod, mod.multilib)
  641. android.InitApexModule(mod)
  642. android.InitDefaultableModule(mod)
  643. return mod
  644. }
  645. func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
  646. return &Module{
  647. hod: hod,
  648. multilib: multilib,
  649. }
  650. }
  651. func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
  652. module := newBaseModule(hod, multilib)
  653. module.afdo = &afdo{}
  654. module.coverage = &coverage{}
  655. module.clippy = &clippy{}
  656. module.sanitize = &sanitize{}
  657. return module
  658. }
  659. type ModuleContext interface {
  660. android.ModuleContext
  661. ModuleContextIntf
  662. }
  663. type BaseModuleContext interface {
  664. android.BaseModuleContext
  665. ModuleContextIntf
  666. }
  667. type DepsContext interface {
  668. android.BottomUpMutatorContext
  669. ModuleContextIntf
  670. }
  671. type ModuleContextIntf interface {
  672. RustModule() *Module
  673. toolchain() config.Toolchain
  674. }
  675. type depsContext struct {
  676. android.BottomUpMutatorContext
  677. }
  678. type moduleContext struct {
  679. android.ModuleContext
  680. }
  681. type baseModuleContext struct {
  682. android.BaseModuleContext
  683. }
  684. func (ctx *moduleContext) RustModule() *Module {
  685. return ctx.Module().(*Module)
  686. }
  687. func (ctx *moduleContext) toolchain() config.Toolchain {
  688. return ctx.RustModule().toolchain(ctx)
  689. }
  690. func (ctx *depsContext) RustModule() *Module {
  691. return ctx.Module().(*Module)
  692. }
  693. func (ctx *depsContext) toolchain() config.Toolchain {
  694. return ctx.RustModule().toolchain(ctx)
  695. }
  696. func (ctx *baseModuleContext) RustModule() *Module {
  697. return ctx.Module().(*Module)
  698. }
  699. func (ctx *baseModuleContext) toolchain() config.Toolchain {
  700. return ctx.RustModule().toolchain(ctx)
  701. }
  702. func (mod *Module) nativeCoverage() bool {
  703. // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
  704. if mod.Target().NativeBridge == android.NativeBridgeEnabled {
  705. return false
  706. }
  707. return mod.compiler != nil && mod.compiler.nativeCoverage()
  708. }
  709. func (mod *Module) EverInstallable() bool {
  710. return mod.compiler != nil &&
  711. // Check to see whether the module is actually ever installable.
  712. mod.compiler.everInstallable()
  713. }
  714. func (mod *Module) Installable() *bool {
  715. return mod.Properties.Installable
  716. }
  717. func (mod *Module) ProcMacro() bool {
  718. if pm, ok := mod.compiler.(procMacroInterface); ok {
  719. return pm.ProcMacro()
  720. }
  721. return false
  722. }
  723. func (mod *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
  724. if mod.cachedToolchain == nil {
  725. mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
  726. }
  727. return mod.cachedToolchain
  728. }
  729. func (mod *Module) ccToolchain(ctx android.BaseModuleContext) cc_config.Toolchain {
  730. return cc_config.FindToolchain(ctx.Os(), ctx.Arch())
  731. }
  732. func (d *Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
  733. }
  734. func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
  735. ctx := &moduleContext{
  736. ModuleContext: actx,
  737. }
  738. apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
  739. if !apexInfo.IsForPlatform() {
  740. mod.hideApexVariantFromMake = true
  741. }
  742. toolchain := mod.toolchain(ctx)
  743. mod.makeLinkType = cc.GetMakeLinkType(actx, mod)
  744. mod.Properties.SubName = cc.GetSubnameProperty(actx, mod)
  745. if !toolchain.Supported() {
  746. // This toolchain's unsupported, there's nothing to do for this mod.
  747. return
  748. }
  749. deps := mod.depsToPaths(ctx)
  750. flags := Flags{
  751. Toolchain: toolchain,
  752. }
  753. // Calculate rustc flags
  754. if mod.afdo != nil {
  755. flags, deps = mod.afdo.flags(actx, flags, deps)
  756. }
  757. if mod.compiler != nil {
  758. flags = mod.compiler.compilerFlags(ctx, flags)
  759. flags = mod.compiler.cfgFlags(ctx, flags)
  760. flags = mod.compiler.featureFlags(ctx, flags)
  761. }
  762. if mod.coverage != nil {
  763. flags, deps = mod.coverage.flags(ctx, flags, deps)
  764. }
  765. if mod.clippy != nil {
  766. flags, deps = mod.clippy.flags(ctx, flags, deps)
  767. }
  768. if mod.sanitize != nil {
  769. flags, deps = mod.sanitize.flags(ctx, flags, deps)
  770. }
  771. // SourceProvider needs to call GenerateSource() before compiler calls
  772. // compile() so it can provide the source. A SourceProvider has
  773. // multiple variants (e.g. source, rlib, dylib). Only the "source"
  774. // variant is responsible for effectively generating the source. The
  775. // remaining variants relies on the "source" variant output.
  776. if mod.sourceProvider != nil {
  777. if mod.compiler.(libraryInterface).source() {
  778. mod.sourceProvider.GenerateSource(ctx, deps)
  779. mod.sourceProvider.setSubName(ctx.ModuleSubDir())
  780. } else {
  781. sourceMod := actx.GetDirectDepWithTag(mod.Name(), sourceDepTag)
  782. sourceLib := sourceMod.(*Module).compiler.(*libraryDecorator)
  783. mod.sourceProvider.setOutputFiles(sourceLib.sourceProvider.Srcs())
  784. }
  785. }
  786. if mod.compiler != nil && !mod.compiler.Disabled() {
  787. mod.compiler.initialize(ctx)
  788. buildOutput := mod.compiler.compile(ctx, flags, deps)
  789. if ctx.Failed() {
  790. return
  791. }
  792. mod.outputFile = android.OptionalPathForPath(buildOutput.outputFile)
  793. if buildOutput.kytheFile != nil {
  794. mod.kytheFiles = append(mod.kytheFiles, buildOutput.kytheFile)
  795. }
  796. bloaty.MeasureSizeForPaths(ctx, mod.compiler.strippedOutputFilePath(), android.OptionalPathForPath(mod.compiler.unstrippedOutputFilePath()))
  797. mod.docTimestampFile = mod.compiler.rustdoc(ctx, flags, deps)
  798. if mod.docTimestampFile.Valid() {
  799. ctx.CheckbuildFile(mod.docTimestampFile.Path())
  800. }
  801. // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current or
  802. // RECOVERY_SNAPSHOT_VERSION is current.
  803. if lib, ok := mod.compiler.(snapshotLibraryInterface); ok {
  804. if cc.ShouldCollectHeadersForSnapshot(ctx, mod, apexInfo) {
  805. lib.collectHeadersForSnapshot(ctx, deps)
  806. }
  807. }
  808. apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
  809. if !proptools.BoolDefault(mod.Installable(), mod.EverInstallable()) && !mod.ProcMacro() {
  810. // If the module has been specifically configure to not be installed then
  811. // hide from make as otherwise it will break when running inside make as the
  812. // output path to install will not be specified. Not all uninstallable
  813. // modules can be hidden from make as some are needed for resolving make
  814. // side dependencies. In particular, proc-macros need to be captured in the
  815. // host snapshot.
  816. mod.HideFromMake()
  817. } else if !mod.installable(apexInfo) {
  818. mod.SkipInstall()
  819. }
  820. // Still call install though, the installs will be stored as PackageSpecs to allow
  821. // using the outputs in a genrule.
  822. if mod.OutputFile().Valid() {
  823. mod.compiler.install(ctx)
  824. if ctx.Failed() {
  825. return
  826. }
  827. }
  828. ctx.Phony("rust", ctx.RustModule().OutputFile().Path())
  829. }
  830. }
  831. func (mod *Module) deps(ctx DepsContext) Deps {
  832. deps := Deps{}
  833. if mod.compiler != nil {
  834. deps = mod.compiler.compilerDeps(ctx, deps)
  835. }
  836. if mod.sourceProvider != nil {
  837. deps = mod.sourceProvider.SourceProviderDeps(ctx, deps)
  838. }
  839. if mod.coverage != nil {
  840. deps = mod.coverage.deps(ctx, deps)
  841. }
  842. if mod.sanitize != nil {
  843. deps = mod.sanitize.deps(ctx, deps)
  844. }
  845. deps.Rlibs = android.LastUniqueStrings(deps.Rlibs)
  846. deps.Dylibs = android.LastUniqueStrings(deps.Dylibs)
  847. deps.Rustlibs = android.LastUniqueStrings(deps.Rustlibs)
  848. deps.ProcMacros = android.LastUniqueStrings(deps.ProcMacros)
  849. deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
  850. deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
  851. deps.Stdlibs = android.LastUniqueStrings(deps.Stdlibs)
  852. deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
  853. return deps
  854. }
  855. type dependencyTag struct {
  856. blueprint.BaseDependencyTag
  857. name string
  858. library bool
  859. procMacro bool
  860. dynamic bool
  861. }
  862. // InstallDepNeeded returns true for rlibs, dylibs, and proc macros so that they or their transitive
  863. // dependencies (especially C/C++ shared libs) are installed as dependencies of a rust binary.
  864. func (d dependencyTag) InstallDepNeeded() bool {
  865. return d.library || d.procMacro
  866. }
  867. var _ android.InstallNeededDependencyTag = dependencyTag{}
  868. func (d dependencyTag) LicenseAnnotations() []android.LicenseAnnotation {
  869. if d.library && d.dynamic {
  870. return []android.LicenseAnnotation{android.LicenseAnnotationSharedDependency}
  871. }
  872. return nil
  873. }
  874. var _ android.LicenseAnnotationsDependencyTag = dependencyTag{}
  875. var (
  876. customBindgenDepTag = dependencyTag{name: "customBindgenTag"}
  877. rlibDepTag = dependencyTag{name: "rlibTag", library: true}
  878. dylibDepTag = dependencyTag{name: "dylib", library: true, dynamic: true}
  879. procMacroDepTag = dependencyTag{name: "procMacro", procMacro: true}
  880. testPerSrcDepTag = dependencyTag{name: "rust_unit_tests"}
  881. sourceDepTag = dependencyTag{name: "source"}
  882. dataLibDepTag = dependencyTag{name: "data lib"}
  883. dataBinDepTag = dependencyTag{name: "data bin"}
  884. )
  885. func IsDylibDepTag(depTag blueprint.DependencyTag) bool {
  886. tag, ok := depTag.(dependencyTag)
  887. return ok && tag == dylibDepTag
  888. }
  889. func IsRlibDepTag(depTag blueprint.DependencyTag) bool {
  890. tag, ok := depTag.(dependencyTag)
  891. return ok && tag == rlibDepTag
  892. }
  893. type autoDep struct {
  894. variation string
  895. depTag dependencyTag
  896. }
  897. var (
  898. rlibVariation = "rlib"
  899. dylibVariation = "dylib"
  900. rlibAutoDep = autoDep{variation: rlibVariation, depTag: rlibDepTag}
  901. dylibAutoDep = autoDep{variation: dylibVariation, depTag: dylibDepTag}
  902. )
  903. type autoDeppable interface {
  904. autoDep(ctx android.BottomUpMutatorContext) autoDep
  905. }
  906. func (mod *Module) begin(ctx BaseModuleContext) {
  907. if mod.coverage != nil {
  908. mod.coverage.begin(ctx)
  909. }
  910. if mod.sanitize != nil {
  911. mod.sanitize.begin(ctx)
  912. }
  913. }
  914. func (mod *Module) Prebuilt() *android.Prebuilt {
  915. if p, ok := mod.compiler.(rustPrebuilt); ok {
  916. return p.prebuilt()
  917. }
  918. return nil
  919. }
  920. func rustMakeLibName(ctx android.ModuleContext, c cc.LinkableInterface, dep cc.LinkableInterface, depName string) string {
  921. if rustDep, ok := dep.(*Module); ok {
  922. // Use base module name for snapshots when exporting to Makefile.
  923. if snapshotPrebuilt, ok := rustDep.compiler.(cc.SnapshotInterface); ok {
  924. baseName := rustDep.BaseModuleName()
  925. return baseName + snapshotPrebuilt.SnapshotAndroidMkSuffix() + rustDep.AndroidMkSuffix()
  926. }
  927. }
  928. return cc.MakeLibName(ctx, c, dep, depName)
  929. }
  930. func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
  931. var depPaths PathDeps
  932. directRlibDeps := []*Module{}
  933. directDylibDeps := []*Module{}
  934. directProcMacroDeps := []*Module{}
  935. directSharedLibDeps := []cc.SharedLibraryInfo{}
  936. directStaticLibDeps := [](cc.LinkableInterface){}
  937. directSrcProvidersDeps := []*Module{}
  938. directSrcDeps := [](android.SourceFileProducer){}
  939. // For the dependency from platform to apex, use the latest stubs
  940. mod.apexSdkVersion = android.FutureApiLevel
  941. apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
  942. if !apexInfo.IsForPlatform() {
  943. mod.apexSdkVersion = apexInfo.MinSdkVersion
  944. }
  945. if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
  946. // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
  947. // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
  948. // (b/144430859)
  949. mod.apexSdkVersion = android.FutureApiLevel
  950. }
  951. skipModuleList := map[string]bool{}
  952. var apiImportInfo multitree.ApiImportInfo
  953. hasApiImportInfo := false
  954. ctx.VisitDirectDeps(func(dep android.Module) {
  955. if dep.Name() == "api_imports" {
  956. apiImportInfo = ctx.OtherModuleProvider(dep, multitree.ApiImportsProvider).(multitree.ApiImportInfo)
  957. hasApiImportInfo = true
  958. }
  959. })
  960. if hasApiImportInfo {
  961. targetStubModuleList := map[string]string{}
  962. targetOrigModuleList := map[string]string{}
  963. // Search for dependency which both original module and API imported library with APEX stub exists
  964. ctx.VisitDirectDeps(func(dep android.Module) {
  965. depName := ctx.OtherModuleName(dep)
  966. if apiLibrary, ok := apiImportInfo.ApexSharedLibs[depName]; ok {
  967. targetStubModuleList[apiLibrary] = depName
  968. }
  969. })
  970. ctx.VisitDirectDeps(func(dep android.Module) {
  971. depName := ctx.OtherModuleName(dep)
  972. if origLibrary, ok := targetStubModuleList[depName]; ok {
  973. targetOrigModuleList[origLibrary] = depName
  974. }
  975. })
  976. // Decide which library should be used between original and API imported library
  977. ctx.VisitDirectDeps(func(dep android.Module) {
  978. depName := ctx.OtherModuleName(dep)
  979. if apiLibrary, ok := targetOrigModuleList[depName]; ok {
  980. if cc.ShouldUseStubForApex(ctx, dep) {
  981. skipModuleList[depName] = true
  982. } else {
  983. skipModuleList[apiLibrary] = true
  984. }
  985. }
  986. })
  987. }
  988. ctx.VisitDirectDeps(func(dep android.Module) {
  989. depName := ctx.OtherModuleName(dep)
  990. depTag := ctx.OtherModuleDependencyTag(dep)
  991. if _, exists := skipModuleList[depName]; exists {
  992. return
  993. }
  994. if rustDep, ok := dep.(*Module); ok && !rustDep.CcLibraryInterface() {
  995. //Handle Rust Modules
  996. makeLibName := rustMakeLibName(ctx, mod, rustDep, depName+rustDep.Properties.RustSubName)
  997. switch depTag {
  998. case dylibDepTag:
  999. dylib, ok := rustDep.compiler.(libraryInterface)
  1000. if !ok || !dylib.dylib() {
  1001. ctx.ModuleErrorf("mod %q not an dylib library", depName)
  1002. return
  1003. }
  1004. directDylibDeps = append(directDylibDeps, rustDep)
  1005. mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, makeLibName)
  1006. case rlibDepTag:
  1007. rlib, ok := rustDep.compiler.(libraryInterface)
  1008. if !ok || !rlib.rlib() {
  1009. ctx.ModuleErrorf("mod %q not an rlib library", makeLibName)
  1010. return
  1011. }
  1012. directRlibDeps = append(directRlibDeps, rustDep)
  1013. mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, makeLibName)
  1014. case procMacroDepTag:
  1015. directProcMacroDeps = append(directProcMacroDeps, rustDep)
  1016. mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, makeLibName)
  1017. }
  1018. if android.IsSourceDepTagWithOutputTag(depTag, "") {
  1019. // Since these deps are added in path_properties.go via AddDependencies, we need to ensure the correct
  1020. // OS/Arch variant is used.
  1021. var helper string
  1022. if ctx.Host() {
  1023. helper = "missing 'host_supported'?"
  1024. } else {
  1025. helper = "device module defined?"
  1026. }
  1027. if dep.Target().Os != ctx.Os() {
  1028. ctx.ModuleErrorf("OS mismatch on dependency %q (%s)", dep.Name(), helper)
  1029. return
  1030. } else if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
  1031. ctx.ModuleErrorf("Arch mismatch on dependency %q (%s)", dep.Name(), helper)
  1032. return
  1033. }
  1034. directSrcProvidersDeps = append(directSrcProvidersDeps, rustDep)
  1035. }
  1036. //Append the dependencies exportedDirs, except for proc-macros which target a different arch/OS
  1037. if depTag != procMacroDepTag {
  1038. exportedInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
  1039. depPaths.linkDirs = append(depPaths.linkDirs, exportedInfo.LinkDirs...)
  1040. depPaths.depFlags = append(depPaths.depFlags, exportedInfo.Flags...)
  1041. depPaths.linkObjects = append(depPaths.linkObjects, exportedInfo.LinkObjects...)
  1042. depPaths.LibDeps = append(depPaths.LibDeps, exportedInfo.LibDeps...)
  1043. }
  1044. if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag {
  1045. linkFile := rustDep.UnstrippedOutputFile()
  1046. linkDir := linkPathFromFilePath(linkFile)
  1047. if lib, ok := mod.compiler.(exportedFlagsProducer); ok {
  1048. lib.exportLinkDirs(linkDir)
  1049. }
  1050. }
  1051. } else if ccDep, ok := dep.(cc.LinkableInterface); ok {
  1052. //Handle C dependencies
  1053. makeLibName := cc.MakeLibName(ctx, mod, ccDep, depName)
  1054. if _, ok := ccDep.(*Module); !ok {
  1055. if ccDep.Module().Target().Os != ctx.Os() {
  1056. ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
  1057. return
  1058. }
  1059. if ccDep.Module().Target().Arch.ArchType != ctx.Arch().ArchType {
  1060. ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
  1061. return
  1062. }
  1063. }
  1064. linkObject := ccDep.OutputFile()
  1065. linkPath := linkPathFromFilePath(linkObject.Path())
  1066. if !linkObject.Valid() {
  1067. ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName())
  1068. }
  1069. exportDep := false
  1070. switch {
  1071. case cc.IsStaticDepTag(depTag):
  1072. if cc.IsWholeStaticLib(depTag) {
  1073. // rustc will bundle static libraries when they're passed with "-lstatic=<lib>". This will fail
  1074. // if the library is not prefixed by "lib".
  1075. if mod.Binary() {
  1076. // Binaries may sometimes need to link whole static libraries that don't start with 'lib'.
  1077. // Since binaries don't need to 'rebundle' these like libraries and only use these for the
  1078. // final linkage, pass the args directly to the linker to handle these cases.
  1079. depPaths.depLinkFlags = append(depPaths.depLinkFlags, []string{"-Wl,--whole-archive", linkObject.Path().String(), "-Wl,--no-whole-archive"}...)
  1080. } else if libName, ok := libNameFromFilePath(linkObject.Path()); ok {
  1081. depPaths.depFlags = append(depPaths.depFlags, "-lstatic="+libName)
  1082. depPaths.WholeStaticLibs = append(depPaths.WholeStaticLibs, linkObject.Path())
  1083. } else {
  1084. ctx.ModuleErrorf("'%q' cannot be listed as a whole_static_library in Rust modules unless the output is prefixed by 'lib'", depName, ctx.ModuleName())
  1085. }
  1086. }
  1087. // Add this to linkObjects to pass the library directly to the linker as well. This propagates
  1088. // to dependencies to avoid having to redeclare static libraries for dependents of the dylib variant.
  1089. depPaths.linkObjects = append(depPaths.linkObjects, linkObject.AsPaths()...)
  1090. depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
  1091. exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo)
  1092. depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
  1093. depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
  1094. depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...)
  1095. depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
  1096. directStaticLibDeps = append(directStaticLibDeps, ccDep)
  1097. // Record baseLibName for snapshots.
  1098. mod.Properties.SnapshotStaticLibs = append(mod.Properties.SnapshotStaticLibs, cc.BaseLibName(depName))
  1099. mod.Properties.AndroidMkStaticLibs = append(mod.Properties.AndroidMkStaticLibs, makeLibName)
  1100. case cc.IsSharedDepTag(depTag):
  1101. // For the shared lib dependencies, we may link to the stub variant
  1102. // of the dependency depending on the context (e.g. if this
  1103. // dependency crosses the APEX boundaries).
  1104. sharedLibraryInfo, exportedInfo := cc.ChooseStubOrImpl(ctx, dep)
  1105. // Re-get linkObject as ChooseStubOrImpl actually tells us which
  1106. // object (either from stub or non-stub) to use.
  1107. linkObject = android.OptionalPathForPath(sharedLibraryInfo.SharedLibrary)
  1108. linkPath = linkPathFromFilePath(linkObject.Path())
  1109. depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
  1110. depPaths.linkObjects = append(depPaths.linkObjects, linkObject.AsPaths()...)
  1111. depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
  1112. depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
  1113. depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...)
  1114. depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
  1115. directSharedLibDeps = append(directSharedLibDeps, sharedLibraryInfo)
  1116. // Record baseLibName for snapshots.
  1117. mod.Properties.SnapshotSharedLibs = append(mod.Properties.SnapshotSharedLibs, cc.BaseLibName(depName))
  1118. mod.Properties.AndroidMkSharedLibs = append(mod.Properties.AndroidMkSharedLibs, makeLibName)
  1119. exportDep = true
  1120. case cc.IsHeaderDepTag(depTag):
  1121. exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo)
  1122. depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
  1123. depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
  1124. depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
  1125. case depTag == cc.CrtBeginDepTag:
  1126. depPaths.CrtBegin = append(depPaths.CrtBegin, linkObject.Path())
  1127. case depTag == cc.CrtEndDepTag:
  1128. depPaths.CrtEnd = append(depPaths.CrtEnd, linkObject.Path())
  1129. }
  1130. // Make sure these dependencies are propagated
  1131. if lib, ok := mod.compiler.(exportedFlagsProducer); ok && exportDep {
  1132. lib.exportLinkDirs(linkPath)
  1133. if linkObject.Valid() {
  1134. lib.exportLinkObjects(linkObject.Path())
  1135. }
  1136. }
  1137. } else {
  1138. switch {
  1139. case depTag == cc.CrtBeginDepTag:
  1140. depPaths.CrtBegin = append(depPaths.CrtBegin, android.OutputFileForModule(ctx, dep, ""))
  1141. case depTag == cc.CrtEndDepTag:
  1142. depPaths.CrtEnd = append(depPaths.CrtEnd, android.OutputFileForModule(ctx, dep, ""))
  1143. }
  1144. }
  1145. if srcDep, ok := dep.(android.SourceFileProducer); ok {
  1146. if android.IsSourceDepTagWithOutputTag(depTag, "") {
  1147. // These are usually genrules which don't have per-target variants.
  1148. directSrcDeps = append(directSrcDeps, srcDep)
  1149. }
  1150. }
  1151. })
  1152. var rlibDepFiles RustLibraries
  1153. for _, dep := range directRlibDeps {
  1154. rlibDepFiles = append(rlibDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: dep.CrateName()})
  1155. }
  1156. var dylibDepFiles RustLibraries
  1157. for _, dep := range directDylibDeps {
  1158. dylibDepFiles = append(dylibDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: dep.CrateName()})
  1159. }
  1160. var procMacroDepFiles RustLibraries
  1161. for _, dep := range directProcMacroDeps {
  1162. procMacroDepFiles = append(procMacroDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: dep.CrateName()})
  1163. }
  1164. var libDepFiles android.Paths
  1165. for _, dep := range directStaticLibDeps {
  1166. libDepFiles = append(libDepFiles, dep.OutputFile().Path())
  1167. }
  1168. for _, dep := range directSharedLibDeps {
  1169. if dep.TableOfContents.Valid() {
  1170. libDepFiles = append(libDepFiles, dep.TableOfContents.Path())
  1171. } else {
  1172. libDepFiles = append(libDepFiles, dep.SharedLibrary)
  1173. }
  1174. }
  1175. var srcProviderDepFiles android.Paths
  1176. for _, dep := range directSrcProvidersDeps {
  1177. srcs, _ := dep.OutputFiles("")
  1178. srcProviderDepFiles = append(srcProviderDepFiles, srcs...)
  1179. }
  1180. for _, dep := range directSrcDeps {
  1181. srcs := dep.Srcs()
  1182. srcProviderDepFiles = append(srcProviderDepFiles, srcs...)
  1183. }
  1184. depPaths.RLibs = append(depPaths.RLibs, rlibDepFiles...)
  1185. depPaths.DyLibs = append(depPaths.DyLibs, dylibDepFiles...)
  1186. depPaths.LibDeps = append(depPaths.LibDeps, libDepFiles...)
  1187. depPaths.ProcMacros = append(depPaths.ProcMacros, procMacroDepFiles...)
  1188. depPaths.SrcDeps = append(depPaths.SrcDeps, srcProviderDepFiles...)
  1189. // Dedup exported flags from dependencies
  1190. depPaths.linkDirs = android.FirstUniqueStrings(depPaths.linkDirs)
  1191. depPaths.linkObjects = android.FirstUniquePaths(depPaths.linkObjects)
  1192. depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags)
  1193. depPaths.depClangFlags = android.FirstUniqueStrings(depPaths.depClangFlags)
  1194. depPaths.depIncludePaths = android.FirstUniquePaths(depPaths.depIncludePaths)
  1195. depPaths.depSystemIncludePaths = android.FirstUniquePaths(depPaths.depSystemIncludePaths)
  1196. return depPaths
  1197. }
  1198. func (mod *Module) InstallInData() bool {
  1199. if mod.compiler == nil {
  1200. return false
  1201. }
  1202. return mod.compiler.inData()
  1203. }
  1204. func (mod *Module) InstallInRamdisk() bool {
  1205. return mod.InRamdisk()
  1206. }
  1207. func (mod *Module) InstallInVendorRamdisk() bool {
  1208. return mod.InVendorRamdisk()
  1209. }
  1210. func (mod *Module) InstallInRecovery() bool {
  1211. return mod.InRecovery()
  1212. }
  1213. func linkPathFromFilePath(filepath android.Path) string {
  1214. return strings.Split(filepath.String(), filepath.Base())[0]
  1215. }
  1216. // usePublicApi returns true if the rust variant should link against NDK (publicapi)
  1217. func (r *Module) usePublicApi() bool {
  1218. return r.Device() && r.UseSdk()
  1219. }
  1220. // useVendorApi returns true if the rust variant should link against LLNDK (vendorapi)
  1221. func (r *Module) useVendorApi() bool {
  1222. return r.Device() && (r.InVendor() || r.InProduct())
  1223. }
  1224. func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
  1225. ctx := &depsContext{
  1226. BottomUpMutatorContext: actx,
  1227. }
  1228. deps := mod.deps(ctx)
  1229. var commonDepVariations []blueprint.Variation
  1230. var snapshotInfo *cc.SnapshotInfo
  1231. apiImportInfo := cc.GetApiImports(mod, actx)
  1232. if mod.usePublicApi() || mod.useVendorApi() {
  1233. for idx, lib := range deps.SharedLibs {
  1234. deps.SharedLibs[idx] = cc.GetReplaceModuleName(lib, apiImportInfo.SharedLibs)
  1235. }
  1236. }
  1237. if ctx.Os() == android.Android {
  1238. deps.SharedLibs, _ = cc.RewriteLibs(mod, &snapshotInfo, actx, ctx.Config(), deps.SharedLibs)
  1239. }
  1240. stdLinkage := "dylib-std"
  1241. if mod.compiler.stdLinkage(ctx) == RlibLinkage {
  1242. stdLinkage = "rlib-std"
  1243. }
  1244. rlibDepVariations := commonDepVariations
  1245. if lib, ok := mod.compiler.(libraryInterface); !ok || !lib.sysroot() {
  1246. rlibDepVariations = append(rlibDepVariations,
  1247. blueprint.Variation{Mutator: "rust_stdlinkage", Variation: stdLinkage})
  1248. }
  1249. // rlibs
  1250. rlibDepVariations = append(rlibDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: rlibVariation})
  1251. for _, lib := range deps.Rlibs {
  1252. depTag := rlibDepTag
  1253. lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Rlibs)
  1254. actx.AddVariationDependencies(rlibDepVariations, depTag, lib)
  1255. }
  1256. // dylibs
  1257. actx.AddVariationDependencies(
  1258. append(commonDepVariations, []blueprint.Variation{
  1259. {Mutator: "rust_libraries", Variation: dylibVariation}}...),
  1260. dylibDepTag, deps.Dylibs...)
  1261. // rustlibs
  1262. if deps.Rustlibs != nil && !mod.compiler.Disabled() {
  1263. autoDep := mod.compiler.(autoDeppable).autoDep(ctx)
  1264. for _, lib := range deps.Rustlibs {
  1265. if autoDep.depTag == rlibDepTag {
  1266. // Handle the rlib deptag case
  1267. addRlibDependency(actx, lib, mod, &snapshotInfo, rlibDepVariations)
  1268. } else {
  1269. // autoDep.depTag is a dylib depTag. Not all rustlibs may be available as a dylib however.
  1270. // Check for the existence of the dylib deptag variant. Select it if available,
  1271. // otherwise select the rlib variant.
  1272. autoDepVariations := append(commonDepVariations,
  1273. blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation})
  1274. if actx.OtherModuleDependencyVariantExists(autoDepVariations, lib) {
  1275. actx.AddVariationDependencies(autoDepVariations, autoDep.depTag, lib)
  1276. } else {
  1277. // If there's no dylib dependency available, try to add the rlib dependency instead.
  1278. addRlibDependency(actx, lib, mod, &snapshotInfo, rlibDepVariations)
  1279. }
  1280. }
  1281. }
  1282. }
  1283. // stdlibs
  1284. if deps.Stdlibs != nil {
  1285. if mod.compiler.stdLinkage(ctx) == RlibLinkage {
  1286. for _, lib := range deps.Stdlibs {
  1287. depTag := rlibDepTag
  1288. lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Rlibs)
  1289. actx.AddVariationDependencies(append(commonDepVariations, []blueprint.Variation{{Mutator: "rust_libraries", Variation: "rlib"}}...),
  1290. depTag, lib)
  1291. }
  1292. } else {
  1293. actx.AddVariationDependencies(
  1294. append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"}),
  1295. dylibDepTag, deps.Stdlibs...)
  1296. }
  1297. }
  1298. for _, lib := range deps.SharedLibs {
  1299. depTag := cc.SharedDepTag()
  1300. name, version := cc.StubsLibNameAndVersion(lib)
  1301. variations := []blueprint.Variation{
  1302. {Mutator: "link", Variation: "shared"},
  1303. }
  1304. // For core variant, add a dep on the implementation (if it exists) and its .apiimport (if it exists)
  1305. // GenerateAndroidBuildActions will pick the correct impl/stub based on the api_domain boundary
  1306. if _, ok := apiImportInfo.ApexSharedLibs[name]; !ok || ctx.OtherModuleExists(name) {
  1307. cc.AddSharedLibDependenciesWithVersions(ctx, mod, variations, depTag, name, version, false)
  1308. }
  1309. if apiLibraryName, ok := apiImportInfo.ApexSharedLibs[name]; ok {
  1310. cc.AddSharedLibDependenciesWithVersions(ctx, mod, variations, depTag, apiLibraryName, version, false)
  1311. }
  1312. }
  1313. for _, lib := range deps.WholeStaticLibs {
  1314. depTag := cc.StaticDepTag(true)
  1315. lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).StaticLibs)
  1316. actx.AddVariationDependencies([]blueprint.Variation{
  1317. {Mutator: "link", Variation: "static"},
  1318. }, depTag, lib)
  1319. }
  1320. for _, lib := range deps.StaticLibs {
  1321. depTag := cc.StaticDepTag(false)
  1322. lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).StaticLibs)
  1323. actx.AddVariationDependencies([]blueprint.Variation{
  1324. {Mutator: "link", Variation: "static"},
  1325. }, depTag, lib)
  1326. }
  1327. actx.AddVariationDependencies(nil, cc.HeaderDepTag(), deps.HeaderLibs...)
  1328. crtVariations := cc.GetCrtVariations(ctx, mod)
  1329. for _, crt := range deps.CrtBegin {
  1330. actx.AddVariationDependencies(crtVariations, cc.CrtBeginDepTag,
  1331. cc.GetReplaceModuleName(crt, cc.GetSnapshot(mod, &snapshotInfo, actx).Objects))
  1332. }
  1333. for _, crt := range deps.CrtEnd {
  1334. actx.AddVariationDependencies(crtVariations, cc.CrtEndDepTag,
  1335. cc.GetReplaceModuleName(crt, cc.GetSnapshot(mod, &snapshotInfo, actx).Objects))
  1336. }
  1337. if mod.sourceProvider != nil {
  1338. if bindgen, ok := mod.sourceProvider.(*bindgenDecorator); ok &&
  1339. bindgen.Properties.Custom_bindgen != "" {
  1340. actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), customBindgenDepTag,
  1341. bindgen.Properties.Custom_bindgen)
  1342. }
  1343. }
  1344. actx.AddVariationDependencies([]blueprint.Variation{
  1345. {Mutator: "link", Variation: "shared"},
  1346. }, dataLibDepTag, deps.DataLibs...)
  1347. actx.AddVariationDependencies(nil, dataBinDepTag, deps.DataBins...)
  1348. // proc_macros are compiler plugins, and so we need the host arch variant as a dependendcy.
  1349. actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), procMacroDepTag, deps.ProcMacros...)
  1350. mod.afdo.addDep(ctx, actx)
  1351. }
  1352. // addRlibDependency will add an rlib dependency, rewriting to the snapshot library if available.
  1353. func addRlibDependency(actx android.BottomUpMutatorContext, lib string, mod *Module, snapshotInfo **cc.SnapshotInfo, variations []blueprint.Variation) {
  1354. lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, snapshotInfo, actx).Rlibs)
  1355. actx.AddVariationDependencies(variations, rlibDepTag, lib)
  1356. }
  1357. func BeginMutator(ctx android.BottomUpMutatorContext) {
  1358. if mod, ok := ctx.Module().(*Module); ok && mod.Enabled() {
  1359. mod.beginMutator(ctx)
  1360. }
  1361. }
  1362. func (mod *Module) beginMutator(actx android.BottomUpMutatorContext) {
  1363. ctx := &baseModuleContext{
  1364. BaseModuleContext: actx,
  1365. }
  1366. mod.begin(ctx)
  1367. }
  1368. func (mod *Module) Name() string {
  1369. name := mod.ModuleBase.Name()
  1370. if p, ok := mod.compiler.(interface {
  1371. Name(string) string
  1372. }); ok {
  1373. name = p.Name(name)
  1374. }
  1375. return name
  1376. }
  1377. func (mod *Module) disableClippy() {
  1378. if mod.clippy != nil {
  1379. mod.clippy.Properties.Clippy_lints = proptools.StringPtr("none")
  1380. }
  1381. }
  1382. var _ android.HostToolProvider = (*Module)(nil)
  1383. var _ snapshot.RelativeInstallPath = (*Module)(nil)
  1384. func (mod *Module) HostToolPath() android.OptionalPath {
  1385. if !mod.Host() {
  1386. return android.OptionalPath{}
  1387. }
  1388. if binary, ok := mod.compiler.(*binaryDecorator); ok {
  1389. return android.OptionalPathForPath(binary.baseCompiler.path)
  1390. } else if pm, ok := mod.compiler.(*procMacroDecorator); ok {
  1391. // Even though proc-macros aren't strictly "tools", since they target the compiler
  1392. // and act as compiler plugins, we treat them similarly.
  1393. return android.OptionalPathForPath(pm.baseCompiler.path)
  1394. }
  1395. return android.OptionalPath{}
  1396. }
  1397. var _ android.ApexModule = (*Module)(nil)
  1398. func (mod *Module) MinSdkVersion() string {
  1399. return String(mod.Properties.Min_sdk_version)
  1400. }
  1401. // Implements android.ApexModule
  1402. func (mod *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
  1403. minSdkVersion := mod.MinSdkVersion()
  1404. if minSdkVersion == "apex_inherit" {
  1405. return nil
  1406. }
  1407. if minSdkVersion == "" {
  1408. return fmt.Errorf("min_sdk_version is not specificed")
  1409. }
  1410. // Not using nativeApiLevelFromUser because the context here is not
  1411. // necessarily a native context.
  1412. ver, err := android.ApiLevelFromUser(ctx, minSdkVersion)
  1413. if err != nil {
  1414. return err
  1415. }
  1416. if ver.GreaterThan(sdkVersion) {
  1417. return fmt.Errorf("newer SDK(%v)", ver)
  1418. }
  1419. return nil
  1420. }
  1421. // Implements android.ApexModule
  1422. func (mod *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
  1423. depTag := ctx.OtherModuleDependencyTag(dep)
  1424. if ccm, ok := dep.(*cc.Module); ok {
  1425. if ccm.HasStubsVariants() {
  1426. if cc.IsSharedDepTag(depTag) {
  1427. // dynamic dep to a stubs lib crosses APEX boundary
  1428. return false
  1429. }
  1430. if cc.IsRuntimeDepTag(depTag) {
  1431. // runtime dep to a stubs lib also crosses APEX boundary
  1432. return false
  1433. }
  1434. if cc.IsHeaderDepTag(depTag) {
  1435. return false
  1436. }
  1437. }
  1438. if mod.Static() && cc.IsSharedDepTag(depTag) {
  1439. // shared_lib dependency from a static lib is considered as crossing
  1440. // the APEX boundary because the dependency doesn't actually is
  1441. // linked; the dependency is used only during the compilation phase.
  1442. return false
  1443. }
  1444. }
  1445. if depTag == procMacroDepTag || depTag == customBindgenDepTag {
  1446. return false
  1447. }
  1448. return true
  1449. }
  1450. // Overrides ApexModule.IsInstallabeToApex()
  1451. func (mod *Module) IsInstallableToApex() bool {
  1452. if mod.compiler != nil {
  1453. if lib, ok := mod.compiler.(libraryInterface); ok && (lib.shared() || lib.dylib()) {
  1454. return true
  1455. }
  1456. if _, ok := mod.compiler.(*binaryDecorator); ok {
  1457. return true
  1458. }
  1459. }
  1460. return false
  1461. }
  1462. // If a library file has a "lib" prefix, extract the library name without the prefix.
  1463. func libNameFromFilePath(filepath android.Path) (string, bool) {
  1464. libName := strings.TrimSuffix(filepath.Base(), filepath.Ext())
  1465. if strings.HasPrefix(libName, "lib") {
  1466. libName = libName[3:]
  1467. return libName, true
  1468. }
  1469. return "", false
  1470. }
  1471. func kytheExtractRustFactory() android.Singleton {
  1472. return &kytheExtractRustSingleton{}
  1473. }
  1474. type kytheExtractRustSingleton struct {
  1475. }
  1476. func (k kytheExtractRustSingleton) GenerateBuildActions(ctx android.SingletonContext) {
  1477. var xrefTargets android.Paths
  1478. ctx.VisitAllModules(func(module android.Module) {
  1479. if rustModule, ok := module.(xref); ok {
  1480. xrefTargets = append(xrefTargets, rustModule.XrefRustFiles()...)
  1481. }
  1482. })
  1483. if len(xrefTargets) > 0 {
  1484. ctx.Phony("xref_rust", xrefTargets...)
  1485. }
  1486. }
  1487. func (c *Module) Partition() string {
  1488. return ""
  1489. }
  1490. var Bool = proptools.Bool
  1491. var BoolDefault = proptools.BoolDefault
  1492. var String = proptools.String
  1493. var StringPtr = proptools.StringPtr
  1494. var _ android.OutputFileProducer = (*Module)(nil)