diff --git a/.circleci/config.yml b/.circleci/config.yml index d1cb4b75b2..183dda2367 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -46,7 +46,7 @@ commands: steps: - save_cache: name: "Save rustup cache" - key: cargo-v2-{{ checksum "rust-toolchain" }}-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}-{{ arch }} + key: cargo-v2-{{ checksum "rust-toolchain.toml" }}-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}-{{ arch }} paths: - "~/.cargo" - "~/.rustup" @@ -55,7 +55,7 @@ commands: steps: - restore_cache: keys: - - cargo-v2-{{ checksum "rust-toolchain" }}-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}-{{ arch }} + - cargo-v2-{{ checksum "rust-toolchain.toml" }}-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}-{{ arch }} install_gpu_deps: steps: @@ -69,10 +69,10 @@ jobs: - checkout - run: name: Update submodules - command: git submodule update --init --recursive - - run: curl https://sh.rustup.rs -sSf | sh -s -- -y - - run: rustup install $(cat rust-toolchain) - - run: rustup default $(cat rust-toolchain) + command: | + git submodule update --init --recursive + curl https://sh.rustup.rs -sSf | sh -s -- -y + - run: rustup show - run: cargo --version - run: rustc --version - run: @@ -133,8 +133,7 @@ jobs: name: Install Rust command: | curl https://sh.rustup.rs -sSf | sh -s -- -y - - run: rustup install $(cat rust-toolchain) - - run: rustup default $(cat rust-toolchain) + - run: rustup show - run: cargo --version - run: cargo update - run: cargo fetch @@ -157,8 +156,7 @@ jobs: name: Install Rust command: | curl https://sh.rustup.rs -sSf | sh -s -- -y - - run: rustup install $(cat rust-toolchain) - - run: rustup default $(cat rust-toolchain) + - run: rustup show - run: cargo --version - run: cargo update - run: cargo fetch diff --git a/.envrc b/.envrc new file mode 100644 index 0000000000..3550a30f2d --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000000..5956c17438 --- /dev/null +++ b/flake.lock @@ -0,0 +1,102 @@ +{ + "nodes": { + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1675146246, + "narHash": "sha256-upQtcca/sThA5Jkmn5pDaYFoCmPLMyv7bGFCZFcVhqM=", + "owner": "nix-community", + "repo": "fenix", + "rev": "97deb5c86b238c2a000ef4eb92fb40465f086706", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "naersk": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1671096816, + "narHash": "sha256-ezQCsNgmpUHdZANDCILm3RvtO1xH8uujk/+EqNvzIOg=", + "owner": "nix-community", + "repo": "naersk", + "rev": "d998160d6a076cfe8f9741e56aeec7e267e3e114", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1675115703, + "narHash": "sha256-4zetAPSyY0D77x+Ww9QBe8RHn1akvIvHJ/kgg8kGDbk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "2caf4ef5005ecc68141ecb4aac271079f7371c44", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, + "root": { + "inputs": { + "fenix": "fenix", + "flake-utils": "flake-utils", + "naersk": "naersk", + "nixpkgs": "nixpkgs" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1675097868, + "narHash": "sha256-BKFLjEzdoFWso7Artln7djf8RbtBynj9wZKIj22LV5g=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "b75803ad31772d105d86f8ebee0cbc8844a4fa29", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000000..a739ed47a7 --- /dev/null +++ b/flake.nix @@ -0,0 +1,45 @@ +{ + inputs = { + nixpkgs.url = "nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + naersk = { + url = "github:nix-community/naersk"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, nixpkgs, flake-utils, naersk, fenix }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = (import nixpkgs) { + inherit system; + }; + + toolchain = with fenix.packages.${system}; fromToolchainFile { + file = ./rust-toolchain.toml; # alternatively, dir = ./.; + sha256 = "sha256-riZUc+R9V35c/9e8KJUE+8pzpXyl0lRXt3ZkKlxoY0g="; + }; + + in rec { + defaultPackage = (naersk.lib.${system}.override { + # For `nix build` & `nix run`: + cargo = toolchain; + rustc = toolchain; + }).buildPackage { + src = ./.; + }; + + # For `nix develop` or `direnv allow`: + devShell = pkgs.mkShell { + buildInputs = with pkgs; [ + ocl-icd + toolchain + ]; + }; + } + ); +} diff --git a/rust-toolchain b/rust-toolchain deleted file mode 100644 index 77c582d8d9..0000000000 --- a/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -1.67.0 \ No newline at end of file diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000000..cf84741dd3 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,7 @@ +[toolchain] +channel = "1.67.0" +targets = [ "aarch64-unknown-linux-gnu", "x86_64-unknown-linux-gnu", "x86_64-apple-darwin", "wasm32-unknown-unknown" ] +components = [ "rustc", "cargo", "clippy", "rustfmt", "rust-src", +"rust-analysis", "rust-analyzer" ] +profile = "default" +