blob: de59f39ac7ab4b5fb060d409067ed4b841e82444 [file] [log] [blame]
Ivan Lozanoffee3342019-08-27 12:03:00 -07001// 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
15package rust
16
17import (
18 "fmt"
19 "path/filepath"
Ivan Lozano45a9e312021-07-27 12:29:12 -040020 "strings"
Ivan Lozanoffee3342019-08-27 12:03:00 -070021
Ivan Lozanoad8b18b2019-10-31 19:38:29 -070022 "github.com/google/blueprint/proptools"
23
Ivan Lozanoffee3342019-08-27 12:03:00 -070024 "android/soong/android"
25 "android/soong/rust/config"
26)
27
Ivan Lozanodd055472020-09-28 13:22:45 -040028type RustLinkage int
29
30const (
31 DefaultLinkage RustLinkage = iota
32 RlibLinkage
33 DylibLinkage
34)
35
Thiébaud Weksteene81c9242020-08-03 10:46:28 +020036func (compiler *baseCompiler) edition() string {
Chih-Hung Hsieh961a30c2019-10-03 09:47:06 -070037 return proptools.StringDefault(compiler.Properties.Edition, config.DefaultEdition)
38}
39
Matthew Maurer99020b02019-10-31 10:44:40 -070040func (compiler *baseCompiler) setNoStdlibs() {
41 compiler.Properties.No_stdlibs = proptools.BoolPtr(true)
42}
43
Thiébaud Weksteen9e8451e2020-08-13 12:55:59 +020044func (compiler *baseCompiler) disableLints() {
45 compiler.Properties.Lints = proptools.StringPtr("none")
Stephen Craneda931d42020-08-04 13:02:28 -070046}
47
Chih-Hung Hsieh9a4a7ba2019-12-12 19:36:05 -080048func NewBaseCompiler(dir, dir64 string, location installLocation) *baseCompiler {
Ivan Lozanoffee3342019-08-27 12:03:00 -070049 return &baseCompiler{
Chih-Hung Hsieh961a30c2019-10-03 09:47:06 -070050 Properties: BaseCompilerProperties{},
51 dir: dir,
52 dir64: dir64,
Chih-Hung Hsieh9a4a7ba2019-12-12 19:36:05 -080053 location: location,
Ivan Lozanoffee3342019-08-27 12:03:00 -070054 }
55}
56
Chih-Hung Hsieh9a4a7ba2019-12-12 19:36:05 -080057type installLocation int
58
59const (
60 InstallInSystem installLocation = 0
61 InstallInData = iota
Ivan Lozano43845682020-07-09 21:03:28 -040062
63 incorrectSourcesError = "srcs can only contain one path for a rust file and source providers prefixed by \":\""
Thiébaud Weksteenee6a89b2021-02-25 16:30:57 +010064 genSubDir = "out/"
Chih-Hung Hsieh9a4a7ba2019-12-12 19:36:05 -080065)
66
Ivan Lozanoffee3342019-08-27 12:03:00 -070067type BaseCompilerProperties struct {
Ivan Lozano8a23fa42020-06-16 10:26:57 -040068 // path to the source file that is the main entry point of the program (e.g. main.rs or lib.rs)
69 Srcs []string `android:"path,arch_variant"`
70
Thiébaud Weksteen9e8451e2020-08-13 12:55:59 +020071 // name of the lint set that should be used to validate this module.
72 //
73 // Possible values are "default" (for using a sensible set of lints
74 // depending on the module's location), "android" (for the strictest
75 // lint set that applies to all Android platform code), "vendor" (for
76 // a relaxed set) and "none" (for ignoring all lint warnings and
77 // errors). The default value is "default".
78 Lints *string
Chih-Hung Hsiehefdd7ac2019-09-26 18:59:27 -070079
Thiébaud Weksteenc44e7372021-04-07 14:53:06 +020080 // flags to pass to rustc. To enable configuration options or features, use the "cfgs" or "features" properties.
Liz Kammereda93982021-04-20 10:15:41 -040081 Flags []string `android:"arch_variant"`
Ivan Lozanoffee3342019-08-27 12:03:00 -070082
83 // flags to pass to the linker
Liz Kammereda93982021-04-20 10:15:41 -040084 Ld_flags []string `android:"arch_variant"`
Ivan Lozanoffee3342019-08-27 12:03:00 -070085
86 // list of rust rlib crate dependencies
87 Rlibs []string `android:"arch_variant"`
88
89 // list of rust dylib crate dependencies
90 Dylibs []string `android:"arch_variant"`
91
Matthew Maurer0f003b12020-06-29 14:34:06 -070092 // list of rust automatic crate dependencies
93 Rustlibs []string `android:"arch_variant"`
94
Ivan Lozanoffee3342019-08-27 12:03:00 -070095 // list of rust proc_macro crate dependencies
96 Proc_macros []string `android:"arch_variant"`
97
98 // list of C shared library dependencies
99 Shared_libs []string `android:"arch_variant"`
100
Ivan Lozano63bb7682021-03-23 15:53:44 -0400101 // list of C static library dependencies. These dependencies do not normally propagate to dependents
102 // and may need to be redeclared. See whole_static_libs for bundling static dependencies into a library.
Ivan Lozanoffee3342019-08-27 12:03:00 -0700103 Static_libs []string `android:"arch_variant"`
104
Ivan Lozano63bb7682021-03-23 15:53:44 -0400105 // Similar to static_libs, but will bundle the static library dependency into a library. This is helpful
106 // to avoid having to redeclare the dependency for dependents of this library, but in some cases may also
107 // result in bloat if multiple dependencies all include the same static library whole.
108 //
109 // The common use case for this is when the static library is unlikely to be a dependency of other modules to avoid
110 // having to redeclare the static library dependency for every dependent module.
111 // If you are not sure what to, for rust_library modules most static dependencies should go in static_libraries,
112 // and for rust_ffi modules most static dependencies should go into whole_static_libraries.
113 //
114 // For rust_ffi static variants, these libraries will be included in the resulting static library archive.
115 //
116 // For rust_library rlib variants, these libraries will be bundled into the resulting rlib library. This will
117 // include all of the static libraries symbols in any dylibs or binaries which use this rlib as well.
118 Whole_static_libs []string `android:"arch_variant"`
119
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400120 // crate name, required for modules which produce Rust libraries: rust_library, rust_ffi and SourceProvider
121 // modules which create library variants (rust_bindgen). This must be the expected extern crate name used in
122 // source, and is required to conform to an enforced format matching library output files (if the output file is
123 // lib<someName><suffix>, the crate_name property must be <someName>).
Ivan Lozanoffee3342019-08-27 12:03:00 -0700124 Crate_name string `android:"arch_variant"`
125
126 // list of features to enable for this crate
127 Features []string `android:"arch_variant"`
128
Thiébaud Weksteenc44e7372021-04-07 14:53:06 +0200129 // list of configuration options to enable for this crate. To enable features, use the "features" property.
130 Cfgs []string `android:"arch_variant"`
131
Ivan Lozanoffee3342019-08-27 12:03:00 -0700132 // specific rust edition that should be used if the default version is not desired
133 Edition *string `android:"arch_variant"`
134
135 // sets name of the output
136 Stem *string `android:"arch_variant"`
137
138 // append to name of output
139 Suffix *string `android:"arch_variant"`
140
141 // install to a subdirectory of the default install path for the module
142 Relative_install_path *string `android:"arch_variant"`
Matthew Maurer99020b02019-10-31 10:44:40 -0700143
144 // whether to suppress inclusion of standard crates - defaults to false
145 No_stdlibs *bool
Ivan Lozanoea086132020-12-08 14:43:00 -0500146
147 // Change the rustlibs linkage to select rlib linkage by default for device targets.
148 // Also link libstd as an rlib as well on device targets.
149 // Note: This is the default behavior for host targets.
150 //
151 // This is primarily meant for rust_binary and rust_ffi modules where the default
152 // linkage of libstd might need to be overridden in some use cases. This should
153 // generally be avoided with other module types since it may cause collisions at
154 // linkage if all dependencies of the root binary module do not link against libstd\
155 // the same way.
156 Prefer_rlib *bool `android:"arch_variant"`
Ivan Lozanoffee3342019-08-27 12:03:00 -0700157}
158
159type baseCompiler struct {
Joel Galensonfa049382021-01-14 16:03:18 -0800160 Properties BaseCompilerProperties
Ivan Lozanoffee3342019-08-27 12:03:00 -0700161
162 // Install related
163 dir string
164 dir64 string
165 subDir string
166 relative string
Colin Cross70dda7e2019-10-01 22:05:35 -0700167 path android.InstallPath
Chih-Hung Hsieh9a4a7ba2019-12-12 19:36:05 -0800168 location installLocation
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500169 sanitize *sanitize
Ivan Lozano8a23fa42020-06-16 10:26:57 -0400170
Joel Galensonfa049382021-01-14 16:03:18 -0800171 distFile android.OptionalPath
Thiébaud Weksteenfabaff62020-08-27 13:48:36 +0200172 // Stripped output file. If Valid(), this file will be installed instead of outputFile.
173 strippedOutputFile android.OptionalPath
Thiébaud Weksteenee6a89b2021-02-25 16:30:57 +0100174
175 // If a crate has a source-generated dependency, a copy of the source file
176 // will be available in cargoOutDir (equivalent to Cargo OUT_DIR).
177 cargoOutDir android.ModuleOutPath
Ivan Lozanoffee3342019-08-27 12:03:00 -0700178}
179
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400180func (compiler *baseCompiler) Disabled() bool {
181 return false
182}
183
184func (compiler *baseCompiler) SetDisabled() {
185 panic("baseCompiler does not implement SetDisabled()")
186}
187
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400188func (compiler *baseCompiler) coverageOutputZipPath() android.OptionalPath {
189 panic("baseCompiler does not implement coverageOutputZipPath()")
190}
191
Ivan Lozanoea086132020-12-08 14:43:00 -0500192func (compiler *baseCompiler) preferRlib() bool {
193 return Bool(compiler.Properties.Prefer_rlib)
194}
195
Ivan Lozanodd055472020-09-28 13:22:45 -0400196func (compiler *baseCompiler) stdLinkage(ctx *depsContext) RustLinkage {
Ivan Lozano2b081132020-09-08 12:46:52 -0400197 // For devices, we always link stdlibs in as dylibs by default.
Ivan Lozanoea086132020-12-08 14:43:00 -0500198 if compiler.preferRlib() {
199 return RlibLinkage
200 } else if ctx.Device() {
Ivan Lozanodd055472020-09-28 13:22:45 -0400201 return DylibLinkage
Ivan Lozano2b081132020-09-08 12:46:52 -0400202 } else {
Ivan Lozanodd055472020-09-28 13:22:45 -0400203 return RlibLinkage
Ivan Lozano2b081132020-09-08 12:46:52 -0400204 }
Ivan Lozano042504f2020-08-18 14:31:23 -0400205}
206
Ivan Lozanoffee3342019-08-27 12:03:00 -0700207var _ compiler = (*baseCompiler)(nil)
208
Chih-Hung Hsieh9a4a7ba2019-12-12 19:36:05 -0800209func (compiler *baseCompiler) inData() bool {
210 return compiler.location == InstallInData
211}
212
Ivan Lozanoffee3342019-08-27 12:03:00 -0700213func (compiler *baseCompiler) compilerProps() []interface{} {
214 return []interface{}{&compiler.Properties}
215}
216
Thiébaud Weksteenc44e7372021-04-07 14:53:06 +0200217func (compiler *baseCompiler) cfgsToFlags() []string {
Ivan Lozanoffee3342019-08-27 12:03:00 -0700218 flags := []string{}
Thiébaud Weksteenc44e7372021-04-07 14:53:06 +0200219 for _, cfg := range compiler.Properties.Cfgs {
220 flags = append(flags, "--cfg '"+cfg+"'")
221 }
222 return flags
223}
224
225func (compiler *baseCompiler) featuresToFlags() []string {
226 flags := []string{}
227 for _, feature := range compiler.Properties.Features {
Ivan Lozanoffee3342019-08-27 12:03:00 -0700228 flags = append(flags, "--cfg 'feature=\""+feature+"\"'")
229 }
230 return flags
231}
232
233func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flags {
234
Thiébaud Weksteen9e8451e2020-08-13 12:55:59 +0200235 lintFlags, err := config.RustcLintsForDir(ctx.ModuleDir(), compiler.Properties.Lints)
236 if err != nil {
237 ctx.PropertyErrorf("lints", err.Error())
Chih-Hung Hsiehefdd7ac2019-09-26 18:59:27 -0700238 }
Ivan Lozano45a9e312021-07-27 12:29:12 -0400239
240 // linkage-related flags are disallowed.
241 for _, s := range compiler.Properties.Ld_flags {
242 if strings.HasPrefix(s, "-Wl,-l") || strings.HasPrefix(s, "-Wl,-L") {
243 ctx.PropertyErrorf("ld_flags", "'-Wl,-l' and '-Wl,-L' flags cannot be manually specified")
244 }
245 }
246 for _, s := range compiler.Properties.Flags {
247 if strings.HasPrefix(s, "-l") || strings.HasPrefix(s, "-L") {
248 ctx.PropertyErrorf("flags", "'-l' and '-L' flags cannot be manually specified")
249 }
250 if strings.HasPrefix(s, "--extern") {
251 ctx.PropertyErrorf("flags", "'--extern' flag cannot be manually specified")
252 }
253 if strings.HasPrefix(s, "-Clink-args=") || strings.HasPrefix(s, "-C link-args=") {
254 ctx.PropertyErrorf("flags", "'-C link-args' flag cannot be manually specified")
255 }
256 }
257
Thiébaud Weksteen9e8451e2020-08-13 12:55:59 +0200258 flags.RustFlags = append(flags.RustFlags, lintFlags)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700259 flags.RustFlags = append(flags.RustFlags, compiler.Properties.Flags...)
Thiébaud Weksteenc44e7372021-04-07 14:53:06 +0200260 flags.RustFlags = append(flags.RustFlags, compiler.cfgsToFlags()...)
261 flags.RustFlags = append(flags.RustFlags, compiler.featuresToFlags()...)
Dan Albert06feee92021-03-19 15:06:02 -0700262 flags.RustdocFlags = append(flags.RustdocFlags, compiler.cfgsToFlags()...)
263 flags.RustdocFlags = append(flags.RustdocFlags, compiler.featuresToFlags()...)
Thiébaud Weksteene81c9242020-08-03 10:46:28 +0200264 flags.RustFlags = append(flags.RustFlags, "--edition="+compiler.edition())
Dan Albert06feee92021-03-19 15:06:02 -0700265 flags.RustdocFlags = append(flags.RustdocFlags, "--edition="+compiler.edition())
Ivan Lozanoffee3342019-08-27 12:03:00 -0700266 flags.LinkFlags = append(flags.LinkFlags, compiler.Properties.Ld_flags...)
Joel Galenson724286c2019-09-30 13:01:37 -0700267 flags.GlobalRustFlags = append(flags.GlobalRustFlags, config.GlobalRustFlags...)
Ivan Lozanof1c84332019-09-20 11:00:37 -0700268 flags.GlobalRustFlags = append(flags.GlobalRustFlags, ctx.toolchain().ToolchainRustFlags())
269 flags.GlobalLinkFlags = append(flags.GlobalLinkFlags, ctx.toolchain().ToolchainLinkFlags())
Ivan Lozanoffee3342019-08-27 12:03:00 -0700270
271 if ctx.Host() && !ctx.Windows() {
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800272 rpathPrefix := `\$$ORIGIN/`
Ivan Lozanoffee3342019-08-27 12:03:00 -0700273 if ctx.Darwin() {
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800274 rpathPrefix = "@loader_path/"
Ivan Lozanoffee3342019-08-27 12:03:00 -0700275 }
276
277 var rpath string
278 if ctx.toolchain().Is64Bit() {
279 rpath = "lib64"
280 } else {
281 rpath = "lib"
282 }
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800283 flags.LinkFlags = append(flags.LinkFlags, "-Wl,-rpath,"+rpathPrefix+rpath)
284 flags.LinkFlags = append(flags.LinkFlags, "-Wl,-rpath,"+rpathPrefix+"../"+rpath)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700285 }
286
Ivan Lozanof76cdf72021-02-12 09:55:06 -0500287 if ctx.RustModule().UseVndk() {
288 flags.RustFlags = append(flags.RustFlags, "--cfg 'android_vndk'")
289 }
290
Ivan Lozanoffee3342019-08-27 12:03:00 -0700291 return flags
292}
293
294func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path {
295 panic(fmt.Errorf("baseCrater doesn't know how to crate things!"))
296}
297
Dan Albert06feee92021-03-19 15:06:02 -0700298func (compiler *baseCompiler) rustdoc(ctx ModuleContext, flags Flags,
299 deps PathDeps) android.OptionalPath {
300
301 return android.OptionalPath{}
302}
303
Thiébaud Weksteenee6a89b2021-02-25 16:30:57 +0100304func (compiler *baseCompiler) initialize(ctx ModuleContext) {
305 compiler.cargoOutDir = android.PathForModuleOut(ctx, genSubDir)
306}
307
308func (compiler *baseCompiler) CargoOutDir() android.OptionalPath {
309 return android.OptionalPathForPath(compiler.cargoOutDir)
310}
311
Jiyong Parke54f07e2021-04-07 15:08:04 +0900312func (compiler *baseCompiler) strippedOutputFilePath() android.OptionalPath {
313 return compiler.strippedOutputFile
314}
315
Ivan Lozanoffee3342019-08-27 12:03:00 -0700316func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps {
317 deps.Rlibs = append(deps.Rlibs, compiler.Properties.Rlibs...)
318 deps.Dylibs = append(deps.Dylibs, compiler.Properties.Dylibs...)
Matthew Maurer0f003b12020-06-29 14:34:06 -0700319 deps.Rustlibs = append(deps.Rustlibs, compiler.Properties.Rustlibs...)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700320 deps.ProcMacros = append(deps.ProcMacros, compiler.Properties.Proc_macros...)
321 deps.StaticLibs = append(deps.StaticLibs, compiler.Properties.Static_libs...)
Ivan Lozano63bb7682021-03-23 15:53:44 -0400322 deps.WholeStaticLibs = append(deps.WholeStaticLibs, compiler.Properties.Whole_static_libs...)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700323 deps.SharedLibs = append(deps.SharedLibs, compiler.Properties.Shared_libs...)
324
Matthew Maurer99020b02019-10-31 10:44:40 -0700325 if !Bool(compiler.Properties.No_stdlibs) {
326 for _, stdlib := range config.Stdlibs {
Jiyong Parkb5d2dd22020-08-31 17:22:01 +0900327 // If we're building for the primary arch of the build host, use the compiler's stdlibs
Colin Cross0c66bc62021-07-20 09:47:41 -0700328 if ctx.Target().Os == ctx.Config().BuildOS {
Matthew Maurer99020b02019-10-31 10:44:40 -0700329 stdlib = stdlib + "_" + ctx.toolchain().RustTriple()
330 }
Ivan Lozano2b081132020-09-08 12:46:52 -0400331 deps.Stdlibs = append(deps.Stdlibs, stdlib)
Matthew Maurer99020b02019-10-31 10:44:40 -0700332 }
333 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700334 return deps
335}
336
Thiébaud Weksteenf1ff54a2021-03-22 14:24:54 +0100337func bionicDeps(ctx DepsContext, deps Deps, static bool) Deps {
Ivan Lozanobf63d002020-10-02 10:03:23 -0400338 bionicLibs := []string{}
339 bionicLibs = append(bionicLibs, "liblog")
340 bionicLibs = append(bionicLibs, "libc")
341 bionicLibs = append(bionicLibs, "libm")
342 bionicLibs = append(bionicLibs, "libdl")
343
344 if static {
345 deps.StaticLibs = append(deps.StaticLibs, bionicLibs...)
346 } else {
347 deps.SharedLibs = append(deps.SharedLibs, bionicLibs...)
348 }
Ivan Lozanof1c84332019-09-20 11:00:37 -0700349
Thiébaud Weksteenf1ff54a2021-03-22 14:24:54 +0100350 if libRuntimeBuiltins := config.BuiltinsRuntimeLibrary(ctx.toolchain()); libRuntimeBuiltins != "" {
351 deps.StaticLibs = append(deps.StaticLibs, libRuntimeBuiltins)
352 }
Ivan Lozanof1c84332019-09-20 11:00:37 -0700353 return deps
354}
355
Ivan Lozanoffee3342019-08-27 12:03:00 -0700356func (compiler *baseCompiler) crateName() string {
357 return compiler.Properties.Crate_name
358}
359
Ivan Lozanod7586b62021-04-01 09:49:36 -0400360func (compiler *baseCompiler) everInstallable() bool {
361 // Most modules are installable, so return true by default.
362 return true
363}
364
Colin Cross70dda7e2019-10-01 22:05:35 -0700365func (compiler *baseCompiler) installDir(ctx ModuleContext) android.InstallPath {
Ivan Lozanoffee3342019-08-27 12:03:00 -0700366 dir := compiler.dir
367 if ctx.toolchain().Is64Bit() && compiler.dir64 != "" {
368 dir = compiler.dir64
369 }
Ivan Lozanod6fdca82020-04-07 12:30:33 -0400370 if ctx.Target().NativeBridge == android.NativeBridgeEnabled {
371 dir = filepath.Join(dir, ctx.Target().NativeBridgeRelativePath)
372 }
373 if !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) {
Ivan Lozanoffee3342019-08-27 12:03:00 -0700374 dir = filepath.Join(dir, ctx.Arch().ArchType.String())
375 }
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400376
377 if compiler.location == InstallInData && ctx.RustModule().UseVndk() {
378 dir = filepath.Join(dir, "vendor")
379 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700380 return android.PathForModuleInstall(ctx, dir, compiler.subDir,
381 compiler.relativeInstallPath(), compiler.relative)
382}
383
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400384func (compiler *baseCompiler) nativeCoverage() bool {
385 return false
386}
387
Thiébaud Weksteenfabaff62020-08-27 13:48:36 +0200388func (compiler *baseCompiler) install(ctx ModuleContext) {
Jiyong Parke54f07e2021-04-07 15:08:04 +0900389 path := ctx.RustModule().OutputFile()
Thiébaud Weksteenfabaff62020-08-27 13:48:36 +0200390 compiler.path = ctx.InstallFile(compiler.installDir(ctx), path.Path().Base(), path.Path())
Ivan Lozanoffee3342019-08-27 12:03:00 -0700391}
392
393func (compiler *baseCompiler) getStem(ctx ModuleContext) string {
394 return compiler.getStemWithoutSuffix(ctx) + String(compiler.Properties.Suffix)
395}
396
397func (compiler *baseCompiler) getStemWithoutSuffix(ctx BaseModuleContext) string {
Thiébaud Weksteen1f7f70f2020-06-24 11:32:48 +0200398 stem := ctx.ModuleName()
Ivan Lozanoffee3342019-08-27 12:03:00 -0700399 if String(compiler.Properties.Stem) != "" {
400 stem = String(compiler.Properties.Stem)
401 }
402
403 return stem
404}
Ivan Lozanoad8b18b2019-10-31 19:38:29 -0700405
Ivan Lozanoffee3342019-08-27 12:03:00 -0700406func (compiler *baseCompiler) relativeInstallPath() string {
407 return String(compiler.Properties.Relative_install_path)
408}
409
Ivan Lozano43845682020-07-09 21:03:28 -0400410// Returns the Path for the main source file along with Paths for generated source files from modules listed in srcs.
Chih-Hung Hsiehbbd25ae2020-05-15 17:36:30 -0700411func srcPathFromModuleSrcs(ctx ModuleContext, srcs []string) (android.Path, android.Paths) {
412 // The srcs can contain strings with prefix ":".
413 // They are dependent modules of this module, with android.SourceDepTag.
414 // They are not the main source file compiled by rustc.
415 numSrcs := 0
416 srcIndex := 0
417 for i, s := range srcs {
418 if android.SrcIsModule(s) == "" {
419 numSrcs++
420 srcIndex = i
421 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700422 }
Chih-Hung Hsiehbbd25ae2020-05-15 17:36:30 -0700423 if numSrcs != 1 {
Ivan Lozano43845682020-07-09 21:03:28 -0400424 ctx.PropertyErrorf("srcs", incorrectSourcesError)
Chih-Hung Hsiehbbd25ae2020-05-15 17:36:30 -0700425 }
426 if srcIndex != 0 {
427 ctx.PropertyErrorf("srcs", "main source file must be the first in srcs")
428 }
429 paths := android.PathsForModuleSrc(ctx, srcs)
Ivan Lozano43845682020-07-09 21:03:28 -0400430 return paths[srcIndex], paths[1:]
Ivan Lozanoffee3342019-08-27 12:03:00 -0700431}