Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at 21.05 106 lines 4.4 kB view raw
1{ rustcVersion 2, rustcSha256 3, enableRustcDev ? true 4, bootstrapVersion 5, bootstrapHashes 6, selectRustPackage 7, rustcPatches ? [] 8, llvmBootstrapForDarwin 9, llvmShared 10, llvmSharedForBuild 11, llvmSharedForHost 12, llvmSharedForTarget 13}: 14{ stdenv, lib 15, buildPackages 16, newScope, callPackage 17, CoreFoundation, Security 18, pkgsBuildTarget, pkgsBuildBuild 19, makeRustPlatform 20}: rec { 21 # https://doc.rust-lang.org/reference/conditional-compilation.html#target_arch 22 toTargetArch = platform: 23 if platform.isAarch32 then "arm" 24 else platform.parsed.cpu.name; 25 26 # https://doc.rust-lang.org/reference/conditional-compilation.html#target_os 27 toTargetOs = platform: 28 if platform.isDarwin then "macos" 29 else platform.parsed.kernel.name; 30 31 # Returns the name of the rust target, even if it is custom. Adjustments are 32 # because rust has slightly different naming conventions than we do. 33 toRustTarget = platform: with platform.parsed; let 34 cpu_ = platform.rustc.platform.arch or { 35 "armv7a" = "armv7"; 36 "armv7l" = "armv7"; 37 "armv6l" = "arm"; 38 "armv5tel" = "armv5te"; 39 }.${cpu.name} or cpu.name; 40 in platform.rustc.config 41 or "${cpu_}-${vendor.name}-${kernel.name}${lib.optionalString (abi.name != "unknown") "-${abi.name}"}"; 42 43 # Returns the name of the rust target if it is standard, or the json file 44 # containing the custom target spec. 45 toRustTargetSpec = platform: 46 if (platform.rustc or {}) ? platform 47 then builtins.toFile (toRustTarget platform + ".json") (builtins.toJSON platform.rustc.platform) 48 else toRustTarget platform; 49 50 # This just contains tools for now. But it would conceivably contain 51 # libraries too, say if we picked some default/recommended versions from 52 # `cratesIO` to build by Hydra and/or try to prefer/bias in Cargo.lock for 53 # all vendored Carnix-generated nix. 54 # 55 # In the end game, rustc, the rust standard library (`core`, `std`, etc.), 56 # and cargo would themselves be built with `buildRustCreate` like 57 # everything else. Tools and `build.rs` and procedural macro dependencies 58 # would be taken from `buildRustPackages` (and `bootstrapRustPackages` for 59 # anything provided prebuilt or their build-time dependencies to break 60 # cycles / purify builds). In this way, nixpkgs would be in control of all 61 # bootstrapping. 62 packages = { 63 prebuilt = callPackage ./bootstrap.nix { 64 version = bootstrapVersion; 65 hashes = bootstrapHashes; 66 }; 67 stable = lib.makeScope newScope (self: let 68 # Like `buildRustPackages`, but may also contain prebuilt binaries to 69 # break cycle. Just like `bootstrapTools` for nixpkgs as a whole, 70 # nothing in the final package set should refer to this. 71 bootstrapRustPackages = self.buildRustPackages.overrideScope' (_: _: 72 lib.optionalAttrs (stdenv.buildPlatform == stdenv.hostPlatform) 73 (selectRustPackage buildPackages).packages.prebuilt); 74 bootRustPlatform = makeRustPlatform bootstrapRustPackages; 75 in { 76 # Packages suitable for build-time, e.g. `build.rs`-type stuff. 77 buildRustPackages = (selectRustPackage buildPackages).packages.stable; 78 # Analogous to stdenv 79 rustPlatform = makeRustPlatform self.buildRustPackages; 80 rustc = self.callPackage ./rustc.nix ({ 81 version = rustcVersion; 82 sha256 = rustcSha256; 83 inherit enableRustcDev; 84 inherit llvmShared llvmSharedForBuild llvmSharedForHost llvmSharedForTarget; 85 86 patches = rustcPatches; 87 88 # Use boot package set to break cycle 89 rustPlatform = bootRustPlatform; 90 } // lib.optionalAttrs (stdenv.cc.isClang && stdenv.hostPlatform == stdenv.buildPlatform) { 91 stdenv = llvmBootstrapForDarwin.stdenv; 92 pkgsBuildBuild = pkgsBuildBuild // { targetPackages.stdenv = llvmBootstrapForDarwin.stdenv; }; 93 pkgsBuildHost = pkgsBuildBuild // { targetPackages.stdenv = llvmBootstrapForDarwin.stdenv; }; 94 pkgsBuildTarget = pkgsBuildTarget // { targetPackages.stdenv = llvmBootstrapForDarwin.stdenv; }; 95 }); 96 rustfmt = self.callPackage ./rustfmt.nix { inherit Security; }; 97 cargo = self.callPackage ./cargo.nix { 98 # Use boot package set to break cycle 99 rustPlatform = bootRustPlatform; 100 inherit CoreFoundation Security; 101 }; 102 clippy = self.callPackage ./clippy.nix { inherit Security; }; 103 rls = self.callPackage ./rls { inherit CoreFoundation Security; }; 104 }); 105 }; 106}