From 5bca001f9703940e693d6a55944ef1ee7fc67f58 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Fri, 2 Aug 2019 00:50:29 +0200 Subject: build: support crate imports using an alias name A crate can assign an alternative name, different from the crate name, when importing another crate. On the command line this looks like: rustc ... --extern foo_crate=path/to/bar_crate.rlib We need to support this so we can eventually upgrade to rand-0.7.x. --- build_extra/rust/rust.gni | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'build_extra/rust') diff --git a/build_extra/rust/rust.gni b/build_extra/rust/rust.gni index b4c128e71..787888bc2 100644 --- a/build_extra/rust/rust.gni +++ b/build_extra/rust/rust.gni @@ -148,12 +148,10 @@ template("_rust_crate") { extern_outputs += [ { label = info.label - crate_name = info.crate_name crate_type = info.crate_type + crate_name = info.crate_name - if (!defined(info.crate_version)) { - crate_suffix = "" - } else { + if (defined(info.crate_version)) { crate_version = info.crate_version crate_suffix = exec_script("//tools/sha256sum.py", [ @@ -161,6 +159,14 @@ template("_rust_crate") { "--format=-%.8s", ], "trim string") + } else { + crate_suffix = "" + } + + if (defined(info.crate_alias)) { + crate_alias = info.crate_alias + } else { + crate_alias = info.crate_name } if (crate_type == "rlib") { @@ -293,7 +299,7 @@ template("_rust_crate") { foreach(info, extern_outputs) { args += [ "--extern", - info.crate_name + "=" + rebase_path(info.out_path, root_build_dir), + info.crate_alias + "=" + rebase_path(info.out_path, root_build_dir), ] sources += [ info.out_path ] deps += [ info.label ] -- cgit v1.2.3