blob: eda2bb4ea45ca8ae3a4170975e597d52414f910b [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"
Ivan Lozano9da4aa82021-01-29 12:48:05 -050021 "android/soong/cc"
Ivan Lozanoffee3342019-08-27 12:03:00 -070022)
23
24type AndroidMkContext interface {
25 Name() string
26 Target() android.Target
Liz Kammer4018a8d2020-11-24 09:35:21 -080027 SubAndroidMk(*android.AndroidMkEntries, interface{})
Ivan Lozanoffee3342019-08-27 12:03:00 -070028}
29
Andrei Homescuc7767922020-08-05 06:36:19 -070030type SubAndroidMkProvider interface {
Liz Kammer4018a8d2020-11-24 09:35:21 -080031 AndroidMk(AndroidMkContext, *android.AndroidMkEntries)
Ivan Lozanoffee3342019-08-27 12:03:00 -070032}
33
Liz Kammer4018a8d2020-11-24 09:35:21 -080034func (mod *Module) SubAndroidMk(data *android.AndroidMkEntries, obj interface{}) {
Ivan Lozanoffee3342019-08-27 12:03:00 -070035 if mod.subAndroidMkOnce == nil {
Andrei Homescuc7767922020-08-05 06:36:19 -070036 mod.subAndroidMkOnce = make(map[SubAndroidMkProvider]bool)
Ivan Lozanoffee3342019-08-27 12:03:00 -070037 }
Andrei Homescuc7767922020-08-05 06:36:19 -070038 if androidmk, ok := obj.(SubAndroidMkProvider); ok {
Ivan Lozanoffee3342019-08-27 12:03:00 -070039 if !mod.subAndroidMkOnce[androidmk] {
40 mod.subAndroidMkOnce[androidmk] = true
41 androidmk.AndroidMk(mod, data)
42 }
43 }
44}
45
Liz Kammer4018a8d2020-11-24 09:35:21 -080046func (mod *Module) AndroidMkEntries() []android.AndroidMkEntries {
Jiyong Park99644e92020-11-17 22:21:02 +090047 if mod.Properties.HideFromMake || mod.hideApexVariantFromMake {
Liz Kammer4018a8d2020-11-24 09:35:21 -080048
49 return []android.AndroidMkEntries{android.AndroidMkEntries{Disabled: true}}
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -040050 }
51
Liz Kammer4018a8d2020-11-24 09:35:21 -080052 ret := android.AndroidMkEntries{
Ivan Lozanoffee3342019-08-27 12:03:00 -070053 OutputFile: mod.outputFile,
54 Include: "$(BUILD_SYSTEM)/soong_rust_prebuilt.mk",
Liz Kammer4018a8d2020-11-24 09:35:21 -080055 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -070056 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Liz Kammer4018a8d2020-11-24 09:35:21 -080057 entries.AddStrings("LOCAL_RLIB_LIBRARIES", mod.Properties.AndroidMkRlibs...)
58 entries.AddStrings("LOCAL_DYLIB_LIBRARIES", mod.Properties.AndroidMkDylibs...)
59 entries.AddStrings("LOCAL_PROC_MACRO_LIBRARIES", mod.Properties.AndroidMkProcMacroLibs...)
60 entries.AddStrings("LOCAL_SHARED_LIBRARIES", mod.Properties.AndroidMkSharedLibs...)
61 entries.AddStrings("LOCAL_STATIC_LIBRARIES", mod.Properties.AndroidMkStaticLibs...)
Ivan Lozano6a884432020-12-02 09:15:16 -050062 entries.AddStrings("LOCAL_SOONG_LINK_TYPE", mod.makeLinkType)
Ivan Lozanoffee3342019-08-27 12:03:00 -070063 },
64 },
65 }
Ivan Lozano26ecd6c2020-07-31 13:40:31 -040066
67 if mod.compiler != nil && !mod.compiler.Disabled() {
Andrei Homescuc7767922020-08-05 06:36:19 -070068 mod.SubAndroidMk(&ret, mod.compiler)
Ivan Lozano4fef93c2020-07-08 08:39:44 -040069 } else if mod.sourceProvider != nil {
Ivan Lozano26ecd6c2020-07-31 13:40:31 -040070 // If the compiler is disabled, this is a SourceProvider.
Andrei Homescuc7767922020-08-05 06:36:19 -070071 mod.SubAndroidMk(&ret, mod.sourceProvider)
Ivan Lozano4fef93c2020-07-08 08:39:44 -040072 }
Chih-Hung Hsieha5f22ed2019-10-24 20:47:54 -070073 ret.SubName += mod.Properties.SubName
74
Liz Kammer4018a8d2020-11-24 09:35:21 -080075 return []android.AndroidMkEntries{ret}
Ivan Lozanoffee3342019-08-27 12:03:00 -070076}
77
Liz Kammer4018a8d2020-11-24 09:35:21 -080078func (binary *binaryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
Andrei Homescuc7767922020-08-05 06:36:19 -070079 ctx.SubAndroidMk(ret, binary.baseCompiler)
Ivan Lozanoffee3342019-08-27 12:03:00 -070080
Jingwen Chen40fd90a2020-06-15 05:24:19 +000081 if binary.distFile.Valid() {
82 ret.DistFiles = android.MakeDefaultDistFiles(binary.distFile.Path())
83 }
84
Ivan Lozanoffee3342019-08-27 12:03:00 -070085 ret.Class = "EXECUTABLES"
Ivan Lozanoffee3342019-08-27 12:03:00 -070086}
87
Liz Kammer4018a8d2020-11-24 09:35:21 -080088func (test *testDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
Ivan Lozano9da4aa82021-01-29 12:48:05 -050089 ctx.SubAndroidMk(ret, test.binaryDecorator)
90
Chih-Hung Hsieh15f369e2019-11-15 04:14:44 -080091 ret.Class = "NATIVE_TESTS"
Colin Crossaa255532020-07-03 13:18:24 -070092 ret.ExtraEntries = append(ret.ExtraEntries,
93 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
94 entries.AddCompatibilityTestSuites(test.Properties.Test_suites...)
95 if test.testConfig != nil {
96 entries.SetString("LOCAL_FULL_TEST_CONFIG", test.testConfig.String())
97 }
98 entries.SetBoolIfTrue("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", !BoolDefault(test.Properties.Auto_gen_config, true))
99 entries.SetBoolIfTrue("LOCAL_IS_UNIT_TEST", Bool(test.Properties.Test_options.Unit_test))
100 })
Ivan Lozano9da4aa82021-01-29 12:48:05 -0500101
102 cc.AndroidMkWriteTestData(test.data, ret)
Chih-Hung Hsieha5f22ed2019-10-24 20:47:54 -0700103}
104
Jakub Kotur546ccd52021-01-15 15:57:27 +0100105func (benchmark *benchmarkDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
106 benchmark.binaryDecorator.AndroidMk(ctx, ret)
107 ret.Class = "NATIVE_TESTS"
108 ret.ExtraEntries = append(ret.ExtraEntries,
109 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
110 entries.AddCompatibilityTestSuites(benchmark.Properties.Test_suites...)
111 if benchmark.testConfig != nil {
112 entries.SetString("LOCAL_FULL_TEST_CONFIG", benchmark.testConfig.String())
113 }
114 entries.SetBool("LOCAL_NATIVE_BENCHMARK", true)
115 entries.SetBoolIfTrue("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", !BoolDefault(benchmark.Properties.Auto_gen_config, true))
116 })
117}
118
Liz Kammer4018a8d2020-11-24 09:35:21 -0800119func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
Andrei Homescuc7767922020-08-05 06:36:19 -0700120 ctx.SubAndroidMk(ret, library.baseCompiler)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700121
122 if library.rlib() {
123 ret.Class = "RLIB_LIBRARIES"
124 } else if library.dylib() {
125 ret.Class = "DYLIB_LIBRARIES"
Ivan Lozano52767be2019-10-18 14:49:46 -0700126 } else if library.static() {
127 ret.Class = "STATIC_LIBRARIES"
128 } else if library.shared() {
129 ret.Class = "SHARED_LIBRARIES"
Ivan Lozanoffee3342019-08-27 12:03:00 -0700130 }
Ivan Lozano52767be2019-10-18 14:49:46 -0700131
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000132 if library.distFile.Valid() {
133 ret.DistFiles = android.MakeDefaultDistFiles(library.distFile.Path())
134 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700135}
136
Liz Kammer4018a8d2020-11-24 09:35:21 -0800137func (procMacro *procMacroDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
Andrei Homescuc7767922020-08-05 06:36:19 -0700138 ctx.SubAndroidMk(ret, procMacro.baseCompiler)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700139
140 ret.Class = "PROC_MACRO_LIBRARIES"
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000141 if procMacro.distFile.Valid() {
142 ret.DistFiles = android.MakeDefaultDistFiles(procMacro.distFile.Path())
143 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700144
145}
146
Liz Kammer4018a8d2020-11-24 09:35:21 -0800147func (sourceProvider *BaseSourceProvider) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
Chih-Hung Hsiehc49649c2020-10-01 21:25:05 -0700148 outFile := sourceProvider.OutputFiles[0]
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400149 ret.Class = "ETC"
150 ret.OutputFile = android.OptionalPathForPath(outFile)
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400151 ret.SubName += sourceProvider.subName
Colin Crossaa255532020-07-03 13:18:24 -0700152 ret.ExtraEntries = append(ret.ExtraEntries,
153 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
154 _, file := filepath.Split(outFile.String())
155 stem, suffix, _ := android.SplitFileExt(file)
156 entries.SetString("LOCAL_MODULE_SUFFIX", suffix)
157 entries.SetString("LOCAL_MODULE_STEM", stem)
158 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
159 })
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400160}
161
Liz Kammer4018a8d2020-11-24 09:35:21 -0800162func (bindgen *bindgenDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
Andrei Homescuc7767922020-08-05 06:36:19 -0700163 ctx.SubAndroidMk(ret, bindgen.BaseSourceProvider)
Treehugger Robot588aae72020-08-21 10:01:58 +0000164}
165
Liz Kammer4018a8d2020-11-24 09:35:21 -0800166func (proto *protobufDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
Treehugger Robot588aae72020-08-21 10:01:58 +0000167 ctx.SubAndroidMk(ret, proto.BaseSourceProvider)
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400168}
169
Liz Kammer4018a8d2020-11-24 09:35:21 -0800170func (compiler *baseCompiler) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
Ivan Lozano2b081132020-09-08 12:46:52 -0400171 if compiler.path == (android.InstallPath{}) {
172 return
173 }
174
ThiƩbaud Weksteenfabaff62020-08-27 13:48:36 +0200175 var unstrippedOutputFile android.OptionalPath
Ivan Lozanoffee3342019-08-27 12:03:00 -0700176 // Soong installation is only supported for host modules. Have Make
177 // installation trigger Soong installation.
178 if ctx.Target().Os.Class == android.Host {
179 ret.OutputFile = android.OptionalPathForPath(compiler.path)
ThiƩbaud Weksteenfabaff62020-08-27 13:48:36 +0200180 } else if compiler.strippedOutputFile.Valid() {
181 unstrippedOutputFile = ret.OutputFile
182 ret.OutputFile = compiler.strippedOutputFile
Ivan Lozanoffee3342019-08-27 12:03:00 -0700183 }
Colin Crossaa255532020-07-03 13:18:24 -0700184 ret.ExtraEntries = append(ret.ExtraEntries,
185 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
186 entries.SetOptionalPath("LOCAL_SOONG_UNSTRIPPED_BINARY", unstrippedOutputFile)
187 path, file := filepath.Split(compiler.path.ToMakePath().String())
188 stem, suffix, _ := android.SplitFileExt(file)
189 entries.SetString("LOCAL_MODULE_SUFFIX", suffix)
190 entries.SetString("LOCAL_MODULE_PATH", path)
191 entries.SetString("LOCAL_MODULE_STEM", stem)
192 })
Ivan Lozanoffee3342019-08-27 12:03:00 -0700193}