2019-08-28 03:03:00 +08: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 15:47:46 +08:00
|
|
|
android.RegisterModuleType("rust_prebuilt_library", PrebuiltLibraryFactory)
|
2019-08-28 03:03:00 +08:00
|
|
|
android.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
|
2020-06-25 15:47:46 +08:00
|
|
|
android.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory)
|
2019-08-28 03:03:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type PrebuiltProperties struct {
|
|
|
|
// path to the prebuilt file
|
|
|
|
Srcs []string `android:"path,arch_variant"`
|
2020-06-26 00:34:12 +08:00
|
|
|
// directories containing associated rlib dependencies
|
|
|
|
Link_dirs []string `android:"path,arch_variant"`
|
2019-08-28 03:03:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type prebuiltLibraryDecorator struct {
|
|
|
|
*libraryDecorator
|
|
|
|
Properties PrebuiltProperties
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ compiler = (*prebuiltLibraryDecorator)(nil)
|
2020-06-26 00:34:12 +08:00
|
|
|
var _ exportedFlagsProducer = (*prebuiltLibraryDecorator)(nil)
|
2019-08-28 03:03:00 +08:00
|
|
|
|
2020-06-25 15:47:46 +08:00
|
|
|
func PrebuiltLibraryFactory() android.Module {
|
|
|
|
module, _ := NewPrebuiltLibrary(android.HostAndDeviceSupported)
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2019-08-28 03:03:00 +08:00
|
|
|
func PrebuiltDylibFactory() android.Module {
|
|
|
|
module, _ := NewPrebuiltDylib(android.HostAndDeviceSupported)
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2020-06-25 15:47:46 +08: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-28 03:03:00 +08:00
|
|
|
func NewPrebuiltDylib(hod android.HostOrDeviceSupported) (*Module, *prebuiltLibraryDecorator) {
|
|
|
|
module, library := NewRustLibrary(hod)
|
|
|
|
library.BuildOnlyDylib()
|
2019-11-01 01:44:40 +08:00
|
|
|
library.setNoStdlibs()
|
2020-06-25 15:47:46 +08: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-28 03:03:00 +08:00
|
|
|
prebuilt := &prebuiltLibraryDecorator{
|
|
|
|
libraryDecorator: library,
|
|
|
|
}
|
|
|
|
module.compiler = prebuilt
|
|
|
|
return module, prebuilt
|
|
|
|
}
|
|
|
|
|
|
|
|
func (prebuilt *prebuiltLibraryDecorator) compilerProps() []interface{} {
|
2020-06-30 04:31:04 +08:00
|
|
|
return append(prebuilt.libraryDecorator.compilerProps(),
|
2019-08-28 03:03:00 +08:00
|
|
|
&prebuilt.Properties)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (prebuilt *prebuiltLibraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path {
|
2020-09-19 05:15:30 +08:00
|
|
|
prebuilt.flagExporter.exportLinkDirs(android.PathsForModuleSrc(ctx, prebuilt.Properties.Link_dirs).Strings()...)
|
|
|
|
prebuilt.flagExporter.setProvider(ctx)
|
2020-06-26 00:34:12 +08:00
|
|
|
|
2020-05-16 08:36:30 +08:00
|
|
|
srcPath, paths := srcPathFromModuleSrcs(ctx, prebuilt.prebuiltSrcs())
|
2020-07-10 09:03:28 +08:00
|
|
|
if len(paths) > 0 {
|
|
|
|
ctx.PropertyErrorf("srcs", "prebuilt libraries can only have one entry in srcs (the prebuilt path)")
|
|
|
|
}
|
2019-08-28 03:03:00 +08:00
|
|
|
return srcPath
|
|
|
|
}
|
2019-09-21 02:00:37 +08:00
|
|
|
|
|
|
|
func (prebuilt *prebuiltLibraryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
|
|
|
|
deps = prebuilt.baseCompiler.compilerDeps(ctx, deps)
|
|
|
|
return deps
|
|
|
|
}
|
2020-04-09 21:56:02 +08:00
|
|
|
|
|
|
|
func (prebuilt *prebuiltLibraryDecorator) nativeCoverage() bool {
|
|
|
|
return false
|
|
|
|
}
|
2020-06-25 15:47:46 +08: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
|
|
|
|
}
|