Skip to content

Commit

Permalink
Improve setup instructions.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnando committed Nov 15, 2024
1 parent bc3b96c commit cda9fec
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 11 deletions.
144 changes: 136 additions & 8 deletions docs/build/smart-contracts/getting-started/setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ description: Install and configure Rust and CLI to deploy smart contracts.
/>
</head>

import CodeBlock from "@theme/CodeBlock";
import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";
import { getPlatform } from "@site/src/helpers/getPlatform";
import { getShell } from "@site/src/helpers/getShell";
import { latestVersion } from "@site/src/helpers/stellarCli";
import { getStellarCliLatestReleaseUrl } from "@site/src/helpers/getStellarCliLatestReleaseUrl";
import { StellarCliVersion } from "@site/src/components/StellarCliVersion";

Stellar smart contracts are small programs written in the [Rust] programming language.

Expand All @@ -31,15 +36,19 @@ To build and develop contracts you need only a couple prerequisites:

## Install Rust

### Linux, macOS, or other Unix-like OS
<Tabs groupId="platform" defaultValue={getPlatform()}>

<TabItem value="unix" label="macOS/Linux">

If you use macOS, Linux, or another Unix-like OS, the simplest method to install a Rust toolchain is to install `rustup`. Install `rustup` with the following command.

```sh
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```

### Windows
</TabItem>

<TabItem value="windows" label="Windows">

