From 6230d6ab1f7c491342fa509864dc8b9bc784e614 Mon Sep 17 00:00:00 2001 From: mitchmindtree Date: Wed, 25 Jun 2025 13:08:28 +1000 Subject: [PATCH] feat: (WIP) Rudimentary, WIP attempt at building risc0's fork of rustc --- flake.nix | 1 + overlay.nix | 3 +++ pkgs/rust.nix | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 pkgs/rust.nix diff --git a/flake.nix b/flake.nix index 4ea6be0..017b3dd 100644 --- a/flake.nix +++ b/flake.nix @@ -23,6 +23,7 @@ }; packages = perSystemPkgs (pkgs: { + risc0-rust = pkgs.risc0-rust; rust-bin-risc0-latest = pkgs.rust-bin.risc0.latest; default = inputs.self.packages.${pkgs.system}.rust-bin-risc0-latest; }); diff --git a/overlay.nix b/overlay.nix index dc5eb5b..6d6948f 100644 --- a/overlay.nix +++ b/overlay.nix @@ -39,4 +39,7 @@ in cargoExtraArgs = (args.cargoExtraArgs or "") + " --target riscv32im-risc0-zkvm-elf"; } ); + + # NOTE: Test package for building risc0's rust fork from source. + risc0-rust = prev.callPackage ./pkgs/rust.nix { }; } diff --git a/pkgs/rust.nix b/pkgs/rust.nix new file mode 100644 index 0000000..8e9634a --- /dev/null +++ b/pkgs/rust.nix @@ -0,0 +1,52 @@ +# risc0-rust.nix +{ + lib, + rustc, + fetchFromGitHub, +}: + +let + version = "1.85.0"; + + risc0Src = fetchFromGitHub { + owner = "risc0"; + repo = "rust"; + rev = "r0.${version}"; + fetchSubmodules = true; + sha256 = "sha256-uxo6Sx9I+x9Gi9/JttRLIzAa+WzTmJ5DTempRwrsp/U="; + }; + +in +rustc.unwrapped.overrideAttrs (oldAttrs: { + pname = "risc0-rustc"; + src = risc0Src // { + # Override the passthru on the source to indicate it's not a release tarball + passthru = (risc0Src.passthru or {}) // { + isReleaseTarball = false; + }; + }; + inherit version; + + # Override configure flags to add RISC Zero target + configureFlags = + let + # Remove existing --target flag and add our own with RISC Zero target included + flagsWithoutTarget = builtins.filter + (flag: !(lib.hasPrefix "--target=" flag)) + oldAttrs.configureFlags; + + # Get the existing target list and add our target + existingTargets = "x86_64-unknown-linux-gnu,wasm32-unknown-unknown,wasm32v1-none,bpfel-unknown-none,bpfeb-unknown-none"; + newTargets = "${existingTargets},riscv32im-risc0-zkvm-elf"; + in + flagsWithoutTarget ++ [ + "--target=${newTargets}" + ]; + + # Add RISC Zero environment variables + preBuild = + (oldAttrs.preBuild or "") + + '' + export CARGO_TARGET_RISCV32IM_RISC0_ZKVM_ELF_RUSTFLAGS="-Cpasses=lower-atomic" + ''; +})