2020-07-08 14:39:44 +02:00
|
|
|
// Copyright 2020 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"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SourceProviderProperties struct {
|
2020-08-05 19:28:32 +02:00
|
|
|
// filename for the generated source file (<source_stem>.rs). This field is required.
|
|
|
|
// The inherited "stem" property sets the output filename for the generated library variants only.
|
2020-07-31 19:40:31 +02:00
|
|
|
Source_stem *string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// crate name, used for the library variant of this source provider. See additional details in rust_library.
|
|
|
|
Crate_name string `android:"arch_variant"`
|
2020-07-08 14:39:44 +02:00
|
|
|
}
|
|
|
|
|
2020-08-05 15:36:19 +02:00
|
|
|
type BaseSourceProvider struct {
|
2020-07-08 14:39:44 +02:00
|
|
|
Properties SourceProviderProperties
|
|
|
|
|
2020-10-28 14:32:10 +01:00
|
|
|
// The first file in OutputFiles must be the library entry point.
|
2022-09-21 15:13:35 +02:00
|
|
|
OutputFiles android.Paths
|
|
|
|
subName string
|
2020-07-08 14:39:44 +02:00
|
|
|
}
|
|
|
|
|
2020-08-05 15:36:19 +02:00
|
|
|
var _ SourceProvider = (*BaseSourceProvider)(nil)
|
2020-07-08 14:39:44 +02:00
|
|
|
|
|
|
|
type SourceProvider interface {
|
2020-08-27 13:37:29 +02:00
|
|
|
GenerateSource(ctx ModuleContext, deps PathDeps) android.Path
|
2020-07-08 14:39:44 +02:00
|
|
|
Srcs() android.Paths
|
2020-08-05 15:36:19 +02:00
|
|
|
SourceProviderProps() []interface{}
|
|
|
|
SourceProviderDeps(ctx DepsContext, deps Deps) Deps
|
2020-07-31 19:40:31 +02:00
|
|
|
setSubName(subName string)
|
2020-10-02 06:25:05 +02:00
|
|
|
setOutputFiles(outputFiles android.Paths)
|
2020-07-08 14:39:44 +02:00
|
|
|
}
|
|
|
|
|
2020-08-05 15:36:19 +02:00
|
|
|
func (sp *BaseSourceProvider) Srcs() android.Paths {
|
2020-10-02 06:25:05 +02:00
|
|
|
return sp.OutputFiles
|
2020-07-08 14:39:44 +02:00
|
|
|
}
|
|
|
|
|
2020-08-27 13:37:29 +02:00
|
|
|
func (sp *BaseSourceProvider) GenerateSource(ctx ModuleContext, deps PathDeps) android.Path {
|
2020-08-05 15:36:19 +02:00
|
|
|
panic("BaseSourceProviderModule does not implement GenerateSource()")
|
2020-07-08 14:39:44 +02:00
|
|
|
}
|
|
|
|
|
2020-08-05 15:36:19 +02:00
|
|
|
func (sp *BaseSourceProvider) SourceProviderProps() []interface{} {
|
2020-07-08 14:39:44 +02:00
|
|
|
return []interface{}{&sp.Properties}
|
|
|
|
}
|
|
|
|
|
2020-08-05 15:36:19 +02:00
|
|
|
func NewSourceProvider() *BaseSourceProvider {
|
|
|
|
return &BaseSourceProvider{
|
2020-07-08 14:39:44 +02:00
|
|
|
Properties: SourceProviderProperties{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-10 22:25:50 +02:00
|
|
|
func NewSourceProviderModule(hod android.HostOrDeviceSupported, sourceProvider SourceProvider, enableLints bool, rlibOnly bool) *Module {
|
2020-08-05 15:36:19 +02:00
|
|
|
_, library := NewRustLibrary(hod)
|
|
|
|
library.BuildOnlyRust()
|
2022-08-10 22:25:50 +02:00
|
|
|
if rlibOnly {
|
|
|
|
library.BuildOnlyRlib()
|
|
|
|
}
|
2020-08-05 15:36:19 +02:00
|
|
|
library.sourceProvider = sourceProvider
|
|
|
|
|
|
|
|
module := newModule(hod, android.MultilibBoth)
|
|
|
|
module.sourceProvider = sourceProvider
|
|
|
|
module.compiler = library
|
|
|
|
|
|
|
|
if !enableLints {
|
2020-08-13 12:55:59 +02:00
|
|
|
library.disableLints()
|
|
|
|
module.disableClippy()
|
2020-08-05 15:36:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sp *BaseSourceProvider) getStem(ctx android.ModuleContext) string {
|
2020-08-05 19:28:32 +02:00
|
|
|
if String(sp.Properties.Source_stem) == "" {
|
|
|
|
ctx.PropertyErrorf("source_stem",
|
|
|
|
"source_stem property is undefined but required for rust_bindgen modules")
|
2020-07-08 14:39:44 +02:00
|
|
|
}
|
2020-08-05 19:28:32 +02:00
|
|
|
return String(sp.Properties.Source_stem)
|
2020-07-08 14:39:44 +02:00
|
|
|
}
|
|
|
|
|
2020-08-05 15:36:19 +02:00
|
|
|
func (sp *BaseSourceProvider) SourceProviderDeps(ctx DepsContext, deps Deps) Deps {
|
2020-07-08 14:39:44 +02:00
|
|
|
return deps
|
|
|
|
}
|
2020-07-31 19:40:31 +02:00
|
|
|
|
2020-08-05 15:36:19 +02:00
|
|
|
func (sp *BaseSourceProvider) setSubName(subName string) {
|
2020-07-31 19:40:31 +02:00
|
|
|
sp.subName = subName
|
|
|
|
}
|
2020-09-23 18:10:17 +02:00
|
|
|
|
2020-10-02 06:25:05 +02:00
|
|
|
func (sp *BaseSourceProvider) setOutputFiles(outputFiles android.Paths) {
|
|
|
|
sp.OutputFiles = outputFiles
|
2020-09-23 18:10:17 +02:00
|
|
|
}
|