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 15package rust 16 17import ( 18 "android/soong/android" 19) 20 21func init() { 22 android.RegisterModuleType("rust_proc_macro", ProcMacroFactory) 23} 24 25type ProcMacroCompilerProperties struct { 26} 27 28type procMacroDecorator struct { 29 *baseCompiler 30 *flagExporter 31 32 Properties ProcMacroCompilerProperties 33} 34 35type procMacroInterface interface { 36} 37 38var _ compiler = (*procMacroDecorator)(nil) 39var _ exportedFlagsProducer = (*procMacroDecorator)(nil) 40 41func ProcMacroFactory() android.Module { 42 module, _ := NewProcMacro(android.HostSupportedNoCross) 43 return module.Init() 44} 45 46func NewProcMacro(hod android.HostOrDeviceSupported) (*Module, *procMacroDecorator) { 47 module := newModule(hod, android.MultilibFirst) 48 49 procMacro := &procMacroDecorator{ 50 baseCompiler: NewBaseCompiler("lib", "lib64", InstallInSystem), 51 flagExporter: NewFlagExporter(), 52 } 53 54 module.compiler = procMacro 55 56 return module, procMacro 57} 58 59func (procMacro *procMacroDecorator) compilerProps() []interface{} { 60 return append(procMacro.baseCompiler.compilerProps(), 61 &procMacro.Properties) 62} 63 64func (procMacro *procMacroDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path { 65 fileName := procMacro.getStem(ctx) + ctx.toolchain().ProcMacroSuffix() 66 outputFile := android.PathForModuleOut(ctx, fileName) 67 68 srcPath, _ := srcPathFromModuleSrcs(ctx, procMacro.baseCompiler.Properties.Srcs) 69 70 procMacro.unstrippedOutputFile = outputFile 71 72 TransformSrctoProcMacro(ctx, srcPath, deps, flags, outputFile, deps.linkDirs) 73 return outputFile 74} 75 76func (procMacro *procMacroDecorator) getStem(ctx ModuleContext) string { 77 stem := procMacro.baseCompiler.getStemWithoutSuffix(ctx) 78 validateLibraryStem(ctx, stem, procMacro.crateName()) 79 80 return stem + String(procMacro.baseCompiler.Properties.Suffix) 81} 82 83func (procMacro *procMacroDecorator) autoDep() autoDep { 84 return rlibAutoDep 85} 86