2019-08-27 21:03:00 +02:00
|
|
|
// Copyright 2019 The Android Open Source Project
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package rust
|
|
|
|
|
|
|
|
import (
|
|
|
|
"android/soong/android"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
android.RegisterModuleType("rust_proc_macro", ProcMacroFactory)
|
|
|
|
}
|
|
|
|
|
|
|
|
type ProcMacroCompilerProperties struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
type procMacroDecorator struct {
|
|
|
|
*baseCompiler
|
2020-06-25 18:34:12 +02:00
|
|
|
*flagExporter
|
2019-08-27 21:03:00 +02:00
|
|
|
|
2020-06-16 16:26:57 +02:00
|
|
|
Properties ProcMacroCompilerProperties
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type procMacroInterface interface {
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ compiler = (*procMacroDecorator)(nil)
|
2020-06-25 18:34:12 +02:00
|
|
|
var _ exportedFlagsProducer = (*procMacroDecorator)(nil)
|
2019-08-27 21:03:00 +02:00
|
|
|
|
|
|
|
func ProcMacroFactory() android.Module {
|
2019-09-23 19:10:40 +02:00
|
|
|
module, _ := NewProcMacro(android.HostSupportedNoCross)
|
2019-08-27 21:03:00 +02:00
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewProcMacro(hod android.HostOrDeviceSupported) (*Module, *procMacroDecorator) {
|
|
|
|
module := newModule(hod, android.MultilibFirst)
|
|
|
|
|
|
|
|
procMacro := &procMacroDecorator{
|
2019-12-13 04:36:05 +01:00
|
|
|
baseCompiler: NewBaseCompiler("lib", "lib64", InstallInSystem),
|
2020-06-25 18:34:12 +02:00
|
|
|
flagExporter: NewFlagExporter(),
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
|
2020-02-11 14:24:25 +01:00
|
|
|
// Don't sanitize procMacros
|
|
|
|
module.sanitize = nil
|
2019-08-27 21:03:00 +02:00
|
|
|
module.compiler = procMacro
|
|
|
|
|
|
|
|
return module, procMacro
|
|
|
|
}
|
|
|
|
|
|
|
|
func (procMacro *procMacroDecorator) compilerProps() []interface{} {
|
|
|
|
return append(procMacro.baseCompiler.compilerProps(),
|
|
|
|
&procMacro.Properties)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (procMacro *procMacroDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path {
|
|
|
|
fileName := procMacro.getStem(ctx) + ctx.toolchain().ProcMacroSuffix()
|
|
|
|
outputFile := android.PathForModuleOut(ctx, fileName)
|
|
|
|
|
2020-07-22 22:09:13 +02:00
|
|
|
srcPath, _ := srcPathFromModuleSrcs(ctx, procMacro.baseCompiler.Properties.Srcs)
|
2019-08-27 21:03:00 +02:00
|
|
|
TransformSrctoProcMacro(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)
|
|
|
|
return outputFile
|
|
|
|
}
|
2019-11-01 03:38:29 +01:00
|
|
|
|
|
|
|
func (procMacro *procMacroDecorator) getStem(ctx ModuleContext) string {
|
|
|
|
stem := procMacro.baseCompiler.getStemWithoutSuffix(ctx)
|
|
|
|
validateLibraryStem(ctx, stem, procMacro.crateName())
|
|
|
|
|
|
|
|
return stem + String(procMacro.baseCompiler.Properties.Suffix)
|
|
|
|
}
|
2020-06-29 23:34:06 +02:00
|
|
|
|
2021-01-26 15:18:53 +01:00
|
|
|
func (procMacro *procMacroDecorator) autoDep(ctx android.BottomUpMutatorContext) autoDep {
|
2020-06-29 23:34:06 +02:00
|
|
|
return rlibAutoDep
|
|
|
|
}
|