blob: 42c8537a9203e312160d8fe89e7795c90d21bbf6 [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 (
18 "android/soong/android"
19)
20
21func init() {
22 android.RegisterModuleType("rust_proc_macro", ProcMacroFactory)
23}
24
25type ProcMacroCompilerProperties struct {
Ivan Lozanoffee3342019-08-27 12:03:00 -070026}
27
28type procMacroDecorator struct {
29 *baseCompiler
30
Ivan Lozano8a23fa42020-06-16 10:26:57 -040031 Properties ProcMacroCompilerProperties
Ivan Lozanoffee3342019-08-27 12:03:00 -070032}
33
34type procMacroInterface interface {
35}
36
37var _ compiler = (*procMacroDecorator)(nil)
38
39func ProcMacroFactory() android.Module {
Ivan Lozano5ca5ef62019-09-23 10:10:40 -070040 module, _ := NewProcMacro(android.HostSupportedNoCross)
Ivan Lozanoffee3342019-08-27 12:03:00 -070041 return module.Init()
42}
43
44func NewProcMacro(hod android.HostOrDeviceSupported) (*Module, *procMacroDecorator) {
45 module := newModule(hod, android.MultilibFirst)
46
47 procMacro := &procMacroDecorator{
Chih-Hung Hsieh9a4a7ba2019-12-12 19:36:05 -080048 baseCompiler: NewBaseCompiler("lib", "lib64", InstallInSystem),
Ivan Lozanoffee3342019-08-27 12:03:00 -070049 }
50
51 module.compiler = procMacro
52
53 return module, procMacro
54}
55
56func (procMacro *procMacroDecorator) compilerProps() []interface{} {
57 return append(procMacro.baseCompiler.compilerProps(),
58 &procMacro.Properties)
59}
60
61func (procMacro *procMacroDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path {
62 fileName := procMacro.getStem(ctx) + ctx.toolchain().ProcMacroSuffix()
63 outputFile := android.PathForModuleOut(ctx, fileName)
64
Ivan Lozano8a23fa42020-06-16 10:26:57 -040065 srcPath := srcPathFromModuleSrcs(ctx, procMacro.baseCompiler.Properties.Srcs)
Ivan Lozanoffee3342019-08-27 12:03:00 -070066
67 procMacro.unstrippedOutputFile = outputFile
68
69 TransformSrctoProcMacro(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)
70 return outputFile
71}
Ivan Lozanoad8b18b2019-10-31 19:38:29 -070072
73func (procMacro *procMacroDecorator) getStem(ctx ModuleContext) string {
74 stem := procMacro.baseCompiler.getStemWithoutSuffix(ctx)
75 validateLibraryStem(ctx, stem, procMacro.crateName())
76
77 return stem + String(procMacro.baseCompiler.Properties.Suffix)
78}