From 655bfdc6fc922d117849cbcf808ee5bf2dfa1d53 Mon Sep 17 00:00:00 2001
From: Dan Forbes <dan@parity.io>
Date: Tue, 17 Nov 2020 10:12:58 -0800
Subject: [PATCH] Update Local Development docs to use Makefile (#105)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* Update Local Development docs to use Makefile

* Update Makefile per @athei

Co-authored-by: Alexander Theißen <alex.theissen@me.com>

Co-authored-by: Alexander Theißen <alex.theissen@me.com>
---
 Makefile        | 19 ++++++++++++++++
 README.md       | 60 ++++++++++++++++++++++++++++++++++++-------------
 scripts/init.sh |  4 +++-
 shell.nix       | 25 ---------------------
 4 files changed, 66 insertions(+), 42 deletions(-)
 create mode 100644 Makefile
 delete mode 100644 shell.nix

diff --git a/Makefile b/Makefile
new file mode 100644
index 000000000..fd553585d
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,19 @@
+.PHONY: init
+init:
+	./scripts/init.sh
+
+.PHONY: check
+check:
+	SKIP_WASM_BUILD=1 cargo check
+
+.PHONY: test
+test:
+	SKIP_WASM_BUILD=1 cargo test --all
+
+.PHONY: run
+run:
+	WASM_BUILD_TOOLCHAIN=nightly-2020-10-05 cargo run --release -- --dev --tmp
+
+.PHONY: build
+build:
+	WASM_BUILD_TOOLCHAIN=nightly-2020-10-05 cargo build --release
diff --git a/README.md b/README.md
index 058608802..158277a09 100644
--- a/README.md
+++ b/README.md
@@ -2,42 +2,70 @@
 
 A new FRAME-based Substrate node, ready for hacking :rocket:
 
-## Local Development
+## Getting Started
 
-Follow these steps to prepare a local Substrate development environment :hammer_and_wrench:
+This project contains some configuration files to help get started :hammer_and_wrench:
 
-### Setup
+### Rust Setup
 
-Setup instructions can be found at the
-[Substrate Developer Hub](https://substrate.dev/docs/en/knowledgebase/getting-started).
+Setup instructions for working with the [Rust](https://www.rust-lang.org/) programming language can
+be found at the
+[Substrate Developer Hub](https://substrate.dev/docs/en/knowledgebase/getting-started). Follow those
+steps to install [`rustup`](https://rustup.rs/) and configure the Rust toolchain to default to the
+latest stable version.
+
+### Makefile
+
+This project uses a [Makefile](Makefile) to document helpful commands and make it easier to execute
+them. Get started by running these [`make`](https://www.gnu.org/software/make/manual/make.html)
+targets:
+
+1. `make init` - Run the [init script](scripts/init.sh) to configure the Rust toolchain for
+   [WebAssembly compilation](https://substrate.dev/docs/en/knowledgebase/getting-started/#webassembly-compilation).
+1. `make run` - Build and launch this project in development mode.
+
+The init script and Makefile both specify the version of the
+[Rust nightly compiler](https://substrate.dev/docs/en/knowledgebase/getting-started/#rust-nightly-toolchain)
+that this project depends on.
 
 ### Build
 
-Once the development environment is set up, build the node template. This command will build the
-[Wasm](https://substrate.dev/docs/en/knowledgebase/advanced/executor#wasm-execution) and
-[native](https://substrate.dev/docs/en/knowledgebase/advanced/executor#native-execution) code:
+The `make run` command will perform an initial build. Use the following command to build the node
+without launching it:
 
-```bash
-WASM_BUILD_TOOLCHAIN=nightly-2020-10-05 cargo build --release
+```sh
+make build
+```
+
+### Embedded Docs
+
+Once the project has been built, the following command can be used to explore all parameters and
+subcommands:
+
+```sh
+./target/release/node-template -h
 ```
 
 ## Run
 
-### Single Node Development Chain
+The `make run` command will launch a temporary node and its state will be discarded after you
+terminate the process. After the project has been built, there are other ways to launch the node.
 
-Purge any existing dev chain state:
+### Single-Node Development Chain
+
+This command will start the single-node development chain with persistent state:
 
 ```bash
-./target/release/node-template purge-chain --dev
+./target/release/node-template --dev
 ```
 
-Start a dev chain:
+Purge the development chain's state:
 
 ```bash
-./target/release/node-template --dev
+./target/release/node-template purge-chain --dev
 ```
 
-Or, start a dev chain with detailed logging:
+Start the development chain with detailed logging:
 
 ```bash
 RUST_LOG=debug RUST_BACKTRACE=1 ./target/release/node-template -lruntime=debug --dev
diff --git a/scripts/init.sh b/scripts/init.sh
index 5faaee8fe..5020ec253 100755
--- a/scripts/init.sh
+++ b/scripts/init.sh
@@ -5,8 +5,10 @@ set -e
 echo "*** Initializing WASM build environment"
 
 if [ -z $CI_PROJECT_NAME ] ; then
-   rustup install nightly-2020-10-05
+   rustup update nightly
+   rustup update nightly-2020-10-05
    rustup update stable
 fi
 
+rustup target add wasm32-unknown-unknown --toolchain nightly
 rustup target add wasm32-unknown-unknown --toolchain nightly-2020-10-05
diff --git a/shell.nix b/shell.nix
deleted file mode 100644
index dcd723ff1..000000000
--- a/shell.nix
+++ /dev/null
@@ -1,25 +0,0 @@
-let
-  mozillaOverlay =
-    import (builtins.fetchGit {
-      url = "https://github.com/mozilla/nixpkgs-mozilla.git";
-      rev = "57c8084c7ef41366993909c20491e359bbb90f54";
-    });
-  nixpkgs = import <nixpkgs> { overlays = [ mozillaOverlay ]; };
-  rust-nightly = with nixpkgs; ((rustChannelOf { date = "2020-10-05"; channel = "nightly"; }).rust.override {
-    targets = [ "wasm32-unknown-unknown" ];
-  });
-in
-with nixpkgs; pkgs.mkShell {
-  buildInputs = [
-    clang
-    cmake
-    pkg-config
-    rust-nightly
-  ] ++ stdenv.lib.optionals stdenv.isDarwin [
-    darwin.apple_sdk.frameworks.Security
-  ];
-
-  LIBCLANG_PATH = "${llvmPackages.libclang}/lib";
-  PROTOC = "${protobuf}/bin/protoc";
-  ROCKSDB_LIB_DIR = "${rocksdb}/lib";
-}
-- 
GitLab