Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sketch troubleshooting (e.g. Rust installation, rust-analyzer) #750

Merged
merged 8 commits into from
Dec 11, 2023
Merged
2 changes: 1 addition & 1 deletion docs/developers/tutorials/crowdfunding-p1.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ The source code of each smart contract requires its own folder. You'll need to c
```bash
mkdir -p ~/MultiversX/SmartContracts
cd ~/MultiversX/SmartContracts
mxpy contract new crowdfunding --template empty
mxpy contract new --name crowdfunding --template empty
code crowdfunding
```

Expand Down
2 changes: 1 addition & 1 deletion docs/developers/tutorials/staking-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Both can be easily installed from the "Extensions" menu in VSCode.
Run the following command in the folder in which you want your smart contract to be created:

```
mxpy contract new staking-contract --template empty
mxpy contract new --name staking-contract --template empty
```

Open VSCode, select File -> Open Folder, and open the newly created `staking-contract` folder.
Expand Down
4 changes: 2 additions & 2 deletions docs/sdk-and-tools/sdk-py/mxpy-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ For example, in order to check if `rust` is installed you would type:
mxpy deps check rust
```

When installing dependecies the `--overwrite` argument can be used to overwrite an existing version. Also the `--tag` argument can be used to specify the exact version you want to install.
When installing dependecies the `--overwrite` argument can be used to overwrite an existing version.

For example, to install `rust`, you can simply type the command:
```sh
Expand All @@ -78,7 +78,7 @@ Generally speaking, the default `rust` version installed by `mxpy` is the one re

Here's how to install a specific version of `rust` (example):
```sh
mxpy deps install rust --tag nightly-2023-04-24 --overwrite
mxpy deps install rust --overwrite
```

[comment]: # (mx-context-auto)
Expand Down
46 changes: 46 additions & 0 deletions docs/sdk-and-tools/troubleshooting/ide-setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
id: ide-setup
title: Fix IDEs configuration
---

[comment]: # (mx-abstract)

