Skip to content

Commit

Permalink
Add dev shell environment (#1534)
Browse files Browse the repository at this point in the history
* Add flake

* small fix

* Update contributing guide and clean flake

* Update CONTRIBUTING.md

Co-authored-by: Leigh McCulloch <[email protected]>

---------

Co-authored-by: Leigh McCulloch <[email protected]>
  • Loading branch information
Ifropc and leighmcculloch authored Aug 13, 2024
1 parent 3515ce7 commit dafc95a
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ snapshot.json
test_snapshots
.vscode/settings.json
.idea
local.sh
25 changes: 25 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,31 @@ changes quickly.
* Clearly describe the issue including steps to reproduce if it is a bug.
* Fork the repository on GitHub.

## Setting up development environment

There are 2 ways to being developing stellar-cli:

### Installing all required dependencies

You may want to install all required dependencies locally. This includes installing `rustup`, `make`, `libudev`, `jq` from your package manager. After all dependencies are installed, you can start with running `make install` to build `stellar-cli` and install it!

### Using `nix`

If you don't want to install necessary dependencies from above, you can run development shell using [nix](https://nixos.org/guides/how-nix-works/) (make sure to [install](https://nixos.org/download/) version above 2.20). After installing `nix`, simply run `nix develop` that will start new `bash` session in your current terminal. If you want to use different shell (e.g. `zsh`) you can run `nix develop -c zsh`

This session will have:
1. All required dependencies installed
2. `stellar` alias (overwriting your existing `stellar` installed via cargo, if any)
3. Configured auto-complete for the working git branch

You can add extra configuration in your `local.sh` file (for example, if you want to export some extra variables for your devshell you can put following in your `local.sh`:
```shell
#!/usr/bin/env bash
export STELLAR_NETWORK=testnet
```
Note that all of dependencies and configurations mentioned above is available only in your local development shell, not outside of it.


### Minor Changes

#### Documentation
Expand Down
96 changes: 96 additions & 0 deletions flake.lock

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

43 changes: 43 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
description = "stellar-cli development shell";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
in
with pkgs;
{
devShells.default = mkShell {
buildInputs = [
openssl
pkg-config
libudev-zero
jq
(rust-bin.stable.latest.default.override {
extensions = [ "rust-src" ];
targets = [ "wasm32-unknown-unknown" ];
})
];
shellHook =
''
echo "Using `nix --version`"
alias stellar="cargo run --bin stellar --"
[ -f ./local.sh ] && source ./local.sh
shell=$0
shell=`basename $SHELL`
source <(stellar completion --shell $shell)
'';
};
}
);
}

0 comments on commit dafc95a

Please sign in to comment.