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 (
|
2019-11-01 10:38:29 +08:00
|
|
|
"regexp"
|
|
|
|
"strings"
|
|
|
|
|
2019-08-28 03:03:00 +08:00
|
|
|
"android/soong/android"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
android.RegisterModuleType("rust_library", RustLibraryFactory)
|
|
|
|
android.RegisterModuleType("rust_library_dylib", RustLibraryDylibFactory)
|
|
|
|
android.RegisterModuleType("rust_library_rlib", RustLibraryRlibFactory)
|
|
|
|
android.RegisterModuleType("rust_library_host", RustLibraryHostFactory)
|
|
|
|
android.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory)
|
|
|
|
android.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory)
|
2020-06-24 05:28:53 +08:00
|
|
|
android.RegisterModuleType("rust_ffi", RustFFIFactory)
|
|
|
|
android.RegisterModuleType("rust_ffi_shared", RustFFISharedFactory)
|
|
|
|
android.RegisterModuleType("rust_ffi_static", RustFFIStaticFactory)
|
|
|
|
android.RegisterModuleType("rust_ffi_host", RustFFIHostFactory)
|
|
|
|
android.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory)
|
|
|
|
android.RegisterModuleType("rust_ffi_host_static", RustFFIStaticHostFactory)
|
2019-08-28 03:03:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type VariantLibraryProperties struct {
|
2020-06-25 15:47:46 +08:00
|
|
|
Enabled *bool `android:"arch_variant"`
|
|
|
|
Srcs []string `android:"path,arch_variant"`
|
2019-08-28 03:03:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type LibraryCompilerProperties struct {
|
2019-10-19 05:49:46 +08:00
|
|
|
Rlib VariantLibraryProperties `android:"arch_variant"`
|
|
|
|
Dylib VariantLibraryProperties `android:"arch_variant"`
|
|
|
|
Shared VariantLibraryProperties `android:"arch_variant"`
|
|
|
|
Static VariantLibraryProperties `android:"arch_variant"`
|
2019-08-28 03:03:00 +08:00
|
|
|
|
2019-10-19 05:49:46 +08:00
|
|
|
// path to include directories to pass to cc_* modules, only relevant for static/shared variants.
|
|
|
|
Include_dirs []string `android:"path,arch_variant"`
|
2019-08-28 03:03:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type LibraryMutatedProperties struct {
|
|
|
|
// Build a dylib variant
|
|
|
|
BuildDylib bool `blueprint:"mutated"`
|
|
|
|
// Build an rlib variant
|
|
|
|
BuildRlib bool `blueprint:"mutated"`
|
2019-10-19 05:49:46 +08:00
|
|
|
// Build a shared library variant
|
|
|
|
BuildShared bool `blueprint:"mutated"`
|
|
|
|
// Build a static library variant
|
|
|
|
BuildStatic bool `blueprint:"mutated"`
|
2019-08-28 03:03:00 +08:00
|
|
|
|
|
|
|
// This variant is a dylib
|
|
|
|
VariantIsDylib bool `blueprint:"mutated"`
|
|
|
|
// This variant is an rlib
|
|
|
|
VariantIsRlib bool `blueprint:"mutated"`
|
2019-10-19 05:49:46 +08:00
|
|
|
// This variant is a shared library
|
|
|
|
VariantIsShared bool `blueprint:"mutated"`
|
|
|
|
// This variant is a static library
|
|
|
|
VariantIsStatic bool `blueprint:"mutated"`
|
2020-08-01 01:40:31 +08:00
|
|
|
|
|
|
|
// This variant is disabled and should not be compiled
|
|
|
|
// (used for SourceProvider variants that produce only source)
|
|
|
|
VariantIsDisabled bool `blueprint:"mutated"`
|
2019-08-28 03:03:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type libraryDecorator struct {
|
|
|
|
*baseCompiler
|
2020-06-26 00:34:12 +08:00
|
|
|
*flagExporter
|
2020-08-27 19:48:36 +08:00
|
|
|
stripper Stripper
|
2019-08-28 03:03:00 +08:00
|
|
|
|
2020-06-16 22:26:57 +08:00
|
|
|
Properties LibraryCompilerProperties
|
|
|
|
MutatedProperties LibraryMutatedProperties
|
|
|
|
includeDirs android.Paths
|
2020-08-01 01:40:31 +08:00
|
|
|
sourceProvider SourceProvider
|
2019-08-28 03:03:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type libraryInterface interface {
|
|
|
|
rlib() bool
|
|
|
|
dylib() bool
|
2019-10-19 05:49:46 +08:00
|
|
|
static() bool
|
|
|
|
shared() bool
|
2019-08-28 03:03:00 +08:00
|
|
|
|
|
|
|
// Returns true if the build options for the module have selected a particular build type
|
|
|
|
buildRlib() bool
|
|
|
|
buildDylib() bool
|
2019-10-19 05:49:46 +08:00
|
|
|
buildShared() bool
|
|
|
|
buildStatic() bool
|
2019-08-28 03:03:00 +08:00
|
|
|
|
|
|
|
// Sets a particular variant type
|
|
|
|
setRlib()
|
|
|
|
setDylib()
|
2019-10-19 05:49:46 +08:00
|
|
|
setShared()
|
|
|
|
setStatic()
|
|
|
|
|
|
|
|
// Build a specific library variant
|
2020-06-24 05:28:53 +08:00
|
|
|
BuildOnlyFFI()
|
|
|
|
BuildOnlyRust()
|
2019-10-19 05:49:46 +08:00
|
|
|
BuildOnlyRlib()
|
|
|
|
BuildOnlyDylib()
|
|
|
|
BuildOnlyStatic()
|
|
|
|
BuildOnlyShared()
|
2019-08-28 03:03:00 +08:00
|
|
|
}
|
|
|
|
|
2020-04-09 21:56:02 +08:00
|
|
|
func (library *libraryDecorator) nativeCoverage() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2019-08-28 03:03:00 +08:00
|
|
|
func (library *libraryDecorator) rlib() bool {
|
|
|
|
return library.MutatedProperties.VariantIsRlib
|
|
|
|
}
|
|
|
|
|
|
|
|
func (library *libraryDecorator) dylib() bool {
|
|
|
|
return library.MutatedProperties.VariantIsDylib
|
|
|
|
}
|
|
|
|
|
2019-10-19 05:49:46 +08:00
|
|
|
func (library *libraryDecorator) shared() bool {
|
|
|
|
return library.MutatedProperties.VariantIsShared
|
|
|
|
}
|
|
|
|
|
|
|
|
func (library *libraryDecorator) static() bool {
|
|
|
|
return library.MutatedProperties.VariantIsStatic
|
|
|
|
}
|
|
|
|
|
2019-08-28 03:03:00 +08:00
|
|
|
func (library *libraryDecorator) buildRlib() bool {
|
|
|
|
return library.MutatedProperties.BuildRlib && BoolDefault(library.Properties.Rlib.Enabled, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (library *libraryDecorator) buildDylib() bool {
|
|
|
|
return library.MutatedProperties.BuildDylib && BoolDefault(library.Properties.Dylib.Enabled, true)
|
|
|
|
}
|
|
|
|
|
2019-10-19 05:49:46 +08:00
|
|
|
func (library *libraryDecorator) buildShared() bool {
|
|
|
|
return library.MutatedProperties.BuildShared && BoolDefault(library.Properties.Shared.Enabled, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (library *libraryDecorator) buildStatic() bool {
|
|
|
|
return library.MutatedProperties.BuildStatic && BoolDefault(library.Properties.Static.Enabled, true)
|
|
|
|
}
|
|
|
|
|
2019-08-28 03:03:00 +08:00
|
|
|
func (library *libraryDecorator) setRlib() {
|
|
|
|
library.MutatedProperties.VariantIsRlib = true
|
|
|
|
library.MutatedProperties.VariantIsDylib = false
|
2019-10-19 05:49:46 +08:00
|
|
|
library.MutatedProperties.VariantIsStatic = false
|
|
|
|
library.MutatedProperties.VariantIsShared = false
|
2019-08-28 03:03:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (library *libraryDecorator) setDylib() {
|
|
|
|
library.MutatedProperties.VariantIsRlib = false
|
|
|
|
library.MutatedProperties.VariantIsDylib = true
|
2019-10-19 05:49:46 +08:00
|
|
|
library.MutatedProperties.VariantIsStatic = false
|
|
|
|
library.MutatedProperties.VariantIsShared = false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (library *libraryDecorator) setShared() {
|
|
|
|
library.MutatedProperties.VariantIsStatic = false
|
|
|
|
library.MutatedProperties.VariantIsShared = true
|
|
|
|
library.MutatedProperties.VariantIsRlib = false
|
|
|
|
library.MutatedProperties.VariantIsDylib = false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (library *libraryDecorator) setStatic() {
|
|
|
|
library.MutatedProperties.VariantIsStatic = true
|
|
|
|
library.MutatedProperties.VariantIsShared = false
|
|
|
|
library.MutatedProperties.VariantIsRlib = false
|
|
|
|
library.MutatedProperties.VariantIsDylib = false
|
2019-08-28 03:03:00 +08:00
|
|
|
}
|
|
|
|
|
2020-08-19 02:31:23 +08:00
|
|
|
func (library *libraryDecorator) autoDep(ctx BaseModuleContext) autoDep {
|
2020-06-30 05:34:06 +08:00
|
|
|
if library.rlib() || library.static() {
|
|
|
|
return rlibAutoDep
|
|
|
|
} else if library.dylib() || library.shared() {
|
|
|
|
return dylibAutoDep
|
|
|
|
} else {
|
2020-08-19 02:31:23 +08:00
|
|
|
panic("autoDep called on library" + ctx.ModuleName() + "that has no enabled variants.")
|
2020-06-30 05:34:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-28 03:03:00 +08:00
|
|
|
var _ compiler = (*libraryDecorator)(nil)
|
2019-10-19 05:49:46 +08:00
|
|
|
var _ libraryInterface = (*libraryDecorator)(nil)
|
2020-06-26 00:34:12 +08:00
|
|
|
var _ exportedFlagsProducer = (*libraryDecorator)(nil)
|
2019-08-28 03:03:00 +08:00
|
|
|
|
2020-06-24 05:28:53 +08:00
|
|
|
// rust_library produces all rust variants.
|
2019-08-28 03:03:00 +08:00
|
|
|
func RustLibraryFactory() android.Module {
|
2020-06-24 05:28:53 +08:00
|
|
|
module, library := NewRustLibrary(android.HostAndDeviceSupported)
|
|
|
|
library.BuildOnlyRust()
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
// rust_ffi produces all ffi variants.
|
|
|
|
func RustFFIFactory() android.Module {
|
|
|
|
module, library := NewRustLibrary(android.HostAndDeviceSupported)
|
|
|
|
library.BuildOnlyFFI()
|
2019-08-28 03:03:00 +08:00
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
// rust_library_dylib produces a dylib.
|
|
|
|
func RustLibraryDylibFactory() android.Module {
|
|
|
|
module, library := NewRustLibrary(android.HostAndDeviceSupported)
|
|
|
|
library.BuildOnlyDylib()
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
// rust_library_rlib produces an rlib.
|
|
|
|
func RustLibraryRlibFactory() android.Module {
|
|
|
|
module, library := NewRustLibrary(android.HostAndDeviceSupported)
|
|
|
|
library.BuildOnlyRlib()
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2020-06-24 05:28:53 +08:00
|
|
|
// rust_ffi_shared produces a shared library.
|
|
|
|
func RustFFISharedFactory() android.Module {
|
2019-10-19 05:49:46 +08:00
|
|
|
module, library := NewRustLibrary(android.HostAndDeviceSupported)
|
|
|
|
library.BuildOnlyShared()
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2020-06-24 05:28:53 +08:00
|
|
|
// rust_ffi_static produces a static library.
|
|
|
|
func RustFFIStaticFactory() android.Module {
|
2019-10-19 05:49:46 +08:00
|
|
|
module, library := NewRustLibrary(android.HostAndDeviceSupported)
|
|
|
|
library.BuildOnlyStatic()
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2020-06-24 05:28:53 +08:00
|
|
|
// rust_library_host produces all rust variants.
|
2019-08-28 03:03:00 +08:00
|
|
|
func RustLibraryHostFactory() android.Module {
|
2020-06-24 05:28:53 +08:00
|
|
|
module, library := NewRustLibrary(android.HostSupported)
|
|
|
|
library.BuildOnlyRust()
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
// rust_ffi_host produces all FFI variants.
|
|
|
|
func RustFFIHostFactory() android.Module {
|
|
|
|
module, library := NewRustLibrary(android.HostSupported)
|
|
|
|
library.BuildOnlyFFI()
|
2019-08-28 03:03:00 +08:00
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
// rust_library_dylib_host produces a dylib.
|
|
|
|
func RustLibraryDylibHostFactory() android.Module {
|
|
|
|
module, library := NewRustLibrary(android.HostSupported)
|
|
|
|
library.BuildOnlyDylib()
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
// rust_library_rlib_host produces an rlib.
|
|
|
|
func RustLibraryRlibHostFactory() android.Module {
|
|
|
|
module, library := NewRustLibrary(android.HostSupported)
|
|
|
|
library.BuildOnlyRlib()
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2020-06-24 05:28:53 +08:00
|
|
|
// rust_ffi_static_host produces a static library.
|
|
|
|
func RustFFIStaticHostFactory() android.Module {
|
2019-10-19 05:49:46 +08:00
|
|
|
module, library := NewRustLibrary(android.HostSupported)
|
|
|
|
library.BuildOnlyStatic()
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2020-06-24 05:28:53 +08:00
|
|
|
// rust_ffi_shared_host produces an shared library.
|
|
|
|
func RustFFISharedHostFactory() android.Module {
|
2019-10-19 05:49:46 +08:00
|
|
|
module, library := NewRustLibrary(android.HostSupported)
|
|
|
|
library.BuildOnlyShared()
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2020-06-24 05:28:53 +08:00
|
|
|
func (library *libraryDecorator) BuildOnlyFFI() {
|
|
|
|
library.MutatedProperties.BuildDylib = false
|
2019-08-28 03:03:00 +08:00
|
|
|
library.MutatedProperties.BuildRlib = false
|
2020-06-24 05:28:53 +08:00
|
|
|
library.MutatedProperties.BuildShared = true
|
|
|
|
library.MutatedProperties.BuildStatic = true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (library *libraryDecorator) BuildOnlyRust() {
|
|
|
|
library.MutatedProperties.BuildDylib = true
|
|
|
|
library.MutatedProperties.BuildRlib = true
|
2019-10-19 05:49:46 +08:00
|
|
|
library.MutatedProperties.BuildShared = false
|
|
|
|
library.MutatedProperties.BuildStatic = false
|
2020-06-24 05:28:53 +08:00
|
|
|
}
|
2019-10-19 05:49:46 +08:00
|
|
|
|
2020-06-24 05:28:53 +08:00
|
|
|
func (library *libraryDecorator) BuildOnlyDylib() {
|
|
|
|
library.MutatedProperties.BuildDylib = true
|
|
|
|
library.MutatedProperties.BuildRlib = false
|
|
|
|
library.MutatedProperties.BuildShared = false
|
|
|
|
library.MutatedProperties.BuildStatic = false
|
2019-08-28 03:03:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (library *libraryDecorator) BuildOnlyRlib() {
|
|
|
|
library.MutatedProperties.BuildDylib = false
|
2020-06-24 05:28:53 +08:00
|
|
|
library.MutatedProperties.BuildRlib = true
|
2019-10-19 05:49:46 +08:00
|
|
|
library.MutatedProperties.BuildShared = false
|
|
|
|
library.MutatedProperties.BuildStatic = false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (library *libraryDecorator) BuildOnlyStatic() {
|
|
|
|
library.MutatedProperties.BuildRlib = false
|
|
|
|
library.MutatedProperties.BuildDylib = false
|
2020-06-24 05:28:53 +08:00
|
|
|
library.MutatedProperties.BuildShared = false
|
|
|
|
library.MutatedProperties.BuildStatic = true
|
2019-10-19 05:49:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (library *libraryDecorator) BuildOnlyShared() {
|
|
|
|
library.MutatedProperties.BuildRlib = false
|
|
|
|
library.MutatedProperties.BuildDylib = false
|
2020-06-24 05:28:53 +08:00
|
|
|
library.MutatedProperties.BuildStatic = false
|
|
|
|
library.MutatedProperties.BuildShared = true
|
2019-08-28 03:03:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewRustLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
|
2020-04-28 22:10:23 +08:00
|
|
|
module := newModule(hod, android.MultilibBoth)
|
2019-08-28 03:03:00 +08:00
|
|
|
|
|
|
|
library := &libraryDecorator{
|
|
|
|
MutatedProperties: LibraryMutatedProperties{
|
2020-06-24 05:28:53 +08:00
|
|
|
BuildDylib: false,
|
|
|
|
BuildRlib: false,
|
|
|
|
BuildShared: false,
|
|
|
|
BuildStatic: false,
|
2019-08-28 03:03:00 +08:00
|
|
|
},
|
2019-12-13 11:36:05 +08:00
|
|
|
baseCompiler: NewBaseCompiler("lib", "lib64", InstallInSystem),
|
2020-06-26 00:34:12 +08:00
|
|
|
flagExporter: NewFlagExporter(),
|
2019-08-28 03:03:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module.compiler = library
|
|
|
|
|
|
|
|
return module, library
|
|
|
|
}
|
|
|
|
|
|
|
|
func (library *libraryDecorator) compilerProps() []interface{} {
|
|
|
|
return append(library.baseCompiler.compilerProps(),
|
|
|
|
&library.Properties,
|
2020-08-27 19:48:36 +08:00
|
|
|
&library.MutatedProperties,
|
|
|
|
&library.stripper.StripProperties)
|
2019-08-28 03:03:00 +08:00
|
|
|
}
|
|
|
|
|
2019-09-21 02:00:37 +08:00
|
|
|
func (library *libraryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
|
|
|
|
deps = library.baseCompiler.compilerDeps(ctx, deps)
|
|
|
|
|
2019-10-19 05:49:46 +08:00
|
|
|
if ctx.toolchain().Bionic() && (library.dylib() || library.shared()) {
|
2020-07-25 04:05:01 +08:00
|
|
|
deps = bionicDeps(deps)
|
2020-04-08 01:19:44 +08:00
|
|
|
deps.CrtBegin = "crtbegin_so"
|
|
|
|
deps.CrtEnd = "crtend_so"
|
2019-09-21 02:00:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return deps
|
|
|
|
}
|
2020-06-09 20:27:49 +08:00
|
|
|
|
|
|
|
func (library *libraryDecorator) sharedLibFilename(ctx ModuleContext) string {
|
|
|
|
return library.getStem(ctx) + ctx.toolchain().SharedLibSuffix()
|
|
|
|
}
|
|
|
|
|
2019-11-07 11:15:49 +08:00
|
|
|
func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags) Flags {
|
2020-06-24 17:32:48 +08:00
|
|
|
flags.RustFlags = append(flags.RustFlags, "-C metadata="+ctx.ModuleName())
|
2019-11-07 11:15:49 +08:00
|
|
|
flags = library.baseCompiler.compilerFlags(ctx, flags)
|
|
|
|
if library.shared() || library.static() {
|
|
|
|
library.includeDirs = append(library.includeDirs, android.PathsForModuleSrc(ctx, library.Properties.Include_dirs)...)
|
|
|
|
}
|
2020-06-09 20:27:49 +08:00
|
|
|
if library.shared() {
|
|
|
|
flags.LinkFlags = append(flags.LinkFlags, "-Wl,-soname="+library.sharedLibFilename(ctx))
|
|
|
|
}
|
|
|
|
|
2019-11-07 11:15:49 +08:00
|
|
|
return flags
|
|
|
|
}
|
2019-09-21 02:00:37 +08:00
|
|
|
|
2019-08-28 03:03:00 +08:00
|
|
|
func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path {
|
2020-08-27 19:48:36 +08:00
|
|
|
var outputFile android.ModuleOutPath
|
|
|
|
var fileName string
|
2020-08-01 01:40:31 +08:00
|
|
|
var srcPath android.Path
|
2019-08-28 03:03:00 +08:00
|
|
|
|
2020-08-01 01:40:31 +08:00
|
|
|
if library.sourceProvider != nil {
|
|
|
|
srcPath = library.sourceProvider.Srcs()[0]
|
|
|
|
} else {
|
|
|
|
srcPath, _ = srcPathFromModuleSrcs(ctx, library.baseCompiler.Properties.Srcs)
|
|
|
|
}
|
2019-08-28 03:03:00 +08:00
|
|
|
|
|
|
|
flags.RustFlags = append(flags.RustFlags, deps.depFlags...)
|
2020-08-26 00:48:19 +08:00
|
|
|
flags.LinkFlags = append(flags.LinkFlags, deps.linkObjects...)
|
2019-08-28 03:03:00 +08:00
|
|
|
|
2020-01-14 08:34:34 +08:00
|
|
|
if library.dylib() {
|
2019-10-19 05:49:46 +08:00
|
|
|
// We need prefer-dynamic for now to avoid linking in the static stdlib. See:
|
|
|
|
// https://github.com/rust-lang/rust/issues/19680
|
|
|
|
// https://github.com/rust-lang/rust/issues/34909
|
|
|
|
flags.RustFlags = append(flags.RustFlags, "-C prefer-dynamic")
|
|
|
|
}
|
|
|
|
|
2019-08-28 03:03:00 +08:00
|
|
|
if library.rlib() {
|
2020-08-27 19:48:36 +08:00
|
|
|
fileName = library.getStem(ctx) + ctx.toolchain().RlibSuffix()
|
2019-08-28 03:03:00 +08:00
|
|
|
outputFile = android.PathForModuleOut(ctx, fileName)
|
|
|
|
|
2020-04-09 21:56:02 +08:00
|
|
|
outputs := TransformSrctoRlib(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)
|
|
|
|
library.coverageFile = outputs.coverageFile
|
2019-08-28 03:03:00 +08:00
|
|
|
} else if library.dylib() {
|
2020-08-27 19:48:36 +08:00
|
|
|
fileName = library.getStem(ctx) + ctx.toolchain().DylibSuffix()
|
2019-08-28 03:03:00 +08:00
|
|
|
outputFile = android.PathForModuleOut(ctx, fileName)
|
|
|
|
|
2020-04-09 21:56:02 +08:00
|
|
|
outputs := TransformSrctoDylib(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)
|
|
|
|
library.coverageFile = outputs.coverageFile
|
2019-10-19 05:49:46 +08:00
|
|
|
} else if library.static() {
|
2020-08-27 19:48:36 +08:00
|
|
|
fileName = library.getStem(ctx) + ctx.toolchain().StaticLibSuffix()
|
2019-10-19 05:49:46 +08:00
|
|
|
outputFile = android.PathForModuleOut(ctx, fileName)
|
|
|
|
|
2020-04-09 21:56:02 +08:00
|
|
|
outputs := TransformSrctoStatic(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)
|
|
|
|
library.coverageFile = outputs.coverageFile
|
2019-10-19 05:49:46 +08:00
|
|
|
} else if library.shared() {
|
2020-08-27 19:48:36 +08:00
|
|
|
fileName = library.sharedLibFilename(ctx)
|
2019-10-19 05:49:46 +08:00
|
|
|
outputFile = android.PathForModuleOut(ctx, fileName)
|
|
|
|
|
2020-04-09 21:56:02 +08:00
|
|
|
outputs := TransformSrctoShared(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)
|
|
|
|
library.coverageFile = outputs.coverageFile
|
|
|
|
}
|
|
|
|
|
2020-08-27 19:48:36 +08:00
|
|
|
if !library.rlib() && library.stripper.NeedsStrip(ctx) {
|
|
|
|
strippedOutputFile := android.PathForModuleOut(ctx, "stripped", fileName)
|
|
|
|
library.stripper.StripExecutableOrSharedLib(ctx, outputFile, strippedOutputFile)
|
|
|
|
library.strippedOutputFile = android.OptionalPathForPath(strippedOutputFile)
|
|
|
|
}
|
|
|
|
|
2020-04-09 21:56:02 +08:00
|
|
|
var coverageFiles android.Paths
|
|
|
|
if library.coverageFile != nil {
|
|
|
|
coverageFiles = append(coverageFiles, library.coverageFile)
|
|
|
|
}
|
|
|
|
if len(deps.coverageFiles) > 0 {
|
|
|
|
coverageFiles = append(coverageFiles, deps.coverageFiles...)
|
2019-08-28 03:03:00 +08:00
|
|
|
}
|
2020-04-09 21:56:02 +08:00
|
|
|
library.coverageOutputZipFile = TransformCoverageFilesToZip(ctx, coverageFiles, library.getStem(ctx))
|
2019-08-28 03:03:00 +08:00
|
|
|
|
2019-10-19 05:49:46 +08:00
|
|
|
if library.rlib() || library.dylib() {
|
2020-06-26 00:34:12 +08:00
|
|
|
library.exportLinkDirs(deps.linkDirs...)
|
|
|
|
library.exportDepFlags(deps.depFlags...)
|
2020-08-26 00:48:19 +08:00
|
|
|
library.exportLinkObjects(deps.linkObjects...)
|
2019-10-19 05:49:46 +08:00
|
|
|
}
|
2019-08-28 03:03:00 +08:00
|
|
|
|
|
|
|
return outputFile
|
|
|
|
}
|
|
|
|
|
2019-11-01 10:38:29 +08:00
|
|
|
func (library *libraryDecorator) getStem(ctx ModuleContext) string {
|
|
|
|
stem := library.baseCompiler.getStemWithoutSuffix(ctx)
|
|
|
|
validateLibraryStem(ctx, stem, library.crateName())
|
|
|
|
|
|
|
|
return stem + String(library.baseCompiler.Properties.Suffix)
|
|
|
|
}
|
|
|
|
|
2020-08-01 01:40:31 +08:00
|
|
|
func (library *libraryDecorator) Disabled() bool {
|
|
|
|
return library.MutatedProperties.VariantIsDisabled
|
|
|
|
}
|
|
|
|
|
|
|
|
func (library *libraryDecorator) SetDisabled() {
|
|
|
|
library.MutatedProperties.VariantIsDisabled = true
|
|
|
|
}
|
|
|
|
|
2019-11-01 10:38:29 +08:00
|
|
|
var validCrateName = regexp.MustCompile("[^a-zA-Z0-9_]+")
|
|
|
|
|
|
|
|
func validateLibraryStem(ctx BaseModuleContext, filename string, crate_name string) {
|
|
|
|
if crate_name == "" {
|
|
|
|
ctx.PropertyErrorf("crate_name", "crate_name must be defined.")
|
|
|
|
}
|
|
|
|
|
|
|
|
// crate_names are used for the library output file, and rustc expects these
|
|
|
|
// to be alphanumeric with underscores allowed.
|
|
|
|
if validCrateName.MatchString(crate_name) {
|
|
|
|
ctx.PropertyErrorf("crate_name",
|
|
|
|
"library crate_names must be alphanumeric with underscores allowed")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Libraries are expected to begin with "lib" followed by the crate_name
|
|
|
|
if !strings.HasPrefix(filename, "lib"+crate_name) {
|
|
|
|
ctx.ModuleErrorf("Invalid name or stem property; library filenames must start with lib<crate_name>")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-28 03:03:00 +08:00
|
|
|
func LibraryMutator(mctx android.BottomUpMutatorContext) {
|
|
|
|
if m, ok := mctx.Module().(*Module); ok && m.compiler != nil {
|
|
|
|
switch library := m.compiler.(type) {
|
|
|
|
case libraryInterface:
|
2020-07-31 23:01:18 +08:00
|
|
|
if library.buildRlib() && library.buildDylib() {
|
2020-08-01 01:40:31 +08:00
|
|
|
variants := []string{"rlib", "dylib"}
|
|
|
|
if m.sourceProvider != nil {
|
|
|
|
variants = append(variants, "")
|
|
|
|
}
|
|
|
|
modules := mctx.CreateLocalVariations(variants...)
|
|
|
|
|
2020-07-31 23:01:18 +08:00
|
|
|
rlib := modules[0].(*Module)
|
|
|
|
dylib := modules[1].(*Module)
|
|
|
|
rlib.compiler.(libraryInterface).setRlib()
|
|
|
|
dylib.compiler.(libraryInterface).setDylib()
|
2020-08-01 01:40:31 +08:00
|
|
|
|
|
|
|
if m.sourceProvider != nil {
|
|
|
|
// This library is SourceProvider generated, so the non-library-producing
|
|
|
|
// variant needs to disable it's compiler and skip installation.
|
|
|
|
sourceProvider := modules[2].(*Module)
|
|
|
|
sourceProvider.compiler.SetDisabled()
|
|
|
|
}
|
2020-07-31 23:01:18 +08:00
|
|
|
} else if library.buildRlib() {
|
|
|
|
modules := mctx.CreateLocalVariations("rlib")
|
|
|
|
modules[0].(*Module).compiler.(libraryInterface).setRlib()
|
|
|
|
} else if library.buildDylib() {
|
|
|
|
modules := mctx.CreateLocalVariations("dylib")
|
|
|
|
modules[0].(*Module).compiler.(libraryInterface).setDylib()
|
2019-08-28 03:03:00 +08:00
|
|
|
}
|
2020-08-01 01:40:31 +08:00
|
|
|
|
|
|
|
if m.sourceProvider != nil {
|
|
|
|
// Alias the non-library variant to the empty-string variant.
|
|
|
|
mctx.AliasVariation("")
|
|
|
|
}
|
2019-08-28 03:03:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|