Advertisement
Guest User

Untitled

a guest
Mar 31st, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.48 KB | None | 0 0
  1. # This file provide a Rust overlay, which provides pre-packaged bleeding edge versions of rustc
  2. # and cargo.
  3. self: super:
  4.  
  5. with import ./lib/parseTOML.nix;
  6. let
  7. # See https://github.com/rust-lang-nursery/rustup.rs/blob/master/src/rustup-dist/src/dist.rs
  8. defaultDistRoot = "https://static.rust-lang.org";
  9. manifest_v1_url = {
  10. dist_root ? defaultDistRoot + "/dist",
  11. date ? null,
  12. staging ? false,
  13. # A channel can be "nightly", "beta", "stable", "\d{1}.\d{1}.\d{1}", or "\d{1}.\d{2\d{1}".
  14. channel ? "nightly"
  15. }:
  16. if date == null && staging == false
  17. then "${dist_root}/channel-rust-${channel}"
  18. else if date != null && staging == false
  19. then "${dist_root}/${date}/channel-rust-${channel}"
  20. else if date == null && staging == true
  21. then "${dist_root}/staging/channel-rust-${channel}"
  22. else throw "not a real-world case";
  23.  
  24. manifest_v2_url = args: (manifest_v1_url args) + ".toml";
  25.  
  26. # Intersection of rustup-dist/src/dist.rs listed platforms and stdenv/default.nix.
  27. hostTripleOf = system: { # switch
  28. "i686-linux" = "i686-unknown-linux-gnu";
  29. "x86_64-linux" = "x86_64-unknown-linux-gnu";
  30. "armv5tel-linux" = "arm-unknown-linux-gnueabi";
  31. "armv6l-linux" = "arm-unknown-linux-gnueabi";
  32. "armv7l-linux" = "arm-unknown-linux-gnueabi";
  33. "aarch64-linux" = "aarch64-unknown-linux-gnu";
  34. "mips64el-linux" = "mips64el-unknown-linux-gnuabi64";
  35. "x86_64-darwin" = "x86_64-apple-darwin";
  36. "i686-cygwin" = "i686-pc-windows-gnu"; # or msvc?
  37. "x86_64-cygwin" = "x86_64-pc-windows-gnu"; # or msvc?
  38. "x86_64-freebsd" = "x86_64-unknown-freebsd";
  39. }.${system} or (throw "Rust overlay does not support ${system} yet.");
  40.  
  41. getDeps = pkgname:
  42. if pkgname == "rust"
  43. then [ "rust" "rust-src" "rust-docs" ]
  44. else [ pkgname ];
  45.  
  46. getFetchUrl = pkgs: pkgname: stdenv: fetchurl:
  47. let
  48. pkg = builtins.getAttr pkgname pkgs;
  49. srcInfo = pkg.target.${hostTripleOf stdenv.system} or pkg.target."*";
  50. print = x: builtins.trace (builtins.toJSON (x)) x;
  51. in
  52. (fetchurl { url = (print srcInfo).url; sha256 = srcInfo.hash; });
  53.  
  54. getSrcs = pkgs: pkgname: stdenv: fetchurl:
  55. let
  56. deps = getDeps pkgname;
  57. print = x: builtins.trace (builtins.toJSON (x)) x;
  58. fetchUrlFromDep = d: i: getFetchUrl pkgs (builtins.elemAt d i) stdenv fetchurl;
  59. src' = d: i: if i == 0 then [ fetchUrlFromDep d (print i) ] else builtins.concatLists [[ (fetchUrlFromDep d i) ] (src' d (i - 1))];
  60. in
  61. src' deps ((builtins.length deps) - 1);
  62.  
  63. # Manifest files are organized as follow:
  64. # { date = "2017-03-03";
  65. # pkg.cargo.version= "0.18.0-nightly (5db6d64 2017-03-03)";
  66. # pkg.cargo.target.x86_64-unknown-linux-gnu = {
  67. # available = true;
  68. # hash = "abce..."; # sha256
  69. # url = "https://static.rust-lang.org/dist/....tar.gz";
  70. # };
  71. # }
  72. #
  73. # The packages available usually are:
  74. # cargo, rust-analysis, rust-docs, rust-src, rust-std, rustc, and
  75. # rust, which aggregates them in one package.
  76. fromManifest = manifest: {stdenv, fetchurl, patchelf}:
  77. let pkgs = fromTOML (builtins.readFile (builtins.fetchurl manifest)); in
  78. with super.lib; flip mapAttrs pkgs.pkg (name: pkg:
  79. let
  80. version' = builtins.match "([^ ]*) [(]([^ ]*) ([^ ]*)[)]" pkg.version;
  81. version = "${elemAt version' 0}-${elemAt version' 2}-${elemAt version' 1}";
  82. srcs = getSrcs pkgs.pkg name stdenv fetchurl;
  83. in
  84. stdenv.mkDerivation {
  85. name = name + "-" + version;
  86. inherit srcs;
  87. sourceRoot = ".";
  88. # (@nbp) TODO: Check on Windows and Mac.
  89. # This code is inspired by patchelf/setup-hook.sh to iterate over all binaries.
  90. installPhase = ''
  91. for i in * ; do
  92. if [ -d "$i" ]; then
  93. cd $i
  94. CFG_DISABLE_LDCONFIG=1 ./install.sh --prefix=$out --verbose
  95. cd ..
  96. fi
  97. done
  98.  
  99. setInterpreter() {
  100. local dir="$1"
  101. [ -e "$dir" ] || return 0
  102.  
  103. header "Patching interpreter of ELF executables and libraries in $dir"
  104. local i
  105. while IFS= read -r -d ''$'\0' i; do
  106. if [[ "$i" =~ .build-id ]]; then continue; fi
  107. if ! isELF "$i"; then continue; fi
  108. echo "setting interpreter of $i"
  109. patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" "$i" || true
  110. done < <(find "$dir" -type f -print0)
  111. }
  112.  
  113. setInterpreter $out
  114. '';
  115. }
  116. );
  117.  
  118. in
  119.  
  120. {
  121. lib = super.lib // {
  122. inherit fromTOML;
  123. rustLib = {
  124. inherit fromManifest manifest_v2_url ;
  125. };
  126. };
  127.  
  128. # For each channel:
  129. # rustChannels.nightly.cargo
  130. # rustChannels.nightly.rust # Aggregate all others. (recommended)
  131. # rustChannels.nightly.rustc
  132. # rustChannels.nightly.rust-analysis
  133. # rustChannels.nightly.rust-docs
  134. # rustChannels.nightly.rust-src
  135. # rustChannels.nightly.rust-std
  136. rustChannels = {
  137. nightly = fromManifest (manifest_v2_url { channel = "nightly"; }) {
  138. inherit (self) stdenv fetchurl patchelf;
  139. };
  140. beta = fromManifest (manifest_v2_url { channel = "beta"; }) {
  141. inherit (self) stdenv fetchurl patchelf;
  142. };
  143. stable = fromManifest (manifest_v2_url { channel = "stable"; }) {
  144. inherit (self) stdenv fetchurl patchelf;
  145. };
  146. };
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement