diff --git a/flake.lock b/flake.lock index 465d56c0838..e779473f0ec 100644 --- a/flake.lock +++ b/flake.lock @@ -11,9 +11,7 @@ "nixpkgs": [ "nixpkgs" ], - "rust-overlay": [ - "rust-overlay" - ] + "rust-overlay": "rust-overlay" }, "locked": { "lastModified": 1681177078, @@ -29,6 +27,27 @@ "type": "github" } }, + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1694499657, + "narHash": "sha256-u/fZtLtN7VcDrMMVrdsFy93PEkaiK+tNpJT9on4SGdU=", + "owner": "nix-community", + "repo": "fenix", + "rev": "2895ff377cbb3cb6f5dd92066734b0447cb04e20", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, "flake-compat": { "flake": false, "locked": { @@ -82,27 +101,46 @@ "root": { "inputs": { "crane": "crane", + "fenix": "fenix", "flake-compat": "flake-compat", "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs", - "rust-overlay": "rust-overlay" + "nixpkgs": "nixpkgs" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1694421477, + "narHash": "sha256-df6YZzR57VFzkOPwIohJfC0fRwgq6yUPbMJkKAtQyAE=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "cc6c8209cbaf7df55013977cf5cc8488d6b7ff1c", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" } }, "rust-overlay": { "inputs": { "flake-utils": [ + "crane", "flake-utils" ], "nixpkgs": [ + "crane", "nixpkgs" ] }, "locked": { - "lastModified": 1681352318, - "narHash": "sha256-+kwy7bTsuW8GYrRqWRQ8T5hg6duZb5IJiHlKo1J+v9g=", + "lastModified": 1694484610, + "narHash": "sha256-aeSDkp7fkAqtVjW3QUn7vq7BKNlFul/BiGgdv7rK+mA=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "aeaa11c65a5c5cebaa51652353ab3c497b9a7bbf", + "rev": "c5b977a7e6a295697fa1f9c42174fd6313b38df4", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 71b6911352d..35db82187f4 100644 --- a/flake.nix +++ b/flake.nix @@ -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"; @@ -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; @@ -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); @@ -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; [ @@ -197,7 +182,7 @@ }; }; in - rec { + { checks = { cargo-clippy = craneLib.cargoClippy (nativeConfig // { pname = "noir"; @@ -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 = '' diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 00000000000..fd86146385a --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,5 @@ +[toolchain] +channel = "1.66.1" +components = [ "rust-src" ] +targets = [ "wasm32-unknown-unknown" ] +profile = "default" diff --git a/wasm-bindgen-cli.nix b/wasm-bindgen-cli.nix index 38b7b0a79c1..7c3910f032e 100644 --- a/wasm-bindgen-cli.nix +++ b/wasm-bindgen-cli.nix @@ -7,6 +7,7 @@ , stdenv , curl , darwin +, libiconv , runCommand }: @@ -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; @@ -34,4 +40,4 @@ rustPlatform.buildRustPackage rec { maintainers = with maintainers; [ nitsky rizary ]; mainProgram = "wasm-bindgen"; }; -} \ No newline at end of file +}