diff --git a/dummy-contract/default.nix b/dummy-contract/default.nix new file mode 100644 index 0000000..2217c90 --- /dev/null +++ b/dummy-contract/default.nix @@ -0,0 +1,51 @@ +{ inputs, ... }: +{ + perSystem = { self', inputs', pkgs, lib, ... }: + let + # nightly-2023-03-25: https://github.com/casper-network/casper-node/blob/release-2.0.0-rc4/smart_contracts/rust-toolchain + toolchainAttrs = { channel = "nightly"; date = "2023-03-25"; sha256 = "sha256-vWMW7tpbU/KseRztVYQ6CukrQWJgPgtlFuB6OPoZ/v8="; }; + rustToolchain = with inputs'.fenix.packages; combine [ + (toolchainOf toolchainAttrs).toolchain + (targets.wasm32-unknown-unknown.toolchainOf toolchainAttrs).rust-std + ]; + craneLib = (inputs.crane.mkLib pkgs).overrideToolchain rustToolchain; + + contractAttrs = { + pname = "dummy-contract"; + src = lib.cleanSourceWith { + src = lib.fileset.toSource { + root = ./.; + fileset = lib.fileset.unions [ + ./Cargo.toml + ./Cargo.lock + ./src + ]; + }; + }; + cargoExtraArgs = "--target wasm32-unknown-unknown"; + CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_LINKER = "lld"; + nativeBuildInputs = [ pkgs.binaryen pkgs.llvmPackages_16.bintools ]; + doCheck = false; + # optimize wasm + postInstall = '' + directory="$out/bin/" + for file in "$directory"*.wasm; do + if [ -e "$file" ]; then + wasm-opt -Oz --strip-debug --signext-lowering "$file" + fi + done + ''; + }; + in + { + devShells.contract = pkgs.mkShell { + inputsFrom = [ self'.packages.dummy-contract ]; + CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_LINKER = "lld"; + }; + packages = { + # Used for testing purposes + dummy-contract = craneLib.buildPackage contractAttrs; + }; + }; + flake = { }; +} diff --git a/flake.nix b/flake.nix index cb1fe09..1ba4ef2 100644 --- a/flake.nix +++ b/flake.nix @@ -38,13 +38,11 @@ imports = [ treefmt-nix.flakeModule ./nixos + ./dummy-contract ]; perSystem = { self', inputs', pkgs, lib, ... }: let - rustToolchain = with inputs'.fenix.packages; combine [ - stable.toolchain - targets.wasm32-unknown-unknown.stable.rust-std - ]; + rustToolchain = inputs'.fenix.packages.stable.toolchain; craneLib = (inputs.crane.mkLib pkgs).overrideToolchain rustToolchain; cctl = inputs'.cctl.packages.cctl; @@ -80,31 +78,6 @@ cctl ]; }; - - contractAttrs = { - pname = "dummy-contract"; - src = lib.cleanSourceWith { - src = lib.fileset.toSource { - root = ./dummy-contract; - fileset = lib.fileset.unions [ - ./dummy-contract - ]; - }; - }; - cargoExtraArgs = "--target wasm32-unknown-unknown"; - CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_LINKER = "lld"; - nativeBuildInputs = [ pkgs.binaryen pkgs.lld ]; - doCheck = false; - # optimize wasm - postInstall = '' - directory="$out/bin/" - for file in "$directory"*.wasm; do - if [ -e "$file" ]; then - wasm-opt -Oz --strip-debug --signext-lowering "$file" - fi - done - ''; - }; in { devShells.default = pkgs.mkShell { @@ -113,9 +86,6 @@ }; packages = { - # Used for testing purposes - dummy-contract = craneLib.buildPackage contractAttrs; - cctl-rs-deps = craneLib.buildDepsOnly cctlAttrs; cctl-rs-docs = craneLib.cargoDoc (cctlAttrs // { diff --git a/test-resources/dummy-contract.wasm b/test-resources/dummy-contract.wasm index e0f7462..256131f 100644 Binary files a/test-resources/dummy-contract.wasm and b/test-resources/dummy-contract.wasm differ