Skip to content

Add Rust custom environment #78

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions custom-environments/Rust/env_validation.ipynb
Original file line number Diff line number Diff line change
@@ -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
}
18 changes: 18 additions & 0 deletions custom-environments/Rust/install.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions custom-environments/Rust/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: rust
dependencies:
- cmake
7 changes: 7 additions & 0 deletions custom-environments/Rust/uninstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

evcxr_jupyter --uninstall
cargo uninstall evcxr_jupyter

conda deactivate
conda env remove -n rust