diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2021-11-01 21:48:55 -0400 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2021-11-07 14:16:49 -0500 |
commit | 18ed048c7b27e288a6c9ba894790a7e67ed5080d (patch) | |
tree | d510e8594b5ee2a9784a15e0ec2a8337c99bc977 /pkgs/build-support/rust/lib | |
parent | 3b0bff383f8e894b1ee7a30b62c8b727a68511df (diff) |
build-support/rust: Organize
- `toRustTarget` and friends pulled out from rust tools into rust library. Since they don't depend on any packages they can be more widely useable. - `build-rust-package` gets its own directory - `fetch-cargo-tarball` gets its own directory
Diffstat (limited to 'pkgs/build-support/rust/lib')
-rw-r--r-- | pkgs/build-support/rust/lib/default.nix | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/pkgs/build-support/rust/lib/default.nix b/pkgs/build-support/rust/lib/default.nix new file mode 100644 index 0000000000000..24adcf2cb4e20 --- /dev/null +++ b/pkgs/build-support/rust/lib/default.nix @@ -0,0 +1,37 @@ +{ lib }: + +rec { + # https://doc.rust-lang.org/reference/conditional-compilation.html#target_arch + toTargetArch = platform: + if platform.isAarch32 then "arm" + else platform.parsed.cpu.name; + + # https://doc.rust-lang.org/reference/conditional-compilation.html#target_os + toTargetOs = platform: + if platform.isDarwin then "macos" + else platform.parsed.kernel.name; + + # 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 + inherit (platform.parsed) cpu vendor kernel abi; + cpu_ = platform.rustc.platform.arch or { + "armv7a" = "armv7"; + "armv7l" = "armv7"; + "armv6l" = "arm"; + "armv5tel" = "armv5te"; + "riscv64" = "riscv64gc"; + }.${cpu.name} or cpu.name; + vendor_ = platform.rustc.platform.vendor or { + "w64" = "pc"; + }.${vendor.name} or vendor.name; + in platform.rustc.config + or "${cpu_}-${vendor_}-${kernel.name}${lib.optionalString (abi.name != "unknown") "-${abi.name}"}"; + + # Returns the name of the rust target if it is standard, or the json file + # containing the custom target spec. + toRustTargetSpec = platform: + if (platform.rustc or {}) ? platform + then builtins.toFile (toRustTarget platform + ".json") (builtins.toJSON platform.rustc.platform) + else toRustTarget platform; +} |