Page MenuHomeDevCentral

D4022.id.diff
No OneTemporary

D4022.id.diff

diff --git a/_modules/rust.py b/_modules/rust.py
--- a/_modules/rust.py
+++ b/_modules/rust.py
@@ -9,17 +9,13 @@
# -------------------------------------------------------------
+import os
+import subprocess
+
from salt.utils.path import which as path_which
-def __virtual__():
- """
- Only load if the Rust compiler is available
- """
- return (
- path_which("rustc") is not None,
- "The Rust execution module cannot be loaded: rustc not installed.",
- )
+can_call_rustc = path_which("rustc") is not None
def get_rustc_triplet():
@@ -31,5 +27,108 @@
salt * rust.get_rustc_triplet
"""
+ if not can_call_rustc:
+ return guess_rust_triplet()
+
# Thanks to @semarie for that tip.
return __salt__["cmd.shell"]("rustc -vV | sed -ne 's/^host: //p'")
+
+
+def _get_arch():
+ arch = os.uname().machine
+
+ if arch == "amd64":
+ return "x86_64"
+
+ if arch.startswith("armv6"):
+ return "arm"
+
+ if arch == "arm64":
+ return "aarch64"
+
+ return arch
+
+
+def _get_os():
+ uname_os = os.uname().sysname.lower()
+
+ if uname_os == "linux":
+ return "linux-gnu"
+
+ return uname_os
+
+
+def guess_rust_triplet():
+ arch = _get_arch()
+ os_part = _get_os()
+
+ if arch == "arm":
+ triplet = _guess_arm32_rust_triplet(os_part)
+ else:
+ triplet = [arch, "unknown", os_part]
+
+ return "-".join(triplet)
+
+
+# -------------------------------------------------------------
+# ARM 32-bits specific code
+#
+# Rust is available in several targets for Linux:
+# - arm-unknown-linux-gnueabi
+# - arm-unknown-linux-gnueabihf
+# - arm-unknown-linux-musleabi
+# - arm-unknown-linux-musleabihf
+#
+# We need to determine if we use glibc or musl
+# and guess hard-float support.
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def _guess_arm32_rust_triplet(os_part):
+ if os_part == "linux-gnu":
+ return ["arm", "unknown", _get_linux_arm_ebi()]
+
+ return ["armv6", "unknown", os_part]
+
+
+def _get_linux_arm_ebi():
+ if not path_which("ldd"):
+ raise ValueError("Not yet supported - need to guess glibc vs musl")
+
+ result = subprocess.run(
+ ["ldd", "--version"],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ text=True,
+ )
+
+ if result.returncode != 0:
+ raise ValueError("Failed to run ldd: " + result.stderr)
+
+ if "musl" in result.stdout.lower():
+ abi = "musleabi"
+ elif "glibc" in result.stdout.lower():
+ abi = "gnueabi"
+ else:
+ raise ValueError("Can't determine libc type")
+
+ if _guess_arm32_is_hard_float():
+ abi += "hf"
+
+ return abi
+
+
+def _guess_arm32_is_hard_float():
+ try:
+ with open("/proc/cpuinfo", "r") as f:
+ cpuinfo = f.read()
+ except FileNotFoundError:
+ raise ValueError("Can't guess hard-float ABI: /proc/cpuinfo not found.")
+
+ hard_float_flags = ["vfp", "vfpv3", "vfpv4", "neon", "fpa"]
+ for line in cpuinfo.splitlines():
+ if line.startswith(("features", "flags")):
+ cpu_flags = line.split(":", 1)[1].strip().split()
+ return any(flag in cpu_flags for flag in hard_float_flags)
+
+ raise ValueError("Can't parse /proc/cpuinfo to read CPU flags.")

File Metadata

Mime Type
text/plain
Expires
Tue, Mar 24, 01:22 (3 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3557263
Default Alt Text
D4022.id.diff (3 KB)

Event Timeline