Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
pkgs/rustc0: build the rustc fork from source
Browse files Browse the repository at this point in the history
  • Loading branch information
marijanp committed Feb 20, 2024
1 parent 7acff27 commit 8bf2d66
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 89 deletions.
27 changes: 22 additions & 5 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
nixpkgs-risc0-rustc.url = "github:NixOS/nixpkgs/7f792be99dc7a8732d4d0aa23c1dacb6ccd17906";
};

outputs = { self, nixpkgs, ... }:
outputs = inputs@{ self, nixpkgs, ... }:
let
eachSystem = systems: f:
let
Expand Down Expand Up @@ -48,7 +49,8 @@
// eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
risc0pkgs = pkgs.recurseIntoAttrs (pkgs.callPackage ./pkgs { });
pkgs-risc0-rustc = inputs.nixpkgs-risc0-rustc.legacyPackages.${system};
risc0pkgs = pkgs-risc0-rustc.recurseIntoAttrs (pkgs-risc0-rustc.callPackage ./pkgs { });
lib = pkgs.recurseIntoAttrs (pkgs.callPackage ./lib { pkgs = pkgs // risc0pkgs; });
in
{
Expand Down
107 changes: 25 additions & 82 deletions pkgs/rustc0/default.nix
Original file line number Diff line number Diff line change
@@ -1,86 +1,29 @@
{ stdenv
, autoPatchelfHook
, fixDarwinDylibNames
, lib
, zlib
, gcc
{ rustc
, fetchpatch
}:

stdenv.mkDerivation rec {
pname = "rustc0";
version = "v2023-08-10.1";
meta = with lib; {
homepage = "https://github.com/risc0/rust";
description = "risc0's Rust compiler";
platforms = [
# Platforms with host tools from
# https://doc.rust-lang.org/nightly/rustc/platform-support.html
"x86_64-darwin"
"i686-darwin"
"aarch64-darwin"
"i686-freebsd13"
"x86_64-freebsd13"
"x86_64-solaris"
"aarch64-linux"
"armv6l-linux"
"armv7l-linux"
"i686-linux"
"loongarch64-linux"
"powerpc64-linux"
"powerpc64le-linux"
"riscv64-linux"
"s390x-linux"
"x86_64-linux"
"aarch64-netbsd"
"armv7l-netbsd"
"i686-netbsd"
"powerpc-netbsd"
"x86_64-netbsd"
"i686-openbsd"
"x86_64-openbsd"
"i686-windows"
"x86_64-windows"
];
};
# How to update the risc0's rustc derivation:
# 1. Find the latest nixpkgs revision that includes the rust version that risc0's rust is based on:
# 1.1 Go to https://github.com/NixOS/nixpkgs/commits/master/pkgs/development/compilers/rust and grep for the version
# 1.2 Copy the revision and update the nixpkgs-risc0-rustc input in the flake.nix, by replacing the revision hash

src =
if stdenv.hostPlatform.isLinux
then
builtins.fetchurl
{
url = "https://github.com/risc0/rust/releases/download/test-release-2/rust-toolchain-x86_64-unknown-linux-gnu.tar.gz";
sha256 = "sha256-ilCDZk+YY8lUFqdITR1w1OxBsjNVfUlYUTQDzk2/D9s=";
}
else if stdenv.hostPlatform.system == "x86_64-darwin"
then
builtins.fetchurl
{
url = "https://github.com/risc0/rust/releases/download/test-release-2/rust-toolchain-x86_64-apple-darwin.tar.gz";
sha256 = "sha256:1nhnsbclpmpsakf5vz77jbhh4ak7k30frh6hp4lg6aasmvif0fp3";
}
else
builtins.fetchurl {
url = "https://github.com/risc0/rust/releases/download/test-release-2/rust-toolchain-aarch64-apple-darwin.tar.gz";
sha256 = "sha256:0vvf6j14vm9n3kb39m0xdzfc7fdycwr3iqzlnyy7razgi3i5vk9l";
};
# 2. Update the version attribute below.

sourceRoot = ".";

nativeBuildInputs = [
]
++ lib.optional stdenv.hostPlatform.isLinux autoPatchelfHook
++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames;

buildInputs = [ zlib gcc.cc.lib ];

dontStrip = stdenv.hostPlatform.isDarwin;

installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp -r lib $out/lib
install -m755 bin/rustc $out/bin/rustc
install -m755 bin/rustdoc $out/bin/rustdoc
runHook postInstall
'';
}
# Alternative:
# 2. Obtain the diff file that includes all the changes that risc0's fork introduces:
# 2.1 Go to https://github.com/rust-lang/rust/compare/master...risc0:rust:risc0
# 2.2 Change the base repository's branch/tag to the version that risc0's release is based on
# 2.3 Change the head repository's branch/tag to the risc0 release version
# 2.4 Download the diff by appending `.diff` to the URL e.g. https://github.com/rust-lang/rust/compare/1.70.0...risc0:rust:v2024-01-31.1.diff
# 2.5 Add the diff file next to this file (default.nix)
# 2.6 Modify the diff and remove the .github/workflows/ci.yml changes
rustc.overrideAttrs (final: prev: {
version = "v2024-01-31.1";
patches = (prev.patches or [ ]) ++ [
(fetchpatch {
url = "https://github.com/rust-lang/rust/compare/${prev.version}...risc0:rust:${final.version}.diff";
hash = "sha256-kUCb4SXq7T0vNctMfLywjvEtlEdRRQhsy3RVP+/0Wmo=";
excludes = [ ".github/workflows/ci.yml" ];
})
];
})

0 comments on commit 8bf2d66

Please sign in to comment.