From 26aa944ef7a43240dc3819352fbb093f88d21cb7 Mon Sep 17 00:00:00 2001 From: Yoshitaka Haribara Date: Sat, 26 Feb 2022 16:00:14 +0000 Subject: [PATCH 1/3] Add Rust custom environment --- custom-environments/Rust/env_validation.ipynb | 159 ++++++++++++++++++ custom-environments/Rust/install.sh | 15 ++ custom-environments/Rust/rust.yml | 3 + custom-environments/Rust/uninstall.sh | 7 + 4 files changed, 184 insertions(+) create mode 100644 custom-environments/Rust/env_validation.ipynb create mode 100644 custom-environments/Rust/install.sh create mode 100644 custom-environments/Rust/rust.yml create mode 100644 custom-environments/Rust/uninstall.sh diff --git a/custom-environments/Rust/env_validation.ipynb b/custom-environments/Rust/env_validation.ipynb new file mode 100644 index 0000000..b3b6333 --- /dev/null +++ b/custom-environments/Rust/env_validation.ipynb @@ -0,0 +1,159 @@ +{ + "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": 2, + "id": "6a1e087f-f353-435d-b261-9b7d52fd7ce9", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello, world!\n" + ] + } + ], + "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": 3, + "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": 4, + "id": "5c7144fb-afee-45d5-9991-c742a4d0ecf7", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "2\n", + "fizz\n", + "4\n", + "buzz\n", + "fizz\n", + "7\n", + "8\n", + "fizz\n", + "buzz\n", + "11\n", + "fizz\n", + "13\n", + "14\n", + "fizzbuzz\n", + "16\n", + "17\n", + "fizz\n", + "19\n", + "buzz\n" + ] + } + ], + "source": [ + "fizzbuzz_to(20);" + ] + }, + { + "cell_type": "markdown", + "id": "f72180a0-4bb1-47a7-9caa-e523567515a8", + "metadata": {}, + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "rust:Rust", + "language": "rust", + "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..6621892 --- /dev/null +++ b/custom-environments/Rust/install.sh @@ -0,0 +1,15 @@ +#!/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 \ 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 From f8341e9d87ead93fb1ad24c1ba71efa055658894 Mon Sep 17 00:00:00 2001 From: Yoshitaka Haribara Date: Sat, 26 Feb 2022 16:40:02 +0000 Subject: [PATCH 2/3] clear output --- custom-environments/Rust/env_validation.ipynb | 47 ++----------------- 1 file changed, 5 insertions(+), 42 deletions(-) diff --git a/custom-environments/Rust/env_validation.ipynb b/custom-environments/Rust/env_validation.ipynb index b3b6333..6d224c8 100644 --- a/custom-environments/Rust/env_validation.ipynb +++ b/custom-environments/Rust/env_validation.ipynb @@ -30,18 +30,10 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "id": "6a1e087f-f353-435d-b261-9b7d52fd7ce9", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Hello, world!\n" - ] - } - ], + "outputs": [], "source": [ "println!(\"Hello, world!\"); " ] @@ -57,7 +49,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "id": "5853a2a6-e34c-415c-909f-e0c7d8163577", "metadata": {}, "outputs": [], @@ -97,37 +89,10 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "id": "5c7144fb-afee-45d5-9991-c742a4d0ecf7", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1\n", - "2\n", - "fizz\n", - "4\n", - "buzz\n", - "fizz\n", - "7\n", - "8\n", - "fizz\n", - "buzz\n", - "11\n", - "fizz\n", - "13\n", - "14\n", - "fizzbuzz\n", - "16\n", - "17\n", - "fizz\n", - "19\n", - "buzz\n" - ] - } - ], + "outputs": [], "source": [ "fizzbuzz_to(20);" ] @@ -141,8 +106,6 @@ ], "metadata": { "kernelspec": { - "display_name": "rust:Rust", - "language": "rust", "name": "conda-env-rust-rust" }, "language_info": { From f925284416e02c6b3a40e582b3f6f5845134e692 Mon Sep 17 00:00:00 2001 From: Yoshitaka Haribara Date: Tue, 17 May 2022 05:04:56 +0000 Subject: [PATCH 3/3] install sccache --- custom-environments/Rust/install.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/custom-environments/Rust/install.sh b/custom-environments/Rust/install.sh index 6621892..c070b70 100644 --- a/custom-environments/Rust/install.sh +++ b/custom-environments/Rust/install.sh @@ -12,4 +12,7 @@ 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 \ No newline at end of file +evcxr_jupyter --install + +#install additional packages +cargo install sccache \ No newline at end of file