On Windows, download and run [rustup-init.exe](https://static.rust-lang.org/rustup/dist/i686-pc-windows-gnu/rustup-init.exe). You can continue with the default settings by pressing Enter.

Expand All @@ -51,10 +60,16 @@ The Stellar CLI uses emojis in its output. To properly render them on Windows, i

If you're already using [WSL](https://learn.microsoft.com/en-us/windows/wsl/install), you can also follow the instructions for Linux.

### Other
</TabItem>

<TabItem value="other" label="Other">

For other methods of installing [Rust], see: https://www.rust-lang.org/tools/install

</TabItem>

</Tabs>

## Install the target

Install the `wasm32-unknown-unknown` target.
Expand All @@ -81,9 +96,15 @@ A popular editor is Visual Studio Code:

The [Stellar CLI](https://github.com/stellar/stellar-cli) can execute smart contracts on futurenet, testnet, mainnet, as well as in a local sandbox.

The latest stable release is [v{latestVersion}](https://github.com/stellar/stellar-cli/releases/latest).

### Install

There are a few ways to install the [latest released version](https://github.com/stellar/stellar-cli/releases) of Stellar CLI.
There are a few ways to install the [latest release](https://github.com/stellar/stellar-cli/releases) of Stellar CLI.

<Tabs groupId="platform" defaultValue={getPlatform()}>

<TabItem value="unix" label="macOS/Linux">

Install with Homebrew (macOS, Linux):

Expand All @@ -93,10 +114,44 @@ brew install stellar-cli

Install with cargo from source:

<StellarCliVersion />

Install with cargo to get the unreleased features from the `main` branch:

```sh
cargo install --locked stellar-cli --features opt
```

</TabItem>

<TabItem value="windows" label="Windows">

Using the installer:

1. Download the installer from the <a href={getStellarCliLatestReleaseUrl()}>latest release</a>.
2. Go to your Downloads folder, double click the installer and follow the wizard instructions.
3. Restart your terminal to use the `stellar` command.

Using [winget](https://learn.microsoft.com/en-us/windows/package-manager/winget/):

```sh
winget install --id Stellar.StellarCLI
```

Install with cargo from source:

<StellarCliVersion />

Install with cargo to get the unreleased features from the `main` branch:

```sh
cargo install --locked stellar-cli --features opt
```

</TabItem>

</Tabs>

:::info

Report issues and share feedback about the Stellar CLI [here](https://github.com/stellar/stellar-cli/issues/new/choose).
Expand All @@ -109,21 +164,94 @@ The auto-generated comprehensive reference documentation is available [here](../

### Autocompletion

You can use `stellar completion` to generate shell completion for `bash`, `elvish`, `fish`, `powershell`, and `zsh`. You should absolutely try it out. It will feel like a super power!
You can use `stellar completion` to generate shell completion for different shells. You should absolutely try it out. It will feel like a super power!

To enable autocomplete in the current bash shell, run:
<Tabs id="shell" defaultValue={getShell()}>

<TabItem value="bash" label="Bash">

To enable autocomplete on the current shell session:

```sh
source <(stellar completion --shell bash)
```

To enable autocomplete permanently in future bash shells, run:
To enable autocomplete permanently, run the following command, then restart your terminal:

```sh
echo "source <(stellar completion --shell bash)" >> ~/.bashrc
```

Users of non-bash shells may need to adapt the above commands to suit their needs.
</TabItem>

<TabItem value="zsh" label="ZSH">

To enable autocomplete on the current shell session:

```sh
source <(stellar completion --shell zsh)
```

To enable autocomplete permanently, run the following commands, then restart your terminal:

```sh
echo "source <(stellar completion --shell zsh)" >> ~/.zshrc
```

</TabItem>

<TabItem value="fish" label="fish">

To enable autocomplete on the current shell session:

```sh
stellar completion --shell fish | source
```

To enable autocomplete permanently, run the following command, then restart your terminal:

```sh
echo "stellar completion --shell fish | source" >> ~/.config/fish/config.fish
```

</TabItem>

<TabItem value="powershell" label="PowerShell">

To enable autocomplete on the current shell session:

```powershell
Invoke-Expression (stellar completion --shell powershell)
```

To enable autocomplete permanently, run the following commands, then restart your terminal:

```powershell
New-Item -ItemType Directory -Path $(Split-Path $PROFILE) -Force
New-Item -ItemType Directory -Path $USERPROFILE\.config\stellar -Force
if (-Not (Test-Path $PROFILE)) { New-Item -ItemType File -Path $PROFILE | Out-Null }
echo "Invoke-Expression (stellar completion --shell powershell)" >> $PROFILE
```

</TabItem>

<TabItem value="elvish" label="Elvish">

To enable autocomplete on the current shell session:

```sh
source (stellar completion --shell elvish)
```

To enable autocomplete permanently, run the following commands, then restart your terminal:

```sh
echo "source (stellar completion --shell elvish)" >> ~/.elvish/rc.elv
```

</TabItem>

</Tabs>

### Configuring the CLI for Testnet

Expand Down
18 changes: 15 additions & 3 deletions scripts/stellar_cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@ if (fs.existsSync(localRepoPath)) {
// Perform a shallow clone of the repository
console.log("Cloning repository...");
execSync(`git clone ${repoUrl} ${localRepoPath}`);
execSync(
`cd ${localRepoPath} && git checkout --quiet $(git tag | grep -v -E 'rc|preview' | tail -n1)`,
);
let latestVersion = execSync(
`cd ${localRepoPath} && git tag | grep -v -E 'rc|preview' | tail -n1`,
)
.toString()
.substring(1)
.trim();

console.log("the latest version is", latestVersion.toString());

execSync(`cd ${localRepoPath} && git checkout --quiet v${latestVersion}`);

// Copy FULL_HELP_DOCS.md
const fullHelpDocsPath = path.join(localRepoPath, "FULL_HELP_DOCS.md");
Expand All @@ -30,6 +37,11 @@ description: This document contains the help content for the stellar command-lin
${fullHelpDocsContent}
`;

fs.writeFileSync(
"src/helpers/stellarCli.ts",
`export const stellarCliVersion = "${latestVersion}";`,
);

fs.writeFileSync(
"docs/tools/developer-tools/cli/stellar-cli.mdx",
modifiedContent,
Expand Down
9 changes: 9 additions & 0 deletions src/components/StellarCliVersion.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from "react";
import CodeBlock from "@theme/CodeBlock";
import { latestVersion } from "@site/src/helpers/stellarCli";

export function StellarCliVersion() {
const command = `cargo install --locked stellar-cli --version v${latestVersion} --features opt`;

return <CodeBlock language="sh">{command}</CodeBlock>;
}
File renamed without changes.
7 changes: 7 additions & 0 deletions src/helpers/getShell.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function getShell() {
if (!globalThis.navigator) {
return "bash";
}

return navigator.userAgent.match(/Windows/) ? "powershell" : "bash";
}
5 changes: 5 additions & 0 deletions src/helpers/getStellarCliLatestReleaseUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { latestVersion } from "@site/src/helpers/stellarCli";

export function getStellarCliLatestReleaseUrl() {
return `https://github.com/stellar/stellar-cli/releases/download/v${latestVersion}/stellar-cli-installer-${latestVersion}-x86_64-pc-windows-msvc.exe`;
}
2 changes: 2 additions & 0 deletions src/helpers/stellarCli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Stub file: the real file is generated in build time by `yarn stellar-cli:build`.
export const latestVersion = "0.0.0";

0 comments on commit cda9fec

Please sign in to comment.