diff --git a/custom-environments/Rust/env_validation.ipynb b/custom-environments/Rust/env_validation.ipynb new file mode 100644 index 0000000..6d224c8 --- /dev/null +++ b/custom-environments/Rust/env_validation.ipynb @@ -0,0 +1,122 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "1d8e03e9-9345-44b0-b113-d610e55d7e5d", + "metadata": {}, + "source": [ + "# Rust Environment Validation\n", + "\n", + "[![Open in SageMaker Studio Lab](https://studiolab.sagemaker.aws/studiolab.svg)](https://studiolab.sagemaker.aws/import/github/aws/studio-lab-examples/blob/main/custom-environments/Rust/env_validation.ipynb)" + ] + }, + { + "cell_type": "markdown", + "id": "23537e27-fd37-4fd0-b27e-dfe19ff65b5f", + "metadata": {}, + "source": [ + "This notebook validates your Rust environment. This assumes you have a default installation of Rust with all dependencies and datasets and the environment was built using the example `.yml` file and `install.sh` script. Open this notebook with the `rust:Rust` kernel to verify your environment." + ] + }, + { + "cell_type": "markdown", + "id": "91f3a130-dc85-4560-bee3-d6af785e2015", + "metadata": {}, + "source": [ + "## Hello world\n", + "\n", + "Make sure you can import packages without any errors. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6a1e087f-f353-435d-b261-9b7d52fd7ce9", + "metadata": {}, + "outputs": [], + "source": [ + "println!(\"Hello, world!\"); " + ] + }, + { + "cell_type": "markdown", + "id": "fe7068d0-9b6d-4734-8661-d2960506cebd", + "metadata": {}, + "source": [ + "## Function\n", + "Verify you can run FizBuzz using functinos as in [Rust By Example](https://doc.rust-lang.org/rust-by-example/fn.html). " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5853a2a6-e34c-415c-909f-e0c7d8163577", + "metadata": {}, + "outputs": [], + "source": [ + "// Function that returns a boolean value\n", + "fn is_divisible_by(lhs: u32, rhs: u32) -> bool {\n", + " // Corner case, early return\n", + " if rhs == 0 {\n", + " return false;\n", + " }\n", + "\n", + " // This is an expression, the `return` keyword is not necessary here\n", + " lhs % rhs == 0\n", + "}\n", + "\n", + "// Functions that \"don't\" return a value, actually return the unit type `()`\n", + "fn fizzbuzz(n: u32) -> () {\n", + " if is_divisible_by(n, 15) {\n", + " println!(\"fizzbuzz\");\n", + " } else if is_divisible_by(n, 3) {\n", + " println!(\"fizz\");\n", + " } else if is_divisible_by(n, 5) {\n", + " println!(\"buzz\");\n", + " } else {\n", + " println!(\"{}\", n);\n", + " }\n", + "}\n", + "\n", + "// When a function returns `()`, the return type can be omitted from the\n", + "// signature\n", + "fn fizzbuzz_to(n: u32) {\n", + " for n in 1..=n {\n", + " fizzbuzz(n);\n", + " }\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5c7144fb-afee-45d5-9991-c742a4d0ecf7", + "metadata": {}, + "outputs": [], + "source": [ + "fizzbuzz_to(20);" + ] + }, + { + "cell_type": "markdown", + "id": "f72180a0-4bb1-47a7-9caa-e523567515a8", + "metadata": {}, + "source": [] + } + ], + "metadata": { + "kernelspec": { + "name": "conda-env-rust-rust" + }, + "language_info": { + "codemirror_mode": "rust", + "file_extension": ".rs", + "mimetype": "text/rust", + "name": "Rust", + "pygment_lexer": "rust", + "version": "" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/custom-environments/Rust/install.sh b/custom-environments/Rust/install.sh new file mode 100644 index 0000000..c070b70 --- /dev/null +++ b/custom-environments/Rust/install.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +#create conda env for Rust +cd $HOME/studio-lab-examples/custom-environments/Rust && conda env create -f rust.yml +conda activate rust + +#install Rust to conda environment +export CARGO_HOME=$HOME/.conda/envs/rust +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y +source $HOME/.conda/envs/rust/env + +#install evcxr_jupyter to conda environment +export JUPYTER_PATH=$HOME/.conda/envs/rust/share/jupyter/ +cargo install evcxr_jupyter +evcxr_jupyter --install + +#install additional packages +cargo install sccache \ No newline at end of file diff --git a/custom-environments/Rust/rust.yml b/custom-environments/Rust/rust.yml new file mode 100644 index 0000000..32712ce --- /dev/null +++ b/custom-environments/Rust/rust.yml @@ -0,0 +1,3 @@ +name: rust +dependencies: + - cmake \ No newline at end of file diff --git a/custom-environments/Rust/uninstall.sh b/custom-environments/Rust/uninstall.sh new file mode 100644 index 0000000..065e1f6 --- /dev/null +++ b/custom-environments/Rust/uninstall.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +evcxr_jupyter --uninstall +cargo uninstall evcxr_jupyter + +conda deactivate +conda env remove -n rust