summarylogtreecommitdiffstats
path: root/rust-1.98-targets.patch
blob: 69968c30dbd40702d88b89ca9ce903881677d821 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
diff --git a/build/moz.configure/rust.configure b/build/moz.configure/rust.configure
index 5525c26a184da..35cb30416c647 100644
--- a/build/moz.configure/rust.configure
+++ b/build/moz.configure/rust.configure
@@ -298,6 +298,10 @@ def detect_rustc_target(host_or_target, arm_target, rust_supported_targets):
         elif not candidates:
             return None
 
+        # config.guess uses the "pc" vendor for x86/x86_64 where rust uses its
+        # generic "unknown" vendor; normalize so we correlate on the right one.
+        vendor = "unknown" if host_or_target.vendor == "pc" else host_or_target.vendor
+
         # We have multiple candidates. There are two cases where we can try to
         # narrow further down using extra information from the build system.
         # - For windows targets, correlate with the ABI
@@ -360,11 +364,19 @@ def detect_rustc_target(host_or_target, arm_target, rust_supported_targets):
             else:
                 suffix = ""
             for p in prefixes:
-                for c in candidates:
-                    if c.rust_target.startswith(
-                        "{}-".format(p)
-                    ) and c.rust_target.endswith(suffix):
+                matches = [
+                    c
+                    for c in candidates
+                    if c.rust_target.startswith("{}-".format(p))
+                    and c.rust_target.endswith(suffix)
+                ]
+                if not matches:
+                    continue
+                # As below, correlate on the (normalized) vendor.
+                for c in matches:
+                    if c.target.vendor == vendor:
                         return c.rust_target
+                return matches[0].rust_target
 
         # See if we can narrow down on the exact alias.
         # We use the sub_configure_alias to keep support mingw32 triplets as input.
@@ -393,6 +405,15 @@ def detect_rustc_target(host_or_target, arm_target, rust_supported_targets):
             elif narrowed:
                 candidates = narrowed
 
+        # Correlate on the (normalized) vendor, so vendor-specific targets (e.g.
+        # the *-oe-linux-gnu targets added in rust 1.98) don't shadow the
+        # generic ones for aliases whose vendor doesn't match a rust target.
+        narrowed = [c for c in candidates if c.target.vendor == vendor]
+        if len(narrowed) == 1:
+            return narrowed[0].rust_target
+        elif narrowed:
+            candidates = narrowed
+
         # See if we can narrow down with the raw OS and raw CPU
         narrowed = [
             c
diff --git a/python/mozbuild/mozbuild/test/configure/test_toolchain_configure.py b/python/mozbuild/mozbuild/test/configure/test_toolchain_configure.py
index 58a736ee85fcc..7dfb0efb9201c 100644
--- a/python/mozbuild/mozbuild/test/configure/test_toolchain_configure.py
+++ b/python/mozbuild/mozbuild/test/configure/test_toolchain_configure.py
@@ -1779,6 +1779,15 @@ def invoke_rustc(stdin, args):
                 "xtensa-esp32s3-espidf",
                 "xtensa-esp32s3-none-elf",
             ]
+            # Additional targets from 1.98
+            if Version(version) >= "1.98.0":
+                rust_targets += [
+                    "aarch64-oe-linux-gnu",
+                    "armv7-oe-linux-gnueabihf",
+                    "i686-oe-linux-gnu",
+                    "riscv64-oe-linux-gnu",
+                    "x86_64-oe-linux-gnu",
+                ]
             return 0, "\n".join(sorted(rust_targets)), ""
         if (
             len(args) == 6
@@ -1869,6 +1878,7 @@ def test_rust_target(self):
             ("x86_64-unknown-linux-android", "x86_64-linux-android"),
             ("x86_64-unknown-linux-android21", "x86_64-linux-android"),
             ("x86_64-pc-linux-gnu", "x86_64-unknown-linux-gnu"),
+            ("riscv64-unknown-linux-gnu", "riscv64gc-unknown-linux-gnu"),
             ("sparcv9-sun-solaris2", "sparcv9-sun-solaris"),
             ("x86_64-sun-solaris2", "x86_64-pc-solaris"),
             ("x86_64-apple-darwin23.3.0", "x86_64-apple-darwin"),
@@ -1970,5 +1980,10 @@ def test_rust_wasi_target(self):
         self.assertEqual(self.get_rust_target("wasm32-unknown-wasi"), "wasm32-wasip1")
 
 
+# Exercises the vendor-specific *-oe-linux-* targets added in rust 1.98.
+class Rust198Test(RustTest):
+    VERSION = "1.98.0"
+
+
 if __name__ == "__main__":
     main()