The issues tackled on this page are related to IDEs preferred by MultiversX builders, such as **VSCode** or **RustRover**. The issues are not strictly related to the official MultiversX VSCode extension (also known as [MultiversX IDE](https://marketplace.visualstudio.com/items?itemName=Elrond.vscode-elrond-ide)).

[comment]: # (mx-context-auto)

## VSCode: fix configuration for Rust Analyzer

If `rust-analyzer` is not working properly on VSCode, you might see (one of) the following error messages:

```
- rust-analyzer failed to load workspace: Failed to load the project.
- Failed to query rust toolchain version.
- error: rustup could not choose a version of cargo to run, because one wasn't specified explicitly, and no default is configured.
```

To fix this, first **[make sure Rust is properly installed](/sdk-and-tools/troubleshooting/rust-setup)**.

Afterwards, check the content of the configuration file `.vscode/settings.json`.

Basic `.vscode/settings.json` for Linux:

```json
{
"terminal.integrated.env.linux": {
"PATH": "${env:HOME}/multiversx-sdk:${env:HOME}/multiversx-sdk/vmtools:${env:PATH}",
}
}
```

Basic `.vscode/settings.json` for MacOS:

```json
{
"terminal.integrated.env.osx": {
"PATH": "${env:HOME}/multiversx-sdk:${env:HOME}/multiversx-sdk/vmtools:${env:PATH}",
}
}
```

Then, restart VSCode. Now, `rust-analyzer` should work properly. If the problem persists, please [contact us](/developers/overview).
162 changes: 162 additions & 0 deletions docs/sdk-and-tools/troubleshooting/rust-setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
---
id: rust-setup
title: Fix Rust installation
---

[comment]: # (mx-abstract)

When encountering issues with your Rust installation, we recommend a cleanup (uninstall) first, especially if you have multiple installations (by accident or on purpose).

[comment]: # (mx-context-auto)

## Uninstall existing Rust

If you've installed Rust using your OS package manager:

```bash
# Ubuntu
sudo apt remove cargo
sudo apt autoremove
```

If you've installed Rust using `rustup`:

```bash
rustup self uninstall
```

If you've installed Rust using `mxpy` with a version older than `v9`:

```bash
rm -rf ~/multiversx-sdk/vendor-rust
```

:::note
Since `mxpy v9` (November of 2023), `mxpy deps install rust` does not create an isolated Rust installation anymore in `~/multiversx-sdk/vendor-rust`. Instead, [it installs Rust _globally_](https://www.rust-lang.org/tools/install).
:::

If you've installed Rust using `mxpy v9` or later:

```bash
rustup self uninstall
```

[comment]: # (mx-context-auto)

## Installing Rust and sc-meta

[comment]: # (mx-context-auto)

:::note
`sc-meta` is universal smart contract management tool. Please follow [this](/developers/meta/sc-meta) for more information.
:::

### With mxpy

```bash
mxpy deps install rust --overwrite
```

:::note
In addition to Rust and `sc-meta`, the above command also installs `twiggy` and `wasm-opt`.
:::

For more information, go to [managing dependencies using `mxpy`](/sdk-and-tools/sdk-py/mxpy-cli/#managing-dependencies).

[comment]: # (mx-context-auto)

### Without mxpy

As recommended on [rust-lang.org](https://www.rust-lang.org/tools/install):

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

Then, choose **Proceed with installation (default)**.

Once Rust is installed, switch to a nightly version and install the `wasm32-unknown-unknown` target:

```bash
rustup default nightly-2023-05-26
rustup target add wasm32-unknown-unknown
```

Afterwards, install `sc-meta`:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: maybe would be good to specify that when installing using mxpy sc-meta, twiggy and wasm-opt are also installed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


```bash
cargo install multiversx-sc-meta
```

Optionally, you may also want to install `wasm-opt` and `twiggy`:

```bash
cargo install wasm-opt
cargo install twiggy
```

[comment]: # (mx-context-auto)

### Without mxpy (CI / CD)

For CI / CD, use the following:

```bash
wget -O rustup.sh https://sh.rustup.rs && \
chmod +x rustup.sh && \
./rustup.sh --verbose --default-toolchain nightly-2023-05-26 --target wasm32-unknown-unknown -y

cargo install multiversx-sc-meta
```

[comment]: # (mx-context-auto)

### Handle missing dependencies of sc-meta

`sc-meta` requires a few dependencies that are not installed by default on some systems. In this case, installation of `sc-meta` fails.

For a workaround, please follow this [GitHub issue](https://github.com/multiversx/mx-sdk-py-cli/issues/338).

## Check your Rust installation

You can check your Rust installation by invoking `rustup show`:

```
$ rustup show

Default host: x86_64-unknown-linux-gnu
rustup home: /home/ubuntu/.rustup

installed toolchains
--------------------

[...]
nightly-2023-05-26-x86_64-unknown-linux-gnu (default)

installed targets for active toolchain
--------------------------------------

[...]
wasm32-unknown-unknown


active toolchain
----------------

[...]
nightly-2023-05-26-x86_64-unknown-linux-gnu (default)
```

You can also check the status of your Rust installation using `mxpy`:

```
$ mxpy deps check rust

INFO cli.deps: Checking dependency: module = rust, tag = nightly-2023-05-26
INFO modules: which rustc: /home/ubuntu/.cargo/bin/rustc
INFO modules: which cargo: /home/ubuntu/.cargo/bin/cargo
INFO modules: which sc-meta: /home/ubuntu/.cargo/bin/sc-meta
INFO modules: which wasm-opt: /home/ubuntu/.cargo/bin/wasm-opt
INFO modules: which twiggy: /home/ubuntu/.cargo/bin/twiggy
INFO cli.deps: [rust nightly-2023-05-26] is installed.
```
11 changes: 11 additions & 0 deletions docs/sdk-and-tools/troubleshooting/troubleshooting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
id: troubleshooting
title: Overview
---

[comment]: # (mx-abstract)

Here you can find some common issues and their solutions, in the context of [MultiversX SDKs and Tools](/sdk-and-tools/overview).

1. [Fix Rust installation](/sdk-and-tools/troubleshooting/rust-setup)
2. [Fix IDEs configuration](/sdk-and-tools/troubleshooting/ide-setup)
11 changes: 10 additions & 1 deletion sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,18 @@ const sidebars = {
"sdk-and-tools/erdcpp",
"sdk-and-tools/sdk-nestjs",
"sdk-and-tools/erdkotlin",
"sdk-and-tools/sdk-js-wallet-cli",
"sdk-and-tools/sdk-js-wallet-cli"
],
},
{
type: "category",
label: "Troubleshooting",
items: [
"sdk-and-tools/troubleshooting/troubleshooting",
"sdk-and-tools/troubleshooting/rust-setup",
"sdk-and-tools/troubleshooting/ide-setup"
],
}
],
Wallet: [
"wallet/overview",
Expand Down
Loading