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 (
|
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
2021-07-27 18:29:12 +02:00
|
|
|
"strings"
|
2019-08-27 21:03:00 +02:00
|
|
|
|
2019-11-01 03:38:29 +01:00
|
|
|
"github.com/google/blueprint/proptools"
|
|
|
|
|
2019-08-27 21:03:00 +02:00
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/rust/config"
|
|
|
|
)
|
|
|
|
|
2020-09-28 19:22:45 +02:00
|
|
|
type RustLinkage int
|
|
|
|
|
|
|
|
const (
|
|
|
|
DefaultLinkage RustLinkage = iota
|
|
|
|
RlibLinkage
|
|
|
|
DylibLinkage
|
|
|
|
)
|
|
|
|
|
2020-08-03 10:46:28 +02:00
|
|
|
func (compiler *baseCompiler) edition() string {
|
2019-10-03 18:47:06 +02:00
|
|
|
return proptools.StringDefault(compiler.Properties.Edition, config.DefaultEdition)
|
|
|
|
}
|
|
|
|
|
2019-10-31 18:44:40 +01:00
|
|
|
func (compiler *baseCompiler) setNoStdlibs() {
|
|
|
|
compiler.Properties.No_stdlibs = proptools.BoolPtr(true)
|
|
|
|
}
|
|
|
|
|
2020-08-13 12:55:59 +02:00
|
|
|
func (compiler *baseCompiler) disableLints() {
|
|
|
|
compiler.Properties.Lints = proptools.StringPtr("none")
|
2020-08-04 22:02:28 +02:00
|
|
|
}
|
|
|
|
|
2019-12-13 04:36:05 +01:00
|
|
|
func NewBaseCompiler(dir, dir64 string, location installLocation) *baseCompiler {
|
2019-08-27 21:03:00 +02:00
|
|
|
return &baseCompiler{
|
2019-10-03 18:47:06 +02:00
|
|
|
Properties: BaseCompilerProperties{},
|
|
|
|
dir: dir,
|
|
|
|
dir64: dir64,
|
2019-12-13 04:36:05 +01:00
|
|
|
location: location,
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-13 04:36:05 +01:00
|
|
|
type installLocation int
|
|
|
|
|
|
|
|
const (
|
|
|
|
InstallInSystem installLocation = 0
|
|
|
|
InstallInData = iota
|
2020-07-10 03:03:28 +02:00
|
|
|
|
|
|
|
incorrectSourcesError = "srcs can only contain one path for a rust file and source providers prefixed by \":\""
|
2021-02-25 16:30:57 +01:00
|
|
|
genSubDir = "out/"
|
2019-12-13 04:36:05 +01:00
|
|
|
)
|
|
|
|
|
2019-08-27 21:03:00 +02:00
|
|
|
type BaseCompilerProperties struct {
|
2021-08-11 19:39:33 +02:00
|
|
|
// path to the source file that is the main entry point of the program (e.g. main.rs or lib.rs).
|
|
|
|
// Only a single source file can be defined. Modules which generate source can be included by prefixing
|
|
|
|
// the module name with ":", for example ":libfoo_bindgen"
|
|
|
|
//
|
|
|
|
// If no source file is defined, a single generated source module can be defined to be used as the main source.
|
2020-06-16 16:26:57 +02:00
|
|
|
Srcs []string `android:"path,arch_variant"`
|
|
|
|
|
2020-08-13 12:55:59 +02:00
|
|
|
// name of the lint set that should be used to validate this module.
|
|
|
|
//
|
|
|
|
// Possible values are "default" (for using a sensible set of lints
|
|
|
|
// depending on the module's location), "android" (for the strictest
|
|
|
|
// lint set that applies to all Android platform code), "vendor" (for
|
|
|
|
// a relaxed set) and "none" (for ignoring all lint warnings and
|
|
|
|
// errors). The default value is "default".
|
|
|
|
Lints *string
|
2019-09-27 03:59:27 +02:00
|
|
|
|
2021-04-07 14:53:06 +02:00
|
|
|
// flags to pass to rustc. To enable configuration options or features, use the "cfgs" or "features" properties.
|
2021-04-20 16:15:41 +02:00
|
|
|
Flags []string `android:"arch_variant"`
|
2019-08-27 21:03:00 +02:00
|
|
|
|
|
|
|
// flags to pass to the linker
|
2021-04-20 16:15:41 +02:00
|
|
|
Ld_flags []string `android:"arch_variant"`
|
2019-08-27 21:03:00 +02:00
|
|
|
|
|
|
|
// list of rust rlib crate dependencies
|
|
|
|
Rlibs []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// list of rust dylib crate dependencies
|
|
|
|
Dylibs []string `android:"arch_variant"`
|
|
|
|
|
2020-06-29 23:34:06 +02:00
|
|
|
// list of rust automatic crate dependencies
|
|
|
|
Rustlibs []string `android:"arch_variant"`
|
|
|
|
|
2019-08-27 21:03:00 +02:00
|
|
|
// list of rust proc_macro crate dependencies
|
|
|
|
Proc_macros []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// list of C shared library dependencies
|
|
|
|
Shared_libs []string `android:"arch_variant"`
|
|
|
|
|
2021-03-23 20:53:44 +01:00
|
|
|
// list of C static library dependencies. These dependencies do not normally propagate to dependents
|
|
|
|
// and may need to be redeclared. See whole_static_libs for bundling static dependencies into a library.
|
2019-08-27 21:03:00 +02:00
|
|
|
Static_libs []string `android:"arch_variant"`
|
|
|
|
|
2021-03-23 20:53:44 +01:00
|
|
|
// Similar to static_libs, but will bundle the static library dependency into a library. This is helpful
|
|
|
|
// to avoid having to redeclare the dependency for dependents of this library, but in some cases may also
|
|
|
|
// result in bloat if multiple dependencies all include the same static library whole.
|
|
|
|
//
|
|
|
|
// The common use case for this is when the static library is unlikely to be a dependency of other modules to avoid
|
|
|
|
// having to redeclare the static library dependency for every dependent module.
|
|
|
|
// If you are not sure what to, for rust_library modules most static dependencies should go in static_libraries,
|
|
|
|
// and for rust_ffi modules most static dependencies should go into whole_static_libraries.
|
|
|
|
//
|
|
|
|
// For rust_ffi static variants, these libraries will be included in the resulting static library archive.
|
|
|
|
//
|
|
|
|
// For rust_library rlib variants, these libraries will be bundled into the resulting rlib library. This will
|
|
|
|
// include all of the static libraries symbols in any dylibs or binaries which use this rlib as well.
|
|
|
|
Whole_static_libs []string `android:"arch_variant"`
|
|
|
|
|
2020-07-31 19:40:31 +02:00
|
|
|
// crate name, required for modules which produce Rust libraries: rust_library, rust_ffi and SourceProvider
|
|
|
|
// modules which create library variants (rust_bindgen). This must be the expected extern crate name used in
|
|
|
|
// source, and is required to conform to an enforced format matching library output files (if the output file is
|
|
|
|
// lib<someName><suffix>, the crate_name property must be <someName>).
|
2019-08-27 21:03:00 +02:00
|
|
|
Crate_name string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// list of features to enable for this crate
|
|
|
|
Features []string `android:"arch_variant"`
|
|
|
|
|
2021-04-07 14:53:06 +02:00
|
|
|
// list of configuration options to enable for this crate. To enable features, use the "features" property.
|
|
|
|
Cfgs []string `android:"arch_variant"`
|
|
|
|
|
2019-08-27 21:03:00 +02:00
|
|
|
// specific rust edition that should be used if the default version is not desired
|
|
|
|
Edition *string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// sets name of the output
|
|
|
|
Stem *string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// append to name of output
|
|
|
|
Suffix *string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// install to a subdirectory of the default install path for the module
|
|
|
|
Relative_install_path *string `android:"arch_variant"`
|
2019-10-31 18:44:40 +01:00
|
|
|
|
|
|
|
// whether to suppress inclusion of standard crates - defaults to false
|
|
|
|
No_stdlibs *bool
|
2020-12-08 20:43:00 +01:00
|
|
|
|
|
|
|
// Change the rustlibs linkage to select rlib linkage by default for device targets.
|
|
|
|
// Also link libstd as an rlib as well on device targets.
|
|
|
|
// Note: This is the default behavior for host targets.
|
|
|
|
//
|
|
|
|
// This is primarily meant for rust_binary and rust_ffi modules where the default
|
|
|
|
// linkage of libstd might need to be overridden in some use cases. This should
|
|
|
|
// generally be avoided with other module types since it may cause collisions at
|
|
|
|
// linkage if all dependencies of the root binary module do not link against libstd\
|
|
|
|
// the same way.
|
|
|
|
Prefer_rlib *bool `android:"arch_variant"`
|
2021-08-11 21:13:43 +02:00
|
|
|
|
|
|
|
// Enables emitting certain Cargo environment variables. Only intended to be used for compatibility purposes.
|
|
|
|
// Will set CARGO_CRATE_NAME to the crate_name property's value.
|
|
|
|
// Will set CARGO_BIN_NAME to the output filename value without the extension.
|
|
|
|
Cargo_env_compat *bool
|
|
|
|
|
|
|
|
// If cargo_env_compat is true, sets the CARGO_PKG_VERSION env var to this value.
|
|
|
|
Cargo_pkg_version *string
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type baseCompiler struct {
|
2021-01-15 01:03:18 +01:00
|
|
|
Properties BaseCompilerProperties
|
2019-08-27 21:03:00 +02:00
|
|
|
|
|
|
|
// Install related
|
|
|
|
dir string
|
|
|
|
dir64 string
|
|
|
|
subDir string
|
|
|
|
relative string
|
2019-10-02 07:05:35 +02:00
|
|
|
path android.InstallPath
|
2019-12-13 04:36:05 +01:00
|
|
|
location installLocation
|
2020-02-11 14:24:25 +01:00
|
|
|
sanitize *sanitize
|
2020-06-16 16:26:57 +02:00
|
|
|
|
2021-01-15 01:03:18 +01:00
|
|
|
distFile android.OptionalPath
|
2020-08-27 13:48:36 +02:00
|
|
|
// Stripped output file. If Valid(), this file will be installed instead of outputFile.
|
|
|
|
strippedOutputFile android.OptionalPath
|
2021-02-25 16:30:57 +01:00
|
|
|
|
|
|
|
// If a crate has a source-generated dependency, a copy of the source file
|
|
|
|
// will be available in cargoOutDir (equivalent to Cargo OUT_DIR).
|
|
|
|
cargoOutDir android.ModuleOutPath
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
|
2020-07-31 19:40:31 +02:00
|
|
|
func (compiler *baseCompiler) Disabled() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (compiler *baseCompiler) SetDisabled() {
|
|
|
|
panic("baseCompiler does not implement SetDisabled()")
|
|
|
|
}
|
|
|
|
|
2020-04-09 15:56:02 +02:00
|
|
|
func (compiler *baseCompiler) coverageOutputZipPath() android.OptionalPath {
|
|
|
|
panic("baseCompiler does not implement coverageOutputZipPath()")
|
|
|
|
}
|
|
|
|
|
2020-12-08 20:43:00 +01:00
|
|
|
func (compiler *baseCompiler) preferRlib() bool {
|
|
|
|
return Bool(compiler.Properties.Prefer_rlib)
|
|
|
|
}
|
|
|
|
|
2020-09-28 19:22:45 +02:00
|
|
|
func (compiler *baseCompiler) stdLinkage(ctx *depsContext) RustLinkage {
|
2020-09-08 18:46:52 +02:00
|
|
|
// For devices, we always link stdlibs in as dylibs by default.
|
2020-12-08 20:43:00 +01:00
|
|
|
if compiler.preferRlib() {
|
|
|
|
return RlibLinkage
|
|
|
|
} else if ctx.Device() {
|
2020-09-28 19:22:45 +02:00
|
|
|
return DylibLinkage
|
2020-09-08 18:46:52 +02:00
|
|
|
} else {
|
2020-09-28 19:22:45 +02:00
|
|
|
return RlibLinkage
|
2020-09-08 18:46:52 +02:00
|
|
|
}
|
2020-08-18 20:31:23 +02:00
|
|
|
}
|
|
|
|
|
2019-08-27 21:03:00 +02:00
|
|
|
var _ compiler = (*baseCompiler)(nil)
|
|
|
|
|
2019-12-13 04:36:05 +01:00
|
|
|
func (compiler *baseCompiler) inData() bool {
|
|
|
|
return compiler.location == InstallInData
|
|
|
|
}
|
|
|
|
|
2019-08-27 21:03:00 +02:00
|
|
|
func (compiler *baseCompiler) compilerProps() []interface{} {
|
|
|
|
return []interface{}{&compiler.Properties}
|
|
|
|
}
|
|
|
|
|
2021-04-07 14:53:06 +02:00
|
|
|
func (compiler *baseCompiler) cfgsToFlags() []string {
|
|
|
|
flags := []string{}
|
|
|
|
for _, cfg := range compiler.Properties.Cfgs {
|
|
|
|
flags = append(flags, "--cfg '"+cfg+"'")
|
|
|
|
}
|
2021-09-23 17:50:33 +02:00
|
|
|
|
2021-04-07 14:53:06 +02:00
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
|
|
|
func (compiler *baseCompiler) featuresToFlags() []string {
|
2019-08-27 21:03:00 +02:00
|
|
|
flags := []string{}
|
2021-04-07 14:53:06 +02:00
|
|
|
for _, feature := range compiler.Properties.Features {
|
2019-08-27 21:03:00 +02:00
|
|
|
flags = append(flags, "--cfg 'feature=\""+feature+"\"'")
|
|
|
|
}
|
2021-09-23 17:50:33 +02:00
|
|
|
|
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
|
|
|
func (compiler *baseCompiler) featureFlags(ctx ModuleContext, flags Flags) Flags {
|
|
|
|
flags.RustFlags = append(flags.RustFlags, compiler.featuresToFlags()...)
|
|
|
|
flags.RustdocFlags = append(flags.RustdocFlags, compiler.featuresToFlags()...)
|
|
|
|
|
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
|
|
|
func (compiler *baseCompiler) cfgFlags(ctx ModuleContext, flags Flags) Flags {
|
|
|
|
if ctx.RustModule().UseVndk() {
|
|
|
|
compiler.Properties.Cfgs = append(compiler.Properties.Cfgs, "android_vndk")
|
|
|
|
}
|
|
|
|
|
|
|
|
flags.RustFlags = append(flags.RustFlags, compiler.cfgsToFlags()...)
|
|
|
|
flags.RustdocFlags = append(flags.RustdocFlags, compiler.cfgsToFlags()...)
|
2019-08-27 21:03:00 +02:00
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
|
|
|
func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flags {
|
|
|
|
|
2020-08-13 12:55:59 +02:00
|
|
|
lintFlags, err := config.RustcLintsForDir(ctx.ModuleDir(), compiler.Properties.Lints)
|
|
|
|
if err != nil {
|
|
|
|
ctx.PropertyErrorf("lints", err.Error())
|
2019-09-27 03:59:27 +02:00
|
|
|
}
|
2021-07-27 18:29:12 +02:00
|
|
|
|
|
|
|
// linkage-related flags are disallowed.
|
|
|
|
for _, s := range compiler.Properties.Ld_flags {
|
|
|
|
if strings.HasPrefix(s, "-Wl,-l") || strings.HasPrefix(s, "-Wl,-L") {
|
|
|
|
ctx.PropertyErrorf("ld_flags", "'-Wl,-l' and '-Wl,-L' flags cannot be manually specified")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, s := range compiler.Properties.Flags {
|
|
|
|
if strings.HasPrefix(s, "-l") || strings.HasPrefix(s, "-L") {
|
|
|
|
ctx.PropertyErrorf("flags", "'-l' and '-L' flags cannot be manually specified")
|
|
|
|
}
|
|
|
|
if strings.HasPrefix(s, "--extern") {
|
|
|
|
ctx.PropertyErrorf("flags", "'--extern' flag cannot be manually specified")
|
|
|
|
}
|
|
|
|
if strings.HasPrefix(s, "-Clink-args=") || strings.HasPrefix(s, "-C link-args=") {
|
|
|
|
ctx.PropertyErrorf("flags", "'-C link-args' flag cannot be manually specified")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-13 12:55:59 +02:00
|
|
|
flags.RustFlags = append(flags.RustFlags, lintFlags)
|
2019-08-27 21:03:00 +02:00
|
|
|
flags.RustFlags = append(flags.RustFlags, compiler.Properties.Flags...)
|
2020-08-03 10:46:28 +02:00
|
|
|
flags.RustFlags = append(flags.RustFlags, "--edition="+compiler.edition())
|
2021-03-19 23:06:02 +01:00
|
|
|
flags.RustdocFlags = append(flags.RustdocFlags, "--edition="+compiler.edition())
|
2019-08-27 21:03:00 +02:00
|
|
|
flags.LinkFlags = append(flags.LinkFlags, compiler.Properties.Ld_flags...)
|
2019-09-30 22:01:37 +02:00
|
|
|
flags.GlobalRustFlags = append(flags.GlobalRustFlags, config.GlobalRustFlags...)
|
2019-09-20 20:00:37 +02:00
|
|
|
flags.GlobalRustFlags = append(flags.GlobalRustFlags, ctx.toolchain().ToolchainRustFlags())
|
|
|
|
flags.GlobalLinkFlags = append(flags.GlobalLinkFlags, ctx.toolchain().ToolchainLinkFlags())
|
2019-08-27 21:03:00 +02:00
|
|
|
|
|
|
|
if ctx.Host() && !ctx.Windows() {
|
2020-12-21 18:11:10 +01:00
|
|
|
rpathPrefix := `\$$ORIGIN/`
|
2019-08-27 21:03:00 +02:00
|
|
|
if ctx.Darwin() {
|
2020-12-21 18:11:10 +01:00
|
|
|
rpathPrefix = "@loader_path/"
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var rpath string
|
|
|
|
if ctx.toolchain().Is64Bit() {
|
|
|
|
rpath = "lib64"
|
|
|
|
} else {
|
|
|
|
rpath = "lib"
|
|
|
|
}
|
2020-12-21 18:11:10 +01:00
|
|
|
flags.LinkFlags = append(flags.LinkFlags, "-Wl,-rpath,"+rpathPrefix+rpath)
|
|
|
|
flags.LinkFlags = append(flags.LinkFlags, "-Wl,-rpath,"+rpathPrefix+"../"+rpath)
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
|
|
|
func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path {
|
|
|
|
panic(fmt.Errorf("baseCrater doesn't know how to crate things!"))
|
|
|
|
}
|
|
|
|
|
2021-03-19 23:06:02 +01:00
|
|
|
func (compiler *baseCompiler) rustdoc(ctx ModuleContext, flags Flags,
|
|
|
|
deps PathDeps) android.OptionalPath {
|
|
|
|
|
|
|
|
return android.OptionalPath{}
|
|
|
|
}
|
|
|
|
|
2021-02-25 16:30:57 +01:00
|
|
|
func (compiler *baseCompiler) initialize(ctx ModuleContext) {
|
|
|
|
compiler.cargoOutDir = android.PathForModuleOut(ctx, genSubDir)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (compiler *baseCompiler) CargoOutDir() android.OptionalPath {
|
|
|
|
return android.OptionalPathForPath(compiler.cargoOutDir)
|
|
|
|
}
|
|
|
|
|
2021-08-11 21:13:43 +02:00
|
|
|
func (compiler *baseCompiler) CargoEnvCompat() bool {
|
|
|
|
return Bool(compiler.Properties.Cargo_env_compat)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (compiler *baseCompiler) CargoPkgVersion() string {
|
|
|
|
return String(compiler.Properties.Cargo_pkg_version)
|
|
|
|
}
|
|
|
|
|
2021-04-07 08:08:04 +02:00
|
|
|
func (compiler *baseCompiler) strippedOutputFilePath() android.OptionalPath {
|
|
|
|
return compiler.strippedOutputFile
|
|
|
|
}
|
|
|
|
|
2019-08-27 21:03:00 +02:00
|
|
|
func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps {
|
|
|
|
deps.Rlibs = append(deps.Rlibs, compiler.Properties.Rlibs...)
|
|
|
|
deps.Dylibs = append(deps.Dylibs, compiler.Properties.Dylibs...)
|
2020-06-29 23:34:06 +02:00
|
|
|
deps.Rustlibs = append(deps.Rustlibs, compiler.Properties.Rustlibs...)
|
2019-08-27 21:03:00 +02:00
|
|
|
deps.ProcMacros = append(deps.ProcMacros, compiler.Properties.Proc_macros...)
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, compiler.Properties.Static_libs...)
|
2021-03-23 20:53:44 +01:00
|
|
|
deps.WholeStaticLibs = append(deps.WholeStaticLibs, compiler.Properties.Whole_static_libs...)
|
2019-08-27 21:03:00 +02:00
|
|
|
deps.SharedLibs = append(deps.SharedLibs, compiler.Properties.Shared_libs...)
|
|
|
|
|
2019-10-31 18:44:40 +01:00
|
|
|
if !Bool(compiler.Properties.No_stdlibs) {
|
|
|
|
for _, stdlib := range config.Stdlibs {
|
2020-08-31 10:22:01 +02:00
|
|
|
// If we're building for the primary arch of the build host, use the compiler's stdlibs
|
2021-07-20 18:47:41 +02:00
|
|
|
if ctx.Target().Os == ctx.Config().BuildOS {
|
2019-10-31 18:44:40 +01:00
|
|
|
stdlib = stdlib + "_" + ctx.toolchain().RustTriple()
|
|
|
|
}
|
2020-09-08 18:46:52 +02:00
|
|
|
deps.Stdlibs = append(deps.Stdlibs, stdlib)
|
2019-10-31 18:44:40 +01:00
|
|
|
}
|
|
|
|
}
|
2019-08-27 21:03:00 +02:00
|
|
|
return deps
|
|
|
|
}
|
|
|
|
|
2021-03-22 14:24:54 +01:00
|
|
|
func bionicDeps(ctx DepsContext, deps Deps, static bool) Deps {
|
2020-10-02 16:03:23 +02:00
|
|
|
bionicLibs := []string{}
|
|
|
|
bionicLibs = append(bionicLibs, "liblog")
|
|
|
|
bionicLibs = append(bionicLibs, "libc")
|
|
|
|
bionicLibs = append(bionicLibs, "libm")
|
|
|
|
bionicLibs = append(bionicLibs, "libdl")
|
|
|
|
|
|
|
|
if static {
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, bionicLibs...)
|
|
|
|
} else {
|
|
|
|
deps.SharedLibs = append(deps.SharedLibs, bionicLibs...)
|
|
|
|
}
|
2021-08-13 19:14:06 +02:00
|
|
|
if ctx.RustModule().StaticExecutable() {
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, "libunwind")
|
|
|
|
}
|
2021-03-22 14:24:54 +01:00
|
|
|
if libRuntimeBuiltins := config.BuiltinsRuntimeLibrary(ctx.toolchain()); libRuntimeBuiltins != "" {
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, libRuntimeBuiltins)
|
|
|
|
}
|
2019-09-20 20:00:37 +02:00
|
|
|
return deps
|
|
|
|
}
|
|
|
|
|
2019-08-27 21:03:00 +02:00
|
|
|
func (compiler *baseCompiler) crateName() string {
|
|
|
|
return compiler.Properties.Crate_name
|
|
|
|
}
|
|
|
|
|
2021-04-01 15:49:36 +02:00
|
|
|
func (compiler *baseCompiler) everInstallable() bool {
|
|
|
|
// Most modules are installable, so return true by default.
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2019-10-02 07:05:35 +02:00
|
|
|
func (compiler *baseCompiler) installDir(ctx ModuleContext) android.InstallPath {
|
2019-08-27 21:03:00 +02:00
|
|
|
dir := compiler.dir
|
|
|
|
if ctx.toolchain().Is64Bit() && compiler.dir64 != "" {
|
|
|
|
dir = compiler.dir64
|
|
|
|
}
|
2020-04-07 18:30:33 +02:00
|
|
|
if ctx.Target().NativeBridge == android.NativeBridgeEnabled {
|
|
|
|
dir = filepath.Join(dir, ctx.Target().NativeBridgeRelativePath)
|
|
|
|
}
|
|
|
|
if !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) {
|
2019-08-27 21:03:00 +02:00
|
|
|
dir = filepath.Join(dir, ctx.Arch().ArchType.String())
|
|
|
|
}
|
2021-04-02 18:41:32 +02:00
|
|
|
|
|
|
|
if compiler.location == InstallInData && ctx.RustModule().UseVndk() {
|
2021-08-19 22:10:05 +02:00
|
|
|
if ctx.RustModule().InProduct() {
|
|
|
|
dir = filepath.Join(dir, "product")
|
|
|
|
} else if ctx.RustModule().InVendor() {
|
|
|
|
dir = filepath.Join(dir, "vendor")
|
|
|
|
} else {
|
|
|
|
ctx.ModuleErrorf("Unknown data+VNDK installation kind")
|
|
|
|
}
|
2021-04-02 18:41:32 +02:00
|
|
|
}
|
2021-08-19 22:10:05 +02:00
|
|
|
|
2019-08-27 21:03:00 +02:00
|
|
|
return android.PathForModuleInstall(ctx, dir, compiler.subDir,
|
|
|
|
compiler.relativeInstallPath(), compiler.relative)
|
|
|
|
}
|
|
|
|
|
2020-04-09 15:56:02 +02:00
|
|
|
func (compiler *baseCompiler) nativeCoverage() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-08-27 13:48:36 +02:00
|
|
|
func (compiler *baseCompiler) install(ctx ModuleContext) {
|
2021-04-07 08:08:04 +02:00
|
|
|
path := ctx.RustModule().OutputFile()
|
2020-08-27 13:48:36 +02:00
|
|
|
compiler.path = ctx.InstallFile(compiler.installDir(ctx), path.Path().Base(), path.Path())
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (compiler *baseCompiler) getStem(ctx ModuleContext) string {
|
|
|
|
return compiler.getStemWithoutSuffix(ctx) + String(compiler.Properties.Suffix)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (compiler *baseCompiler) getStemWithoutSuffix(ctx BaseModuleContext) string {
|
2020-06-24 11:32:48 +02:00
|
|
|
stem := ctx.ModuleName()
|
2019-08-27 21:03:00 +02:00
|
|
|
if String(compiler.Properties.Stem) != "" {
|
|
|
|
stem = String(compiler.Properties.Stem)
|
|
|
|
}
|
|
|
|
|
|
|
|
return stem
|
|
|
|
}
|
2019-11-01 03:38:29 +01:00
|
|
|
|
2019-08-27 21:03:00 +02:00
|
|
|
func (compiler *baseCompiler) relativeInstallPath() string {
|
|
|
|
return String(compiler.Properties.Relative_install_path)
|
|
|
|
}
|
|
|
|
|
2020-07-10 03:03:28 +02:00
|
|
|
// Returns the Path for the main source file along with Paths for generated source files from modules listed in srcs.
|
2020-05-16 02:36:30 +02:00
|
|
|
func srcPathFromModuleSrcs(ctx ModuleContext, srcs []string) (android.Path, android.Paths) {
|
|
|
|
// The srcs can contain strings with prefix ":".
|
|
|
|
// They are dependent modules of this module, with android.SourceDepTag.
|
|
|
|
// They are not the main source file compiled by rustc.
|
|
|
|
numSrcs := 0
|
|
|
|
srcIndex := 0
|
|
|
|
for i, s := range srcs {
|
|
|
|
if android.SrcIsModule(s) == "" {
|
|
|
|
numSrcs++
|
|
|
|
srcIndex = i
|
|
|
|
}
|
|
|
|
}
|
2021-08-11 19:39:33 +02:00
|
|
|
if numSrcs > 1 {
|
2020-07-10 03:03:28 +02:00
|
|
|
ctx.PropertyErrorf("srcs", incorrectSourcesError)
|
2020-05-16 02:36:30 +02:00
|
|
|
}
|
2021-08-11 19:39:33 +02:00
|
|
|
|
|
|
|
// If a main source file is not provided we expect only a single SourceProvider module to be defined
|
|
|
|
// within srcs, with the expectation that the first source it provides is the entry point.
|
2020-05-16 02:36:30 +02:00
|
|
|
if srcIndex != 0 {
|
|
|
|
ctx.PropertyErrorf("srcs", "main source file must be the first in srcs")
|
2021-08-11 19:39:33 +02:00
|
|
|
} else if numSrcs > 1 {
|
|
|
|
ctx.PropertyErrorf("srcs", "only a single generated source module can be defined without a main source file.")
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
2021-08-11 19:39:33 +02:00
|
|
|
|
2020-05-16 02:36:30 +02:00
|
|
|
paths := android.PathsForModuleSrc(ctx, srcs)
|
2020-07-10 03:03:28 +02:00
|
|
|
return paths[srcIndex], paths[1:]
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|