1From 2817f07563070d71b624b4397af32d820efec244 Mon Sep 17 00:00:00 2001
2From: Takuro Ashie <ashie@clear-code.com>
3Date: Thu, 18 Apr 2019 23:15:16 +0900
4Subject: [PATCH] Bug 1545437 - Add options to specify Rust target name
5
6 r?glandium
7
8Certain build systems such as Yocto know more suitable Rust target name, so it
9would be better that there is a way to pass it to Mozilla's build system.
10
11Differential Revision: https://phabricator.services.mozilla.com/D28069
12
13---
14 build/moz.configure/rust.configure | 37 ++++++++++++++++++++++++++----
15 1 file changed, 33 insertions(+), 4 deletions(-)
16
17diff --git a/build/moz.configure/rust.configure b/build/moz.configure/rust.configure
18index dc23355253..e2d9a8552f 100644
19--- a/build/moz.configure/rust.configure
20+++ b/build/moz.configure/rust.configure
21@@ -211,6 +211,28 @@ def rust_supported_targets(rustc):
22     return data
23
24
25+option(env='RUST_HOST',
26+       nargs=1,
27+       help='Define the system type for Rust performing the build')
28+
29+@depends('RUST_HOST')
30+@checking('rust host', lambda host: host)
31+def rust_host_env(value):
32+    if value:
33+        return value[0]
34+
35+
36+option(env='RUST_TARGET',
37+       nargs=1,
38+       help='Define the system type for Rust where the resulting executables will be used')
39+
40+@depends('RUST_TARGET')
41+@checking('rust target', lambda target: target)
42+def rust_target_env(value):
43+    if value:
44+        return value[0]
45+
46+
47 @template
48 def rust_triple_alias(host_or_target):
49     """Template defining the alias used for rustc's --target flag.
50@@ -221,8 +243,9 @@ def rust_triple_alias(host_or_target):
51
52     host_or_target_str = {host: 'host', target: 'target'}[host_or_target]
53
54-    @depends(rustc, host_or_target, c_compiler, rust_supported_targets,
55-             arm_target, when=rust_compiler)
56+    @depends(rustc, host_or_target, rust_host_env, rust_target_env,
57+             c_compiler, rust_supported_targets, arm_target,
58+             when=rust_compiler)
59     @checking('for rust %s triplet' % host_or_target_str)
60     @imports('os')
61     @imports('subprocess')
62@@ -230,8 +253,14 @@ def rust_triple_alias(host_or_target):
63     @imports(_from='mozbuild.shellutil', _import='quote')
64     @imports(_from='tempfile', _import='mkstemp')
65     @imports(_from='textwrap', _import='dedent')
66-    def rust_target(rustc, host_or_target, compiler_info,
67-                    rust_supported_targets, arm_target):
68+    def rust_target(rustc, host_or_target, rust_host_env, rust_target_env,
69+                    compiler_info, rust_supported_targets, arm_target):
70+
71+        specified_targets = {"host": rust_host_env, "target": rust_target_env}
72+        specified_target = specified_targets[host_or_target_str]
73+        if (specified_target):
74+            return specified_target
75+
76         # Rust's --target options are similar to, but not exactly the same
77         # as, the autoconf-derived targets we use.  An example would be that
78         # Rust uses distinct target triples for targetting the GNU C++ ABI
79