Skip to content

Commit

Permalink
chore(nix): Switch to Fenix and provide a rust-toolchain file
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Sep 12, 2023
1 parent 7832943 commit a71d19b
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 57 deletions.
54 changes: 46 additions & 8 deletions flake.lock

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

76 changes: 29 additions & 47 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
description = "Build the Noir programming language";

# All of these inputs (a.k.a. dependencies) need to align with inputs we
# use so they use the `inputs.*.follows` syntax to reference our inputs
inputs = {
nixpkgs = {
url = "github:NixOS/nixpkgs/nixos-22.11";
Expand All @@ -15,51 +17,34 @@
flake = false;
};

rust-overlay = {
url = "github:oxalica/rust-overlay";
# All of these inputs (a.k.a. dependencies) need to align with inputs we
# use so they use the `inputs.*.follows` syntax to reference our inputs
fenix = {
url = "github:nix-community/fenix";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};

crane = {
url = "github:ipetkov/crane";
# All of these inputs (a.k.a. dependencies) need to align with inputs we
# use so they use the `inputs.*.follows` syntax to reference our inputs
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
flake-compat.follows = "flake-compat";
rust-overlay.follows = "rust-overlay";
};
};
};

outputs =
{ self, nixpkgs, crane, flake-utils, rust-overlay, ... }:
{ self, nixpkgs, crane, flake-utils, fenix, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
rust-overlay.overlays.default
];
};

rustVersion = "1.66.1";

rustToolchain = pkgs.rust-bin.stable.${rustVersion}.default.override {
# We include rust-src to ensure rust-analyzer works.
# See https://discourse.nixos.org/t/rust-src-not-found-and-other-misadventures-of-developing-rust-on-nixos/11570/4
extensions = [ "rust-src" ];
targets = [ "wasm32-unknown-unknown" ]
++ pkgs.lib.optional (pkgs.hostPlatform.isx86_64 && pkgs.hostPlatform.isLinux) "x86_64-unknown-linux-gnu"
++ pkgs.lib.optional (pkgs.hostPlatform.isAarch64 && pkgs.hostPlatform.isLinux) "aarch64-unknown-linux-gnu"
++ pkgs.lib.optional (pkgs.hostPlatform.isx86_64 && pkgs.hostPlatform.isDarwin) "x86_64-apple-darwin"
++ pkgs.lib.optional (pkgs.hostPlatform.isAarch64 && pkgs.hostPlatform.isDarwin) "aarch64-apple-darwin";
rustToolchain = fenix.packages.${system}.fromToolchainFile {
file = ./rust-toolchain.toml;
sha256 = "sha256-Zk2rxv6vwKFkTTidgjPm6gDsseVmmljVt201H7zuDkk=";
};

craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
Expand All @@ -68,7 +53,7 @@
GIT_COMMIT = if (self ? rev) then self.rev else "unknown";
GIT_DIRTY = if (self ? rev) then "false" else "true";

# Custom filter with various file extensions that we rely upon to build the compiler or wasm packages
# Custom filter with various file extensions that we rely upon to build packages
# Currently: `.nr`, `.sol`, `.sh`, `.json`, `.md`
sourceFilter = path: type:
(builtins.match ".*\.(nr|sol|sh|json|md)$" path != null) || (craneLib.filterCargoSources path type);
Expand Down Expand Up @@ -102,15 +87,15 @@
cargoTestExtraArgs = "--workspace";
};

# Combine the environment and other configuration needed for crane to build our Rust packages
# Combine the environment and other configuration needed for Crane to build our Rust packages
nativeConfig = environment // config // {
nativeBuildInputs = [ ];

buildInputs = [ ] ++ extraBuildInputs;
};

# Combine the environmnet with cargo args needed to build wasm package
wasmConfig = environment // config // rec {
# Combine the environmnet and other configuration needed for Crane to build our Wasm packages
wasmConfig = environment // config // {
CARGO_TARGET_DIR = "./target";

nativeBuildInputs = with pkgs; [
Expand Down Expand Up @@ -197,7 +182,7 @@
};
};
in
rec {
{
checks = {
cargo-clippy = craneLib.cargoClippy (nativeConfig // {
pname = "noir";
Expand Down Expand Up @@ -233,31 +218,28 @@
# Setup the environment to match the environment settings, the inputs from our checks derivations,
# and extra tooling via `nativeBuildInputs`
devShells.default = pkgs.mkShell (environment // {
inputsFrom = builtins.attrValues checks;
inputsFrom = [
nargo
noir_wasm
noirc_abi_wasm
];

# These are additional tools that werent;'
nativeBuildInputs = with pkgs; [
# Need to install various packages used by the `bb` binary.
# pkgs.curl
# stdenv.cc.cc.lib
# pkgs.gcc.cc.lib
# pkgs.gzip
# Rust toolchain
rustToolchain
# Other tools
starship
yarn
nodejs-18_x
# Used by the `bb` binary
curl
gzip
which
starship
git
# This ensures the right lldb is in the environment for running rust-lldb
llvmPackages.lldb
# Nix tools
nil
nixpkgs-fmt
toml2json
llvmPackages.lldb # This ensures the right lldb is in the environment for running rust-lldb
wasm-bindgen-cli
jq
binaryen
yarn
rust-bin.stable.${rustVersion}.default
rust-analyzer
rustup
nodejs-18_x
];

shellHook = ''
Expand Down
5 changes: 5 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[toolchain]
channel = "1.66.1"
components = [ "rust-src" ]
targets = [ "wasm32-unknown-unknown" ]
profile = "default"
10 changes: 8 additions & 2 deletions wasm-bindgen-cli.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
, stdenv
, curl
, darwin
, libiconv
, runCommand
}:

Expand All @@ -23,7 +24,12 @@ rustPlatform.buildRustPackage rec {

nativeBuildInputs = [ pkg-config ];

buildInputs = [ openssl ] ++ lib.optionals stdenv.isDarwin [ curl darwin.apple_sdk.frameworks.Security ];
buildInputs = [ openssl ] ++ lib.optionals stdenv.isDarwin [
curl
# Need libiconv and apple Security on Darwin. See https://github.com/ipetkov/crane/issues/156
libiconv
darwin.apple_sdk.frameworks.Security
];

doCheck = false;

Expand All @@ -34,4 +40,4 @@ rustPlatform.buildRustPackage rec {
maintainers = with maintainers; [ nitsky rizary ];
mainProgram = "wasm-bindgen";
};
}
}

0 comments on commit a71d19b

Please sign in to comment.