1# New rust versions should first go to staging.
2# Things to check after updating:
3# 1. Rustc should produce rust binaries on x86_64-linux, aarch64-linux and x86_64-darwin:
4# i.e. nix-shell -p fd or @GrahamcOfBorg build fd on github
5# This testing can be also done by other volunteers as part of the pull
6# request review, in case platforms cannot be covered.
7# 2. The LLVM version used for building should match with rust upstream.
8# Check the version number in the src/llvm-project git submodule in:
9# https://github.com/rust-lang/rust/blob/<version-tag>/.gitmodules
10# 3. Firefox and Thunderbird should still build on x86_64-linux.
11
12{
13 stdenv,
14 lib,
15 newScope,
16 callPackage,
17 pkgsBuildTarget,
18 pkgsBuildBuild,
19 pkgsBuildHost,
20 pkgsHostTarget,
21 pkgsTargetTarget,
22 makeRustPlatform,
23 wrapRustcWith,
24 llvmPackages_19,
25 llvm_19,
26 wrapCCWith,
27 overrideCC,
28 fetchpatch,
29}@args:
30let
31 llvmSharedFor =
32 pkgSet:
33 pkgSet.llvmPackages_19.libllvm.override (
34 {
35 enableSharedLibraries = true;
36 }
37 // lib.optionalAttrs (stdenv.targetPlatform.useLLVM or false) {
38 # Force LLVM to compile using clang + LLVM libs when targeting pkgsLLVM
39 stdenv = pkgSet.stdenv.override {
40 allowedRequisites = null;
41 cc = pkgSet.pkgsBuildHost.llvmPackages_19.clangUseLLVM;
42 };
43 }
44 );
45in
46import ./default.nix
47 {
48 rustcVersion = "1.86.0";
49 rustcSha256 = "sha256-AionKG32eQCgRNIn2dtp1HMuw9gz5P/CWcRCXtce7YA=";
50
51 rustcPatches = [
52 # Fix for including no_std targets by default, shipping in Rust 1.87
53 # https://github.com/rust-lang/rust/pull/137073
54 (fetchpatch {
55 name = "bootstrap-skip-nostd-docs";
56 url = "https://github.com/rust-lang/rust/commit/97962d7643300b91c102496ba3ab6d9279d2c536.patch";
57 hash = "sha256-DKl9PWqJP3mX4B1pFeRLQ8/sO6mx1JhbmVLTOOMLZI4=";
58 })
59 ];
60
61 llvmSharedForBuild = llvmSharedFor pkgsBuildBuild;
62 llvmSharedForHost = llvmSharedFor pkgsBuildHost;
63 llvmSharedForTarget = llvmSharedFor pkgsBuildTarget;
64
65 # For use at runtime
66 llvmShared = llvmSharedFor pkgsHostTarget;
67
68 # Expose llvmPackages used for rustc from rustc via passthru for LTO in Firefox
69 llvmPackages =
70 if (stdenv.targetPlatform.useLLVM or false) then
71 callPackage (
72 {
73 pkgs,
74 bootBintoolsNoLibc ? if stdenv.targetPlatform.linker == "lld" then null else pkgs.bintoolsNoLibc,
75 bootBintools ? if stdenv.targetPlatform.linker == "lld" then null else pkgs.bintools,
76 }:
77 let
78 llvmPackages = llvmPackages_19;
79
80 setStdenv =
81 pkg:
82 pkg.override {
83 stdenv = stdenv.override {
84 allowedRequisites = null;
85 cc = pkgsBuildHost.llvmPackages_19.clangUseLLVM;
86 };
87 };
88 in
89 rec {
90 inherit (llvmPackages) bintools;
91
92 libunwind = setStdenv llvmPackages.libunwind;
93 llvm = setStdenv llvmPackages.llvm;
94
95 libcxx = llvmPackages.libcxx.override {
96 stdenv = stdenv.override {
97 allowedRequisites = null;
98 cc = pkgsBuildHost.llvmPackages_19.clangNoLibcxx;
99 hostPlatform = stdenv.hostPlatform // {
100 useLLVM = !stdenv.hostPlatform.isDarwin;
101 };
102 };
103 inherit libunwind;
104 };
105
106 clangUseLLVM = llvmPackages.clangUseLLVM.override { inherit libcxx; };
107
108 stdenv = overrideCC args.stdenv clangUseLLVM;
109 }
110 ) { }
111 else
112 llvmPackages_19;
113
114 # Note: the version MUST be the same version that we are building. Upstream
115 # ensures that each released compiler can compile itself:
116 # https://github.com/NixOS/nixpkgs/pull/351028#issuecomment-2438244363
117 bootstrapVersion = "1.86.0";
118
119 # fetch hashes by running `print-hashes.sh ${bootstrapVersion}`
120 bootstrapHashes = {
121 i686-unknown-linux-gnu = "6d39b7599f872fe330e64800ca2ebfd58624d78e135c491226f44f5ff68b900d";
122 x86_64-unknown-linux-gnu = "f6a8c0d8b8a8a737c40eee78abe286a3cbe984d96b63de9ae83443360e3264bf";
123 x86_64-unknown-linux-musl = "2d399a43e1e4a2dea0e16f83cd0a1dd53f7f32250ba25970ea5d9c31a16df611";
124 arm-unknown-linux-gnueabihf = "d7af8bdf97c76b2c2df50486597dd0ad8af36b9213549f3e0d15384d36bc0a37";
125 armv7-unknown-linux-gnueabihf = "fbddb4d24d701362c65201dc0905f7445eb9dfa3a5d767ff29a5d3f676957253";
126 aarch64-unknown-linux-gnu = "460058cd78f06875721427a42a5ce6a8b8ef2c0c3225fccfae149d9345572ff4";
127 aarch64-unknown-linux-musl = "fcfc61f571b25c13f89545f0ab2fe1950751d8d50bcdc2d40c136e0df533d5a4";
128 x86_64-apple-darwin = "bf8121850b2f6a46566f6c2bbe9fa889b915b1039febf36853ea9d9c4256c67d";
129 aarch64-apple-darwin = "01271f83549c3b5191334a566289aa41615ea8f8f530f49548733585f21c7e5a";
130 powerpc64le-unknown-linux-gnu = "9b104428e2b0377dbdb9dc094eb4d9f4893ada0b80d2b315f0c4ea2135ed9007";
131 riscv64gc-unknown-linux-gnu = "b74cd0bf5ddeb759cd75fb4d7f3f90972dbab6e77569484491ab7ecf073558a8";
132 s390x-unknown-linux-gnu = "721121bcb8f96b98942289f627f9054ded92215c391d48f459527d4b0c63114f";
133 loongarch64-unknown-linux-gnu = "0e7827b14c77ce3ede5ba414de9806b52c655940f95fddd3e07873b8fe46c8bf";
134 loongarch64-unknown-linux-musl = "d769fb639a9116c77d5b35cb0abe4fd3bc85b6d578fe7e4440c218530e32e1cf";
135 x86_64-unknown-freebsd = "fc424d582cd45df010f3b3ff76768f6c87942002421f8896daf7e3989a8f72b4";
136 };
137
138 selectRustPackage = pkgs: pkgs.rust_1_86;
139 }
140
141 (
142 builtins.removeAttrs args [
143 "llvmPackages_19"
144 "llvm_19"
145 "wrapCCWith"
146 "overrideCC"
147 "pkgsHostTarget"
148 "fetchpatch"
149 ]
150 )