summaryrefslogtreecommitdiff
path: root/rust/compiler.go
diff options
context:
space:
mode:
author Andrew Walbran <qwandor@google.com> 2024-03-19 11:36:04 +0000
committer Andrew Walbran <qwandor@google.com> 2024-03-19 17:27:46 +0000
commit52533237ef02050a97e36527bb751cf1b395468c (patch)
tree9ddb89cda44a36bf7d47cc0ef370f410d3eafc13 /rust/compiler.go
parent84fedd36a40eec4319fa3c084cd4f90543415ef8 (diff)
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
Diffstat (limited to 'rust/compiler.go')
-rw-r--r--rust/compiler.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/rust/compiler.go b/rust/compiler.go
index c1bdbeb91..03fdf2b7a 100644
--- a/rust/compiler.go
+++ b/rust/compiler.go
@@ -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() {