Add aliases property for renaming Rust dependencies.

This is equivalent to specifying a dependency name different to the
package name in cargo, which some external crates do.

Bug: 308790322
Test: Built libgrpcio with aliases for protobuf
Change-Id: I2801222051fdd962460cc7f4900cec357f63b974
This commit is contained in:
Andrew Walbran
2024-03-19 11:36:04 +00:00
parent 84fedd36a4
commit 52533237ef
3 changed files with 66 additions and 3 deletions

View File

@@ -75,6 +75,8 @@ type compiler interface {
strippedOutputFilePath() android.OptionalPath
checkedCrateRootPath() (android.Path, error)
Aliases() map[string]string
}
func (compiler *baseCompiler) edition() string {
@@ -140,6 +142,12 @@ type BaseCompilerProperties struct {
// flags to pass to the linker
Ld_flags []string `android:"arch_variant"`
// Rust crate dependencies to rename. Each entry should be a string of the form "dependencyname:alias".
//
// "dependencyname" here should be the name of the crate, not the Android module. This is
// equivalent to writing `alias = { package = "dependencyname" }` in a `Cargo.toml`.
Aliases []string
// list of rust rlib crate dependencies
Rlibs []string `android:"arch_variant"`
@@ -281,6 +289,18 @@ func (compiler *baseCompiler) preferRlib() bool {
return Bool(compiler.Properties.Prefer_rlib)
}
func (compiler *baseCompiler) Aliases() map[string]string {
aliases := map[string]string{}
for _, entry := range compiler.Properties.Aliases {
dep, alias, found := strings.Cut(entry, ":")
if !found {
panic(fmt.Errorf("invalid aliases entry %q missing ':'", entry))
}
aliases[dep] = alias
}
return aliases
}
func (compiler *baseCompiler) stdLinkage(ctx *depsContext) RustLinkage {
// For devices, we always link stdlibs in as dylibs by default.
if compiler.preferRlib() {