about summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2022-11-09 15:52:01 -0500
committerJohn Ericson <John.Ericson@Obsidian.Systems>2022-11-09 15:52:01 -0500
commite94d54dd864062a18aaf75510600c8264353ccb8 (patch)
tree537fa3e4e9286315bd3106eaeab13411c490b37b /pkgs/build-support
parent550202ecdfc4ed721b7ec49267c16553e05103b0 (diff)
build-support/rust/lib: Add `toTargetFamily`
Taken from https://github.com/kolloch/crate2nix/pull/255/files, it
belongs in Nixpkgs not crate2nix.

I have been using that P.R. for a few months without incident.
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/rust/lib/default.nix15
1 files changed, 15 insertions, 0 deletions
diff --git a/pkgs/build-support/rust/lib/default.nix b/pkgs/build-support/rust/lib/default.nix
index 5eac208cc31ca..77397f9b7220c 100644
--- a/pkgs/build-support/rust/lib/default.nix
+++ b/pkgs/build-support/rust/lib/default.nix
@@ -15,6 +15,21 @@ rec {
     else if platform.isDarwin then "macos"
     else platform.parsed.kernel.name;
 
+  # https://doc.rust-lang.org/reference/conditional-compilation.html#target_family
+  toTargetFamily = platform:
+    if platform ? rustc.platform.target-family
+    then
+      (
+        # Since https://github.com/rust-lang/rust/pull/84072
+        # `target-family` is a list instead of single value.
+        let
+          f = platform.rustc.platform.target-family;
+        in
+        if builtins.isList f then f else [ f ]
+      )
+    else lib.optional platform.isUnix "unix"
+      ++ lib.optional platform.isWindows "windows";
+
   # Returns the name of the rust target, even if it is custom. Adjustments are
   # because rust has slightly different naming conventions than we do.
   toRustTarget = platform: let