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() {
|
2020-06-25 09:47:46 +02:00
|
|
|
android.RegisterModuleType("rust_prebuilt_library", PrebuiltLibraryFactory)
|
2019-08-27 21:03:00 +02:00
|
|
|
android.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
|
2020-06-25 09:47:46 +02:00
|
|
|
android.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory)
|
2022-03-23 22:31:39 +01:00
|
|
|
android.RegisterModuleType("rust_prebuilt_proc_macro", PrebuiltProcMacroFactory)
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type PrebuiltProperties struct {
|
|
|
|
// path to the prebuilt file
|
|
|
|
Srcs []string `android:"path,arch_variant"`
|
2020-06-25 18:34:12 +02:00
|
|
|
// directories containing associated rlib dependencies
|
|
|
|
Link_dirs []string `android:"path,arch_variant"`
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type prebuiltLibraryDecorator struct {
|
2021-11-11 15:29:07 +01:00
|
|
|
android.Prebuilt
|
|
|
|
|
2019-08-27 21:03:00 +02:00
|
|
|
*libraryDecorator
|
|
|
|
Properties PrebuiltProperties
|
|
|
|
}
|
|
|
|
|
2022-03-23 22:31:39 +01:00
|
|
|
type prebuiltProcMacroDecorator struct {
|
|
|
|
android.Prebuilt
|
|
|
|
|
|
|
|
*procMacroDecorator
|
|
|
|
Properties PrebuiltProperties
|
|
|
|
}
|
|
|
|
|
|
|
|
func PrebuiltProcMacroFactory() android.Module {
|
|
|
|
module, _ := NewPrebuiltProcMacro(android.HostSupportedNoCross)
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
type rustPrebuilt interface {
|
|
|
|
prebuiltSrcs() []string
|
|
|
|
prebuilt() *android.Prebuilt
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPrebuiltProcMacro(hod android.HostOrDeviceSupported) (*Module, *prebuiltProcMacroDecorator) {
|
|
|
|
module, library := NewProcMacro(hod)
|
|
|
|
prebuilt := &prebuiltProcMacroDecorator{
|
|
|
|
procMacroDecorator: library,
|
|
|
|
}
|
|
|
|
module.compiler = prebuilt
|
|
|
|
|
|
|
|
addSrcSupplier(module, prebuilt)
|
|
|
|
|
|
|
|
return module, prebuilt
|
|
|
|
}
|
|
|
|
|
2019-08-27 21:03:00 +02:00
|
|
|
var _ compiler = (*prebuiltLibraryDecorator)(nil)
|
2020-06-25 18:34:12 +02:00
|
|
|
var _ exportedFlagsProducer = (*prebuiltLibraryDecorator)(nil)
|
2022-03-23 22:31:39 +01:00
|
|
|
var _ rustPrebuilt = (*prebuiltLibraryDecorator)(nil)
|
|
|
|
|
|
|
|
var _ compiler = (*prebuiltProcMacroDecorator)(nil)
|
|
|
|
var _ exportedFlagsProducer = (*prebuiltProcMacroDecorator)(nil)
|
|
|
|
var _ rustPrebuilt = (*prebuiltProcMacroDecorator)(nil)
|
2019-08-27 21:03:00 +02:00
|
|
|
|
2020-06-25 09:47:46 +02:00
|
|
|
func PrebuiltLibraryFactory() android.Module {
|
|
|
|
module, _ := NewPrebuiltLibrary(android.HostAndDeviceSupported)
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2019-08-27 21:03:00 +02:00
|
|
|
func PrebuiltDylibFactory() android.Module {
|
|
|
|
module, _ := NewPrebuiltDylib(android.HostAndDeviceSupported)
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2020-06-25 09:47:46 +02:00
|
|
|
func PrebuiltRlibFactory() android.Module {
|
|
|
|
module, _ := NewPrebuiltRlib(android.HostAndDeviceSupported)
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2022-03-23 22:31:39 +01:00
|
|
|
func addSrcSupplier(module android.PrebuiltInterface, prebuilt rustPrebuilt) {
|
2021-11-11 15:29:07 +01:00
|
|
|
srcsSupplier := func(_ android.BaseModuleContext, _ android.Module) []string {
|
|
|
|
return prebuilt.prebuiltSrcs()
|
|
|
|
}
|
|
|
|
android.InitPrebuiltModuleWithSrcSupplier(module, srcsSupplier, "srcs")
|
|
|
|
}
|
|
|
|
|
2020-06-25 09:47:46 +02:00
|
|
|
func NewPrebuiltLibrary(hod android.HostOrDeviceSupported) (*Module, *prebuiltLibraryDecorator) {
|
|
|
|
module, library := NewRustLibrary(hod)
|
|
|
|
library.BuildOnlyRust()
|
|
|
|
library.setNoStdlibs()
|
|
|
|
prebuilt := &prebuiltLibraryDecorator{
|
|
|
|
libraryDecorator: library,
|
|
|
|
}
|
|
|
|
module.compiler = prebuilt
|
2021-11-11 15:29:07 +01:00
|
|
|
|
|
|
|
addSrcSupplier(module, prebuilt)
|
|
|
|
|
2020-06-25 09:47:46 +02:00
|
|
|
return module, prebuilt
|
|
|
|
}
|
|
|
|
|
2019-08-27 21:03:00 +02:00
|
|
|
func NewPrebuiltDylib(hod android.HostOrDeviceSupported) (*Module, *prebuiltLibraryDecorator) {
|
|
|
|
module, library := NewRustLibrary(hod)
|
|
|
|
library.BuildOnlyDylib()
|
2019-10-31 18:44:40 +01:00
|
|
|
library.setNoStdlibs()
|
2020-06-25 09:47:46 +02:00
|
|
|
prebuilt := &prebuiltLibraryDecorator{
|
|
|
|
libraryDecorator: library,
|
|
|
|
}
|
|
|
|
module.compiler = prebuilt
|
2021-11-11 15:29:07 +01:00
|
|
|
|
|
|
|
addSrcSupplier(module, prebuilt)
|
|
|
|
|
2020-06-25 09:47:46 +02:00
|
|
|
return module, prebuilt
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPrebuiltRlib(hod android.HostOrDeviceSupported) (*Module, *prebuiltLibraryDecorator) {
|
|
|
|
module, library := NewRustLibrary(hod)
|
|
|
|
library.BuildOnlyRlib()
|
|
|
|
library.setNoStdlibs()
|
2019-08-27 21:03:00 +02:00
|
|
|
prebuilt := &prebuiltLibraryDecorator{
|
|
|
|
libraryDecorator: library,
|
|
|
|
}
|
|
|
|
module.compiler = prebuilt
|
2021-11-11 15:29:07 +01:00
|
|
|
|
|
|
|
addSrcSupplier(module, prebuilt)
|
|
|
|
|
2019-08-27 21:03:00 +02:00
|
|
|
return module, prebuilt
|
|
|
|
}
|
|
|
|
|
|
|
|
func (prebuilt *prebuiltLibraryDecorator) compilerProps() []interface{} {
|
2020-06-29 22:31:04 +02:00
|
|
|
return append(prebuilt.libraryDecorator.compilerProps(),
|
2019-08-27 21:03:00 +02:00
|
|
|
&prebuilt.Properties)
|
|
|
|
}
|
|
|
|
|
2022-04-19 05:12:56 +02:00
|
|
|
func (prebuilt *prebuiltLibraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) buildOutput {
|
2020-09-18 23:15:30 +02:00
|
|
|
prebuilt.flagExporter.exportLinkDirs(android.PathsForModuleSrc(ctx, prebuilt.Properties.Link_dirs).Strings()...)
|
|
|
|
prebuilt.flagExporter.setProvider(ctx)
|
2020-06-25 18:34:12 +02:00
|
|
|
|
2020-05-16 02:36:30 +02:00
|
|
|
srcPath, paths := srcPathFromModuleSrcs(ctx, prebuilt.prebuiltSrcs())
|
2020-07-10 03:03:28 +02:00
|
|
|
if len(paths) > 0 {
|
|
|
|
ctx.PropertyErrorf("srcs", "prebuilt libraries can only have one entry in srcs (the prebuilt path)")
|
|
|
|
}
|
2021-11-05 21:36:47 +01:00
|
|
|
prebuilt.baseCompiler.unstrippedOutputFile = srcPath
|
2022-04-19 05:12:56 +02:00
|
|
|
return buildOutput{outputFile: srcPath}
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
2019-09-20 20:00:37 +02:00
|
|
|
|
2021-03-19 23:06:02 +01:00
|
|
|
func (prebuilt *prebuiltLibraryDecorator) rustdoc(ctx ModuleContext, flags Flags,
|
|
|
|
deps PathDeps) android.OptionalPath {
|
|
|
|
|
|
|
|
return android.OptionalPath{}
|
|
|
|
}
|
|
|
|
|
2019-09-20 20:00:37 +02:00
|
|
|
func (prebuilt *prebuiltLibraryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
|
|
|
|
deps = prebuilt.baseCompiler.compilerDeps(ctx, deps)
|
|
|
|
return deps
|
|
|
|
}
|
2020-04-09 15:56:02 +02:00
|
|
|
|
|
|
|
func (prebuilt *prebuiltLibraryDecorator) nativeCoverage() bool {
|
|
|
|
return false
|
|
|
|
}
|
2020-06-25 09:47:46 +02:00
|
|
|
|
|
|
|
func (prebuilt *prebuiltLibraryDecorator) prebuiltSrcs() []string {
|
|
|
|
srcs := prebuilt.Properties.Srcs
|
|
|
|
if prebuilt.rlib() {
|
|
|
|
srcs = append(srcs, prebuilt.libraryDecorator.Properties.Rlib.Srcs...)
|
|
|
|
}
|
|
|
|
if prebuilt.dylib() {
|
|
|
|
srcs = append(srcs, prebuilt.libraryDecorator.Properties.Dylib.Srcs...)
|
|
|
|
}
|
|
|
|
|
|
|
|
return srcs
|
|
|
|
}
|
2021-11-11 15:29:07 +01:00
|
|
|
|
|
|
|
func (prebuilt *prebuiltLibraryDecorator) prebuilt() *android.Prebuilt {
|
|
|
|
return &prebuilt.Prebuilt
|
|
|
|
}
|
2022-03-23 22:31:39 +01:00
|
|
|
|
|
|
|
func (prebuilt *prebuiltProcMacroDecorator) prebuiltSrcs() []string {
|
|
|
|
srcs := prebuilt.Properties.Srcs
|
|
|
|
return srcs
|
|
|
|
}
|
|
|
|
|
|
|
|
func (prebuilt *prebuiltProcMacroDecorator) prebuilt() *android.Prebuilt {
|
|
|
|
return &prebuilt.Prebuilt
|
|
|
|
}
|
|
|
|
|
|
|
|
func (prebuilt *prebuiltProcMacroDecorator) compilerProps() []interface{} {
|
|
|
|
return append(prebuilt.procMacroDecorator.compilerProps(),
|
|
|
|
&prebuilt.Properties)
|
|
|
|
}
|
|
|
|
|
2022-04-19 05:12:56 +02:00
|
|
|
func (prebuilt *prebuiltProcMacroDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) buildOutput {
|
2022-03-23 22:31:39 +01:00
|
|
|
prebuilt.flagExporter.exportLinkDirs(android.PathsForModuleSrc(ctx, prebuilt.Properties.Link_dirs).Strings()...)
|
|
|
|
prebuilt.flagExporter.setProvider(ctx)
|
|
|
|
|
|
|
|
srcPath, paths := srcPathFromModuleSrcs(ctx, prebuilt.prebuiltSrcs())
|
|
|
|
if len(paths) > 0 {
|
|
|
|
ctx.PropertyErrorf("srcs", "prebuilt libraries can only have one entry in srcs (the prebuilt path)")
|
|
|
|
}
|
|
|
|
prebuilt.baseCompiler.unstrippedOutputFile = srcPath
|
2022-04-19 05:12:56 +02:00
|
|
|
return buildOutput{outputFile: srcPath}
|
2022-03-23 22:31:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (prebuilt *prebuiltProcMacroDecorator) rustdoc(ctx ModuleContext, flags Flags,
|
|
|
|
deps PathDeps) android.OptionalPath {
|
|
|
|
|
|
|
|
return android.OptionalPath{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (prebuilt *prebuiltProcMacroDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
|
|
|
|
deps = prebuilt.baseCompiler.compilerDeps(ctx, deps)
|
|
|
|
return deps
|
|
|
|
}
|
|
|
|
|
|
|
|
func (prebuilt *prebuiltProcMacroDecorator) nativeCoverage() bool {
|
|
|
|
return false
|
|
|
|
}
|