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

Commit

Permalink
Merge pull request #13 from cspr-rad/update-template
Browse files Browse the repository at this point in the history
update to use upstream rustc
  • Loading branch information
marijanp authored Apr 18, 2024
2 parents 60ec2cb + e2bb310 commit e03fcf2
Show file tree
Hide file tree
Showing 19 changed files with 1,418 additions and 21,361 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ jobs:
if: matrix.os == 'ubuntu-latest'
run: nix build -L --no-link --show-trace .#checks.x86_64-linux.format

- name: rustc0
if: matrix.os == 'ubuntu-latest'
run: nix build -L --no-link --show-trace .#packages.x86_64-linux.rustc0

- name: r0vm
if: matrix.os == 'ubuntu-latest'
run: nix build -L --no-link --show-trace .#packages.x86_64-linux.r0vm
Expand All @@ -43,10 +39,6 @@ jobs:
git config --global init.defaultBranch main
./scripts/use-template.sh
- name: rustc0
if: matrix.os == 'macos-latest'
run: nix build -L --no-link --show-trace .#packages.x86_64-darwin.rustc0

- name: r0vm
if: matrix.os == 'macos-latest'
run: nix build -L --no-link --show-trace .#packages.x86_64-darwin.r0vm
Expand All @@ -57,10 +49,6 @@ jobs:
git config --global init.defaultBranch main
./scripts/use-template.sh
- name: rustc0
if: matrix.os == 'macos-14'
run: nix build -L --no-link --show-trace .#packages.aarch64-darwin.rustc0

- name: r0vm
if: matrix.os == 'macos-14'
run: nix build -L --no-link --show-trace .#packages.aarch64-darwin.r0vm
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
result
target
68 changes: 53 additions & 15 deletions flake.lock

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

22 changes: 9 additions & 13 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
};

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
# Latest nixpkgs revision including the cached rustc version that risc0's rustc is based on.
# For further details refer to the comments in pkgs/rustc0/default.nix
nixpkgs-risc0-rustc.url = "github:NixOS/nixpkgs/34d8dbb93ddf91fb665b186d1c832b2d2f8e7ff7";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = inputs@{ self, nixpkgs, ... }:
outputs = inputs@{ self, nixpkgs, rust-overlay, ... }:
let
eachSystem = systems: f:
let
Expand All @@ -44,25 +45,22 @@
];
in
{
herculesCI.ciSystems = [ "x86_64-linux" ];
templates.default = {
path = ./templates/default;
description = "risc0 project template";
};
}
// eachDefaultSystem (system:
let
pkgs-risc0-rustc = inputs.nixpkgs-risc0-rustc.legacyPackages.${system};
rustc0 = pkgs-risc0-rustc.callPackage ./pkgs/rustc0 { };

pkgs = nixpkgs.legacyPackages.${system};
pkgs = nixpkgs.legacyPackages.${system}.extend (import rust-overlay);
risc0pkgs = pkgs.recurseIntoAttrs (pkgs.callPackage ./pkgs { });
lib = pkgs.recurseIntoAttrs (pkgs.callPackage ./lib { pkgs = pkgs // risc0pkgs // { inherit rustc0; }; });
lib = pkgs.recurseIntoAttrs (pkgs.callPackage ./lib { pkgs = pkgs; });
in
{
inherit lib;
packages = {
inherit (risc0pkgs) r0vm;
inherit rustc0;
};

formatter = pkgs.nixpkgs-fmt;
Expand All @@ -73,7 +71,5 @@
nixpkgs-fmt --check .
touch $out
'';

herculesCI.ciSystems = [ "x86_64-linux" ];
});
}
55 changes: 20 additions & 35 deletions lib/buildRisc0Package.nix
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{ rustPlatform
{ makeRustPlatform
, pkg-config
, cargo-risczero
, rustc0
, lld
, rust-bin
, writeShellApplication
, cargo
, openssl
, lib
, stdenv
, darwin
}:
attrs:
extraBuildRustPackageAttrs@{ nativeBuildInputs ? [ ], preBuild ? "", buildInputs ? [ ], ... }:

let
toolchain = rust-bin.selectLatestNightlyWith (toolchain: toolchain.default.override {
extensions = [ "rust-src" ];
});
rustup-mock = writeShellApplication {
name = "rustup";
runtimeInputs = [ ];
text = ''
# the buildscript uses rustup toolchain to check
# whether the risc0 toolchain was installed
Expand All @@ -24,44 +24,29 @@ let
printf "risc0\n"
elif [[ "$1" = "+risc0" ]]
then
printf "${rustc0}/bin/rustc"
printf "${toolchain}/bin/rustc"
fi
'';
};
cargo-mock = writeShellApplication {
name = "cargo";
runtimeInputs = [ cargo ];
text = ''
# ignore +risc0
if [[ "$1" = "+risc0" ]]
then
cargo "''${@:2}"
else
cargo "$@"
fi
'';
};
lld-mock = writeShellApplication {
name = "rust-lld";
runtimeInputs = [ lld ];
text = ''
ld.lld "$@"
'';
};
extraBuildRustPackageAttrsNoArgs = builtins.removeAttrs extraBuildRustPackageAttrs [ "buildInputs" "nativeBuildInputs" "preBuild" ];
in

rustPlatform.buildRustPackage (lib.mergeAttrsConcatenateValues attrs {
nativeBuildInputs = [
(makeRustPlatform { rustc = toolchain; cargo = toolchain; }).buildRustPackage (lib.recursiveUpdate extraBuildRustPackageAttrsNoArgs {
nativeBuildInputs = lib.unique ([
pkg-config
cargo-risczero
rustc0
rustup-mock
cargo-mock
lld-mock
];
buildInputs = [
] ++ nativeBuildInputs);
preBuild = ''
export RISC0_RUST_SRC=${toolchain}/lib/rustlib/src/rust;
${preBuild}
'';
buildInputs = lib.unique ([
openssl.dev
] ++ lib.optionals stdenv.isDarwin [
darwin.apple_sdk.frameworks.SystemConfiguration
];
] ++ buildInputs);
doCheck = false;
auditable = false;
passthru = { inherit toolchain; };
})
Loading

0 comments on commit e03fcf2

Please sign in to comment.