blob: 17fd2d8be88ab79b7c7ea3252262dacd2e146362 [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 (
Ivan Lozanoffee3342019-08-27 12:03:00 -070018 "path/filepath"
Ivan Lozanoffee3342019-08-27 12:03:00 -070019
20 "android/soong/android"
21)
22
23type AndroidMkContext interface {
24 Name() string
25 Target() android.Target
Liz Kammer4018a8d2020-11-24 09:35:21 -080026 SubAndroidMk(*android.AndroidMkEntries, interface{})
Ivan Lozanoffee3342019-08-27 12:03:00 -070027}
28
Andrei Homescuc7767922020-08-05 06:36:19 -070029type SubAndroidMkProvider interface {
Liz Kammer4018a8d2020-11-24 09:35:21 -080030 AndroidMk(AndroidMkContext, *android.AndroidMkEntries)
Ivan Lozanoffee3342019-08-27 12:03:00 -070031}
32
Liz Kammer4018a8d2020-11-24 09:35:21 -080033func (mod *Module) SubAndroidMk(data *android.AndroidMkEntries, obj interface{}) {
Ivan Lozanoffee3342019-08-27 12:03:00 -070034 if mod.subAndroidMkOnce == nil {
Andrei Homescuc7767922020-08-05 06:36:19 -070035 mod.subAndroidMkOnce = make(map[SubAndroidMkProvider]bool)
Ivan Lozanoffee3342019-08-27 12:03:00 -070036 }
Andrei Homescuc7767922020-08-05 06:36:19 -070037 if androidmk, ok := obj.(SubAndroidMkProvider); ok {
Ivan Lozanoffee3342019-08-27 12:03:00 -070038 if !mod.subAndroidMkOnce[androidmk] {
39 mod.subAndroidMkOnce[androidmk] = true
40 androidmk.AndroidMk(mod, data)
41 }
42 }
43}
44
Justin Yun24b246a2023-03-16 10:36:16 +090045func (mod *Module) AndroidMkSuffix() string {
46 return mod.Properties.RustSubName + mod.Properties.SubName
47}
48
Liz Kammer4018a8d2020-11-24 09:35:21 -080049func (mod *Module) AndroidMkEntries() []android.AndroidMkEntries {
Jiyong Park99644e92020-11-17 22:21:02 +090050 if mod.Properties.HideFromMake || mod.hideApexVariantFromMake {
Liz Kammer4018a8d2020-11-24 09:35:21 -080051
52 return []android.AndroidMkEntries{android.AndroidMkEntries{Disabled: true}}
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -040053 }
54
Liz Kammer4018a8d2020-11-24 09:35:21 -080055 ret := android.AndroidMkEntries{
Ivan Lozano8d10fc32021-11-05 16:36:47 -040056 OutputFile: android.OptionalPathForPath(mod.UnstrippedOutputFile()),
Ivan Lozanod06cc742021-11-12 13:27:58 -050057 Include: "$(BUILD_SYSTEM)/soong_cc_rust_prebuilt.mk",
Liz Kammer4018a8d2020-11-24 09:35:21 -080058 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -070059 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Liz Kammer4018a8d2020-11-24 09:35:21 -080060 entries.AddStrings("LOCAL_RLIB_LIBRARIES", mod.Properties.AndroidMkRlibs...)
61 entries.AddStrings("LOCAL_DYLIB_LIBRARIES", mod.Properties.AndroidMkDylibs...)
62 entries.AddStrings("LOCAL_PROC_MACRO_LIBRARIES", mod.Properties.AndroidMkProcMacroLibs...)
Cole Faustb6e6f992023-08-17 17:42:26 -070063 entries.AddStrings("LOCAL_SHARED_LIBRARIES", mod.transitiveAndroidMkSharedLibs.ToList()...)
Liz Kammer4018a8d2020-11-24 09:35:21 -080064 entries.AddStrings("LOCAL_STATIC_LIBRARIES", mod.Properties.AndroidMkStaticLibs...)
Ivan Lozano6a884432020-12-02 09:15:16 -050065 entries.AddStrings("LOCAL_SOONG_LINK_TYPE", mod.makeLinkType)
Kiyoung Kimed63c022024-02-02 08:06:52 +000066 if mod.UseVndk() {
67 entries.SetBool("LOCAL_USE_VNDK", true)
Ivan Lozanoc08897c2021-04-02 12:41:32 -040068 }
LaMont Jonesacae2d72024-01-09 22:53:52 +000069 android.SetAconfigFileMkEntries(mod.AndroidModuleBase(), entries, mod.mergedAconfigFiles)
Ivan Lozanoffee3342019-08-27 12:03:00 -070070 },
71 },
72 }
Ivan Lozano26ecd6c2020-07-31 13:40:31 -040073
74 if mod.compiler != nil && !mod.compiler.Disabled() {
Andrei Homescuc7767922020-08-05 06:36:19 -070075 mod.SubAndroidMk(&ret, mod.compiler)
Ivan Lozano4fef93c2020-07-08 08:39:44 -040076 } else if mod.sourceProvider != nil {
Ivan Lozano26ecd6c2020-07-31 13:40:31 -040077 // If the compiler is disabled, this is a SourceProvider.
Andrei Homescuc7767922020-08-05 06:36:19 -070078 mod.SubAndroidMk(&ret, mod.sourceProvider)
Ivan Lozano4fef93c2020-07-08 08:39:44 -040079 }
Tri Vo0a74c3e2021-04-01 13:59:27 -070080
81 if mod.sanitize != nil {
82 mod.SubAndroidMk(&ret, mod.sanitize)
83 }
84
Justin Yun24b246a2023-03-16 10:36:16 +090085 ret.SubName += mod.AndroidMkSuffix()
Chih-Hung Hsieha5f22ed2019-10-24 20:47:54 -070086
Liz Kammer4018a8d2020-11-24 09:35:21 -080087 return []android.AndroidMkEntries{ret}
Ivan Lozanoffee3342019-08-27 12:03:00 -070088}
89
Liz Kammer4018a8d2020-11-24 09:35:21 -080090func (binary *binaryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
Andrei Homescuc7767922020-08-05 06:36:19 -070091 ctx.SubAndroidMk(ret, binary.baseCompiler)
Ivan Lozanoffee3342019-08-27 12:03:00 -070092
Jingwen Chen40fd90a2020-06-15 05:24:19 +000093 if binary.distFile.Valid() {
94 ret.DistFiles = android.MakeDefaultDistFiles(binary.distFile.Path())
95 }
Ivan Lozanoffee3342019-08-27 12:03:00 -070096 ret.Class = "EXECUTABLES"
Ivan Lozanoffee3342019-08-27 12:03:00 -070097}
98
Liz Kammer4018a8d2020-11-24 09:35:21 -080099func (test *testDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
Ivan Lozano9da4aa82021-01-29 12:48:05 -0500100 ctx.SubAndroidMk(ret, test.binaryDecorator)
101
Chih-Hung Hsieh15f369e2019-11-15 04:14:44 -0800102 ret.Class = "NATIVE_TESTS"
Colin Crossaa255532020-07-03 13:18:24 -0700103 ret.ExtraEntries = append(ret.ExtraEntries,
104 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
105 entries.AddCompatibilityTestSuites(test.Properties.Test_suites...)
106 if test.testConfig != nil {
107 entries.SetString("LOCAL_FULL_TEST_CONFIG", test.testConfig.String())
108 }
109 entries.SetBoolIfTrue("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", !BoolDefault(test.Properties.Auto_gen_config, true))
yangbill22bafec2022-02-11 18:06:07 +0800110 if test.Properties.Data_bins != nil {
111 entries.AddStrings("LOCAL_TEST_DATA_BINS", test.Properties.Data_bins...)
112 }
Zhenhuang Wang0ac5a432022-08-12 18:49:20 +0800113
114 test.Properties.Test_options.SetAndroidMkEntries(entries)
Colin Crossaa255532020-07-03 13:18:24 -0700115 })
Chih-Hung Hsieha5f22ed2019-10-24 20:47:54 -0700116}
117
Jakub Kotur546ccd52021-01-15 15:57:27 +0100118func (benchmark *benchmarkDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
119 benchmark.binaryDecorator.AndroidMk(ctx, ret)
120 ret.Class = "NATIVE_TESTS"
121 ret.ExtraEntries = append(ret.ExtraEntries,
122 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
123 entries.AddCompatibilityTestSuites(benchmark.Properties.Test_suites...)
124 if benchmark.testConfig != nil {
125 entries.SetString("LOCAL_FULL_TEST_CONFIG", benchmark.testConfig.String())
126 }
127 entries.SetBool("LOCAL_NATIVE_BENCHMARK", true)
128 entries.SetBoolIfTrue("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", !BoolDefault(benchmark.Properties.Auto_gen_config, true))
129 })
130}
131
Liz Kammer4018a8d2020-11-24 09:35:21 -0800132func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
Andrei Homescuc7767922020-08-05 06:36:19 -0700133 ctx.SubAndroidMk(ret, library.baseCompiler)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700134
135 if library.rlib() {
136 ret.Class = "RLIB_LIBRARIES"
137 } else if library.dylib() {
138 ret.Class = "DYLIB_LIBRARIES"
Ivan Lozano52767be2019-10-18 14:49:46 -0700139 } else if library.static() {
140 ret.Class = "STATIC_LIBRARIES"
141 } else if library.shared() {
142 ret.Class = "SHARED_LIBRARIES"
Ivan Lozanoffee3342019-08-27 12:03:00 -0700143 }
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000144 if library.distFile.Valid() {
145 ret.DistFiles = android.MakeDefaultDistFiles(library.distFile.Path())
146 }
Ivan Lozano7b0781d2021-11-03 15:30:18 -0400147 ret.ExtraEntries = append(ret.ExtraEntries,
148 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
149 if library.tocFile.Valid() {
150 entries.SetString("LOCAL_SOONG_TOC", library.tocFile.String())
151 }
152 })
Ivan Lozanoffee3342019-08-27 12:03:00 -0700153}
Ivan Lozanofba2aa22021-11-11 09:29:07 -0500154
Justin Yun24b246a2023-03-16 10:36:16 +0900155func (library *snapshotLibraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
156 ctx.SubAndroidMk(ret, library.libraryDecorator)
157 ret.SubName = library.SnapshotAndroidMkSuffix()
158}
159
Liz Kammer4018a8d2020-11-24 09:35:21 -0800160func (procMacro *procMacroDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
Andrei Homescuc7767922020-08-05 06:36:19 -0700161 ctx.SubAndroidMk(ret, procMacro.baseCompiler)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700162
163 ret.Class = "PROC_MACRO_LIBRARIES"
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000164 if procMacro.distFile.Valid() {
165 ret.DistFiles = android.MakeDefaultDistFiles(procMacro.distFile.Path())
166 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700167
168}
169
Liz Kammer4018a8d2020-11-24 09:35:21 -0800170func (sourceProvider *BaseSourceProvider) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
Chih-Hung Hsiehc49649c2020-10-01 21:25:05 -0700171 outFile := sourceProvider.OutputFiles[0]
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400172 ret.Class = "ETC"
173 ret.OutputFile = android.OptionalPathForPath(outFile)
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400174 ret.SubName += sourceProvider.subName
Colin Crossaa255532020-07-03 13:18:24 -0700175 ret.ExtraEntries = append(ret.ExtraEntries,
176 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
177 _, file := filepath.Split(outFile.String())
178 stem, suffix, _ := android.SplitFileExt(file)
179 entries.SetString("LOCAL_MODULE_SUFFIX", suffix)
180 entries.SetString("LOCAL_MODULE_STEM", stem)
181 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
182 })
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400183}
184
Liz Kammer4018a8d2020-11-24 09:35:21 -0800185func (bindgen *bindgenDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
Andrei Homescuc7767922020-08-05 06:36:19 -0700186 ctx.SubAndroidMk(ret, bindgen.BaseSourceProvider)
Treehugger Robot588aae72020-08-21 10:01:58 +0000187}
188
Liz Kammer4018a8d2020-11-24 09:35:21 -0800189func (proto *protobufDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
Treehugger Robot588aae72020-08-21 10:01:58 +0000190 ctx.SubAndroidMk(ret, proto.BaseSourceProvider)
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400191}
192
Liz Kammer4018a8d2020-11-24 09:35:21 -0800193func (compiler *baseCompiler) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
Ivan Lozano2b081132020-09-08 12:46:52 -0400194 if compiler.path == (android.InstallPath{}) {
195 return
196 }
197
Colin Cross77435572021-11-08 12:37:01 -0800198 if compiler.strippedOutputFile.Valid() {
ThiƩbaud Weksteenfabaff62020-08-27 13:48:36 +0200199 ret.OutputFile = compiler.strippedOutputFile
Ivan Lozanoffee3342019-08-27 12:03:00 -0700200 }
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400201
Colin Crossaa255532020-07-03 13:18:24 -0700202 ret.ExtraEntries = append(ret.ExtraEntries,
203 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400204 entries.SetPath("LOCAL_SOONG_UNSTRIPPED_BINARY", compiler.unstrippedOutputFile)
Colin Crossc68db4b2021-11-11 18:59:15 -0800205 path, file := filepath.Split(compiler.path.String())
Colin Crossaa255532020-07-03 13:18:24 -0700206 stem, suffix, _ := android.SplitFileExt(file)
207 entries.SetString("LOCAL_MODULE_SUFFIX", suffix)
208 entries.SetString("LOCAL_MODULE_PATH", path)
209 entries.SetString("LOCAL_MODULE_STEM", stem)
210 })
Ivan Lozanoffee3342019-08-27 12:03:00 -0700211}
hamzehc651b522021-04-29 12:50:47 -0700212
Ivan Lozano0f9963e2023-02-06 13:31:02 -0500213func (fuzz *fuzzDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
214 ctx.SubAndroidMk(ret, fuzz.binaryDecorator)
hamzehc651b522021-04-29 12:50:47 -0700215
Ivan Lozano0f9963e2023-02-06 13:31:02 -0500216 ret.ExtraEntries = append(ret.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext,
hamzehc651b522021-04-29 12:50:47 -0700217 entries *android.AndroidMkEntries) {
218 entries.SetBool("LOCAL_IS_FUZZ_TARGET", true)
Ivan Lozano0f9963e2023-02-06 13:31:02 -0500219 if fuzz.installedSharedDeps != nil {
220 entries.AddStrings("LOCAL_FUZZ_INSTALLED_SHARED_DEPS", fuzz.installedSharedDeps...)
221 }
hamzehc651b522021-04-29 12:50:47 -0700222 })
223}