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)
|
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 {
|
|
|
|
*libraryDecorator
|
|
|
|
Properties PrebuiltProperties
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ compiler = (*prebuiltLibraryDecorator)(nil)
|
2020-06-25 18:34:12 +02:00
|
|
|
var _ exportedFlagsProducer = (*prebuiltLibraryDecorator)(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()
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPrebuiltLibrary(hod android.HostOrDeviceSupported) (*Module, *prebuiltLibraryDecorator) {
|
|
|
|
module, library := NewRustLibrary(hod)
|
|
|
|
library.BuildOnlyRust()
|
|
|
|
library.setNoStdlibs()
|
|
|
|
prebuilt := &prebuiltLibraryDecorator{
|
|
|
|
libraryDecorator: library,
|
|
|
|
}
|
|
|
|
module.compiler = prebuilt
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (prebuilt *prebuiltLibraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path {
|
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)")
|
|
|
|
}
|
2019-08-27 21:03:00 +02:00
|
|
|
return srcPath
|
|
|
|
}
|
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
|
|
|
|
}
|