| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 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 |  | 
|  | 15 | package rust | 
|  | 16 |  | 
|  | 17 | import ( | 
|  | 18 | "android/soong/android" | 
|  | 19 | ) | 
|  | 20 |  | 
|  | 21 | func init() { | 
|  | 22 | android.RegisterModuleType("rust_proc_macro", ProcMacroFactory) | 
|  | 23 | } | 
|  | 24 |  | 
|  | 25 | type ProcMacroCompilerProperties struct { | 
|  | 26 | // path to the source file that is the main entry point of the program (e.g. src/lib.rs) | 
|  | 27 | Srcs []string `android:"path,arch_variant"` | 
|  | 28 |  | 
|  | 29 | // set name of the procMacro | 
|  | 30 | Stem   *string `android:"arch_variant"` | 
|  | 31 | Suffix *string `android:"arch_variant"` | 
|  | 32 | } | 
|  | 33 |  | 
|  | 34 | type procMacroDecorator struct { | 
|  | 35 | *baseCompiler | 
|  | 36 |  | 
|  | 37 | Properties           ProcMacroCompilerProperties | 
|  | 38 | distFile             android.OptionalPath | 
|  | 39 | unstrippedOutputFile android.Path | 
|  | 40 | } | 
|  | 41 |  | 
|  | 42 | type procMacroInterface interface { | 
|  | 43 | } | 
|  | 44 |  | 
|  | 45 | var _ compiler = (*procMacroDecorator)(nil) | 
|  | 46 |  | 
|  | 47 | func ProcMacroFactory() android.Module { | 
| Ivan Lozano | 5ca5ef6 | 2019-09-23 10:10:40 -0700 | [diff] [blame] | 48 | module, _ := NewProcMacro(android.HostSupportedNoCross) | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 49 | return module.Init() | 
|  | 50 | } | 
|  | 51 |  | 
|  | 52 | func NewProcMacro(hod android.HostOrDeviceSupported) (*Module, *procMacroDecorator) { | 
|  | 53 | module := newModule(hod, android.MultilibFirst) | 
|  | 54 |  | 
|  | 55 | procMacro := &procMacroDecorator{ | 
| Chih-Hung Hsieh | 9a4a7ba | 2019-12-12 19:36:05 -0800 | [diff] [blame] | 56 | baseCompiler: NewBaseCompiler("lib", "lib64", InstallInSystem), | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 57 | } | 
|  | 58 |  | 
|  | 59 | module.compiler = procMacro | 
|  | 60 |  | 
|  | 61 | return module, procMacro | 
|  | 62 | } | 
|  | 63 |  | 
|  | 64 | func (procMacro *procMacroDecorator) compilerProps() []interface{} { | 
|  | 65 | return append(procMacro.baseCompiler.compilerProps(), | 
|  | 66 | &procMacro.Properties) | 
|  | 67 | } | 
|  | 68 |  | 
|  | 69 | func (procMacro *procMacroDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path { | 
|  | 70 | fileName := procMacro.getStem(ctx) + ctx.toolchain().ProcMacroSuffix() | 
|  | 71 | outputFile := android.PathForModuleOut(ctx, fileName) | 
|  | 72 |  | 
|  | 73 | srcPath := srcPathFromModuleSrcs(ctx, procMacro.Properties.Srcs) | 
|  | 74 |  | 
|  | 75 | procMacro.unstrippedOutputFile = outputFile | 
|  | 76 |  | 
|  | 77 | TransformSrctoProcMacro(ctx, srcPath, deps, flags, outputFile, deps.linkDirs) | 
|  | 78 | return outputFile | 
|  | 79 | } | 
| Ivan Lozano | ad8b18b | 2019-10-31 19:38:29 -0700 | [diff] [blame] | 80 |  | 
|  | 81 | func (procMacro *procMacroDecorator) getStem(ctx ModuleContext) string { | 
|  | 82 | stem := procMacro.baseCompiler.getStemWithoutSuffix(ctx) | 
|  | 83 | validateLibraryStem(ctx, stem, procMacro.crateName()) | 
|  | 84 |  | 
|  | 85 | return stem + String(procMacro.baseCompiler.Properties.Suffix) | 
|  | 86 | } |