iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🦀

Setting up a Rust Development Environment on Cloud9

に公開

Introduction

I am 135yshr, and I have recently started learning Rust.
Since I needed a Rust environment on Cloud9, I have recorded the steps I took.
If there is anything missing, I would appreciate your feedback.

Installing Rust

Executing the command

curl https://sh.rustup.rs -sSf | sh

Confirming options

If you have no specific preferences, just press the Enter key.

Current installation options:


   default host triple: x86_64-unknown-linux-gnu
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>

Restarting the shell

When the installation is complete, a message will appear asking you to restart your shell. Execute the command to restart the shell.

Rust is installed now. Great!

To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory ($HOME/.cargo/bin).

To configure your current shell, run:
source $HOME/.cargo/env

Shell restart

exec $SHELL -l

Verification

cargo -V
cargo 1.62.0 (a748cf5a3 2022-06-08)

Cloud9 Configuration

Execution environment

Create a Runner

Click Run -> Run With -> New Runner in that order.
A template for the runner will appear. Rewrite it as follows and save it as .c9/runners/rust.run.

// Create a custom Cloud9 runner - similar to the Sublime build system
// For more information see http://docs.aws.amazon.com/console/cloud9/create-run-config
{
    "cmd" : ["cargo", "run", "$file", "$args"],
    "info" : "Started $project_path$file_name",
    "env" : {},
    "selector" : "source.rs"
}

Screenshot of the save screen

Verification

Click Run -> Run With and confirm that "Rust" is present.

Test environment

Create a Runner

This step is not mandatory, so please perform it only if necessary.

Similar to Create a Runner, click Run -> Run With -> New Runner in that order.
A template for the runner will appear. Rewrite it as follows and save it as .c9/runners/rust_test.run.

// Create a custom Cloud9 runner - similar to the Sublime build system
// For more information see http://docs.aws.amazon.com/console/cloud9/create-run-config
{
    "cmd" : ["cargo", "test"],
    "info" : "Started $project_path$file_name",
    "env" : {},
    "selector" : "source.rs"
}

Verification

Click Run -> Run With and confirm that "Rust_test" is present.

Code Formatter Configuration

Installation

rustup component add rustfmt

Verification of installation

cargo fmt

Discussion