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 { |
| 48 | module, _ := NewProcMacro(android.HostAndDeviceSupported) |
| 49 | return module.Init() |
| 50 | } |
| 51 | |
| 52 | func NewProcMacro(hod android.HostOrDeviceSupported) (*Module, *procMacroDecorator) { |
| 53 | module := newModule(hod, android.MultilibFirst) |
| 54 | |
| 55 | procMacro := &procMacroDecorator{ |
| 56 | baseCompiler: NewBaseCompiler("lib", "lib64"), |
| 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 | } |