From 1cffcdf650233e3c308cca6eeefeaf64048c990c Mon Sep 17 00:00:00 2001 From: Jessie Mongeon Date: Wed, 14 Aug 2024 17:01:01 -0500 Subject: [PATCH 1/3] fixes to Rust intro docs --- .../backend/rust/2-project-organization.mdx | 12 +--- .../backend/rust/4-quickstart.mdx | 55 +------------- .../backend/rust/5-deploying.mdx | 71 +++---------------- 3 files changed, 13 insertions(+), 125 deletions(-) diff --git a/docs/developer-docs/backend/rust/2-project-organization.mdx b/docs/developer-docs/backend/rust/2-project-organization.mdx index 343a84087a..40a81bc916 100644 --- a/docs/developer-docs/backend/rust/2-project-organization.mdx +++ b/docs/developer-docs/backend/rust/2-project-organization.mdx @@ -13,16 +13,9 @@ import { MarkdownChipRow } from "/src/components/Chip/MarkdownChipRow"; When a new Rust project is created with the command: ``` -dfx new example +dfx new example --type=rust -? Select a backend language: › - Motoko -❯ Rust - TypeScript (Azle) - Python (Kybra) -``` - -the following project structure is generated: +The following project structure is generated: ``` Cargo.lock @@ -53,7 +46,6 @@ webpack.config.js In this structure, you can see the backend canister, in this case `example_backend` contains the following components: -src/example_backend: ``` │   ├── Cargo.toml // │   ├── example_backend.did // The backend canister's Candid file. diff --git a/docs/developer-docs/backend/rust/4-quickstart.mdx b/docs/developer-docs/backend/rust/4-quickstart.mdx index 7e4e0aab54..a9c24180f8 100644 --- a/docs/developer-docs/backend/rust/4-quickstart.mdx +++ b/docs/developer-docs/backend/rust/4-quickstart.mdx @@ -24,43 +24,8 @@ To create a new Rust project using the IC SDK, open a terminal window and run th Use `dfx new ` to create a new project: ``` -dfx new rust_hello -``` - -You will be prompted to select the language that your backend canister will use. Select 'Rust': - -``` -? Select a backend language: › - Motoko -❯ Rust - TypeScript (Azle) - Python (Kybra) -``` - -:::info -`dfx` versions `v0.17.0` and newer support this `dfx new` interactive prompt. [Learn more about `dfx v0.17.0`](/blog/2024/02/14/news-and-updates/update#dfx-v0170). -::: - - -Then, select a frontend framework for your frontend canister, or select 'No frontend canister': - -``` - ? Select a frontend framework: › -❯ SvelteKit - React - Vue - Vanilla JS - No JS template - No frontend canister -``` - -Lastly, you can include extra features to be added to your project: - -``` - ? Add extra features (space to select, enter to confirm) › -⬚ Internet Identity -⬚ Bitcoin (Regtest) -⬚ Frontend tests +dfx start --clean --background +dfx new rust_hello --type=rust ``` @@ -70,22 +35,6 @@ Next, navigate into your project directory by running the following command: cd rust_hello ``` -## Starting the local canister execution environment - -Next, before you can build your project, you need to connect to either the local replica running in your development environment or the decentralized Internet Computer mainnet. For this guide, you'll deploy locally in your developer environment. For more information on deploying on the mainnet, check out the next step [deploying canisters](./5-deploying.mdx). - -To start the local canister execution environment, first check that you are still in the root directory for your project, if needed. - -Then, start the local replica on your computer in the background by running the following command: - -``` -dfx start --clean --background -``` - -:::info -Depending on your platform and local security settings, you might see a warning displayed. If you are prompted to allow or deny incoming network connections, click **Allow**. -::: - ## Register, build, and deploy your project After you connect to the local replica running in your development environment, you can register, build, and deploy your project locally. diff --git a/docs/developer-docs/backend/rust/5-deploying.mdx b/docs/developer-docs/backend/rust/5-deploying.mdx index d6782e81a7..a84cd7162f 100644 --- a/docs/developer-docs/backend/rust/5-deploying.mdx +++ b/docs/developer-docs/backend/rust/5-deploying.mdx @@ -17,56 +17,11 @@ This guide will showcase a simple 'Hello, world!' example. ## Prerequisites -Before getting started, assure you have set up your developer environment according to the instructions in the [developer environment guide](./3-dev-env.mdx). +Before getting started, assure you have set up your developer environment according to the instructions in the [developer environment guide](./3-dev-env.mdx) and have created a [Rust project](./4-quickstart.mdx). -## Writing the canister +## Default project structure -Open a terminal window on your local computer, if you don’t already have one open. - -Use `dfx new [project_name]` to create a new project: - -``` -dfx new hello_world -``` - -You will be prompted to select the language that your backend canister will use: - -``` -? Select a backend language: › -❯ Motoko -Rust -TypeScript (Azle) -Python (Kybra) -``` - -:::info -`dfx` versions `v0.17.0` and newer support this `dfx new` interactive prompt. [Learn more about `dfx v0.17.0`](/blog/2024/02/14/news-and-updates/update#dfx-v0170). -::: - - -Then, select a frontend framework for your frontend canister. In this example, select: - -``` -? Select a frontend framework: › -SvelteKit -React -Vue -❯ Vanilla JS -No JS template -No frontend canister -``` - -Lastly, you can include extra features to be added to your project: - -``` -? Add extra features (space to select, enter to confirm) › -⬚ Internet Identity -⬚ Bitcoin (Regtest) -⬚ Frontend tests -``` - - -By default, the project structure will resemble the following: +By default, Rust projects created with `dfx new` will have a default project structure that will resemble the following: ``` Cargo.lock @@ -95,8 +50,6 @@ For more information on project structure and code organization, review the [pro ## Writing the `lib.rs` file -You'll be focused on the `src/hello_world_backend/src/lib.rs` file in this step. - Open the `src/hello_world_backend/src/lib.rs` file in a text editor. Replace the existing content with the following: ```rust @@ -130,9 +83,9 @@ ic-cdk = "0.7.0" Save the file. -## Deploying the canister to your local canister execution environment +## Deploying the canister locally -## Creating the canister +### Create First, create an empty canister for the canister code to be installed into. To create the canister, run the command: @@ -147,7 +100,7 @@ Creating canister hello_world_backend... hello_world_backend canister created with canister id: br5f7-7uaaa-aaaaa-qaaca-cai ``` -### Building the canister +### Build Next, you need to compile your program into a WebAssembly module that can be deployed on ICP by building the canister. To build the canister, run the command: @@ -155,7 +108,7 @@ Next, you need to compile your program into a WebAssembly module that can be dep dfx build hello_world_backend ``` -### Installing the canister +### Install Then, install the compiled code into your canister with the command: @@ -163,15 +116,9 @@ Then, install the compiled code into your canister with the command: dfx canister install hello_world_backend ``` -### Deploying to the execution environment - -To deploy the canister, start the dfx local replica with the command: - -``` -dfx start --clean --background -``` +### Deploy -Then, you can deploy the canister with the command: +To deploy the canister use the command: ``` dfx deploy hello_world_backend From 9b35de654aa890822fa9d12b63e0b3560eaf5f05 Mon Sep 17 00:00:00 2001 From: Jessie Mongeon <133128541+jessiemongeon1@users.noreply.github.com> Date: Wed, 14 Aug 2024 17:11:24 -0500 Subject: [PATCH 2/3] Update 8-optimizing.mdx --- docs/developer-docs/backend/rust/8-optimizing.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/developer-docs/backend/rust/8-optimizing.mdx b/docs/developer-docs/backend/rust/8-optimizing.mdx index d433550680..45150e6a44 100644 --- a/docs/developer-docs/backend/rust/8-optimizing.mdx +++ b/docs/developer-docs/backend/rust/8-optimizing.mdx @@ -10,7 +10,7 @@ import { MarkdownChipRow } from "/src/components/Chip/MarkdownChipRow"; ## Overview -Compiling Rust to Wasm often increases the file size significantly. dfx versions 0.14.0 and newer include a the `wasm-opt` optimization package that can be used to optimize cycle consumption and binary size. +Compiling Rust to Wasm often increases the file size significantly. dfx versions 0.14.0 and newer include the `wasm-opt` package that can be used to optimize cycle consumption and binary size. ## Prerequisites From b8a1659cc8a82162f58db202b53a2b49d8860ec2 Mon Sep 17 00:00:00 2001 From: Jessie Mongeon Date: Wed, 14 Aug 2024 17:35:29 -0500 Subject: [PATCH 3/3] fixes to Rust intro docs --- docs/developer-docs/backend/rust/2-project-organization.mdx | 2 +- docs/developer-docs/backend/rust/5-deploying.mdx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/developer-docs/backend/rust/2-project-organization.mdx b/docs/developer-docs/backend/rust/2-project-organization.mdx index 40a81bc916..680c06f3b3 100644 --- a/docs/developer-docs/backend/rust/2-project-organization.mdx +++ b/docs/developer-docs/backend/rust/2-project-organization.mdx @@ -236,4 +236,4 @@ If a service method returns a result type, it can still reject the call. Therefo ::: ## Next steps -Now let's get started setting up the Rust [developer environment](./3-dev-env.mdx). +Now let's get started setting up the Rust [developer environment](/docs/current/developer-docs/backend/rust/dev-env). diff --git a/docs/developer-docs/backend/rust/5-deploying.mdx b/docs/developer-docs/backend/rust/5-deploying.mdx index a84cd7162f..40cb80e57d 100644 --- a/docs/developer-docs/backend/rust/5-deploying.mdx +++ b/docs/developer-docs/backend/rust/5-deploying.mdx @@ -17,7 +17,7 @@ This guide will showcase a simple 'Hello, world!' example. ## Prerequisites -Before getting started, assure you have set up your developer environment according to the instructions in the [developer environment guide](./3-dev-env.mdx) and have created a [Rust project](./4-quickstart.mdx). +Before getting started, assure you have set up your developer environment according to the instructions in the [developer environment guide](/docs/current/developer-docs/backend/rust/dev-env) and have created a [Rust project](/docs/current/developer-docs/backend/rust/quickstart). ## Default project structure