├── .editorconfig ├── .vscode ├── settings.json └── launch.json ├── .devcontainer ├── Dockerfile ├── devcontainer.json └── setup.sh ├── hello ├── Cargo.toml └── src │ └── main.rs ├── .gitignore ├── LICENSE ├── CODE_OF_CONDUCT.md └── README.md /.editorconfig: -------------------------------------------------------------------------------- 1 | [core] 2 | indent=4 -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "rust-analyzer.linkedProjects": [ 3 | "./hello/Cargo.toml" 4 | ] 5 | } -------------------------------------------------------------------------------- /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:18.04 2 | 3 | WORKDIR /home/ 4 | 5 | COPY . . 6 | 7 | RUN bash ./setup.sh 8 | 9 | ENV PATH="/root/.cargo/bin:$PATH" 10 | -------------------------------------------------------------------------------- /hello/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hello" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Codespaces Rust Starter", 3 | "extensions": [ 4 | "cschleiden.vscode-github-actions", 5 | "ms-vsliveshare.vsliveshare", 6 | "matklad.rust-analyzer", 7 | "serayuzgur.crates", 8 | "vadimcn.vscode-lldb" 9 | ], 10 | "dockerFile": "Dockerfile", 11 | "settings": { 12 | "editor.formatOnSave": true, 13 | "terminal.integrated.shell.linux": "/usr/bin/zsh", 14 | "files.exclude": { 15 | "**/CODE_OF_CONDUCT.md": true, 16 | "**/LICENSE": true 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /hello/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let m: u64 = gcd(5, 11); 3 | println!("{}", m); 4 | } 5 | 6 | fn gcd(mut n: u64, mut m: u64) -> u64 { 7 | debug_assert!(n != 0 && m != 0); 8 | 9 | while m != 0 { 10 | println!("{} {}", m, n); 11 | if m < n { 12 | let t = m; 13 | m = n; 14 | n = t; 15 | } 16 | m = m % n; 17 | } 18 | 19 | n 20 | } 21 | 22 | #[test] 23 | fn test_gcd() { 24 | assert_eq!(gcd(11, 5), 1); 25 | assert_eq!(gcd(12, 4), 4); 26 | } 27 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "lldb", 9 | "request": "launch", 10 | "name": "Debug", 11 | "program": "${workspaceFolder}/", 12 | "args": [], 13 | "cwd": "${workspaceFolder}" 14 | } 15 | ] 16 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.toptal.com/developers/gitignore/api/rust,rust-analyzer 2 | # Edit at https://www.toptal.com/developers/gitignore?templates=rust,rust-analyzer 3 | 4 | ### Rust ### 5 | # Generated by Cargo 6 | # will have compiled files and executables 7 | debug/ 8 | target/ 9 | 10 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 11 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 12 | Cargo.lock 13 | 14 | # These are backup files generated by rustfmt 15 | **/*.rs.bk 16 | 17 | # MSVC Windows builds of rustc generate these, which store debugging information 18 | *.pdb 19 | 20 | ### rust-analyzer ### 21 | # Can be generated by other build systems other than cargo (ex: bazelbuild/rust_rules) 22 | rust-project.json 23 | 24 | 25 | # End of https://www.toptal.com/developers/gitignore/api/rust,rust-analyzer -------------------------------------------------------------------------------- /.devcontainer/setup.sh: -------------------------------------------------------------------------------- 1 | ## update and install some things we should probably have 2 | apt-get update 3 | apt-get install -y \ 4 | curl \ 5 | git \ 6 | gnupg2 \ 7 | jq \ 8 | sudo \ 9 | zsh \ 10 | vim \ 11 | build-essential \ 12 | openssl 13 | 14 | ## Install rustup and common components 15 | curl https://sh.rustup.rs -sSf | sh -s -- -y 16 | rustup install nightly 17 | rustup component add rustfmt 18 | rustup component add rustfmt --toolchain nightly 19 | rustup component add clippy 20 | rustup component add clippy --toolchain nightly 21 | 22 | cargo install cargo-expand 23 | cargo install cargo-edit 24 | 25 | ## setup and install oh-my-zsh 26 | sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" 27 | cp -R /root/.oh-my-zsh /home/$USERNAME 28 | cp /root/.zshrc /home/$USERNAME 29 | sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc 30 | chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2020 Tierney Cyren 3 | 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 19 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 21 | OR OTHER DEALINGS IN THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | hello@bnb.im. 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Codespaces Rust Starter 2 | 3 | This project is a generic starter for developers to use in Codespaces that includes basic system tools and extensions. 4 | 5 | ## What's Included 6 | 7 | This is a basic environment that should be ready to expand upon to build a day-to-day development envrionment for Rust. It comes with the following software choices: 8 | 9 | ### System Tools 10 | 11 | - [curl/curl](https://github.com/curl/curl): the command line tool for transferring data over a metric boatload of protocols. 12 | - git: the Git SCM tool. 13 | - [gnupg2](https://gnupg.org/): a complete and free implementatiuon of the OpenPGP standard. 14 | - [stedolan/jq](https://github.com/stedolan/jq) - a command line JSON parser. 15 | - [sudo](https://www.sudo.ws/) - the superuser authority delegation tool. 16 | - [zsh](https://www.zsh.org/) - interactive terminal (alternative to `bash`). 17 | - [ohmyzsh/ohmyzsh](https://github.com/ohmyzsh/ohmyzsh) - a delightful community driven framework for managing zsh config. 18 | - [vim](https://www.vim.org/) - a text editor 19 | - build essentials - tools for compiling and linking code 20 | - [openssl](https://www.openssl.org/) - tls and ssl toolkit 21 | 22 | ### Rust Tools 23 | 24 | Besides Rust and Cargo, the image comes with the following Rust related tooling: 25 | 26 | - [rustup](https://rustup.rs/): installer and toolchain manager 27 | - [rustfmt](https://github.com/rust-lang/rustfmt): a tool for formatting Rust code according to style guidelines 28 | - [clippy](https://github.com/rust-lang/rust-clippy): lints to catch common mistakes and improve your Rust code 29 | 30 | ### VS Code Extensions 31 | 32 | - [Rust Analyzer](https://marketplace.visualstudio.com/items?itemName=matklad.rust-analyzer): an alternative rust language server to the RLS. 33 | - [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb): native debugger based on LLDB. 34 | - [Crates](https://marketplace.visualstudio.com/items?itemName=serayuzgur.crates): helps Rust developers managing dependencies with Cargo.toml. 35 | - [Live Share](https://marketplace.visualstudio.com/items?itemName=ms-vsliveshare.vsliveshare): collaborative, multi-user remote editing from directly within the editor. 36 | 37 | ### Operating System 38 | 39 | - [Ubuntu 18.04](https://releases.ubuntu.com/18.04.4/): The 18.04 LTS version of Ubuntu. 40 | 41 | ## Usage 42 | 43 | ### Visual Studio Codespaces 44 | 45 | #### Inital Creation 46 | 47 | For usage in VS Codespaces, you're going to want to head over to [online.visualstudio.com](https://online.visualstudio.com) and sign up for VS Codespaces (that process is outside the scope of these instructions). Once you've got an account and are signed in to [online.visualstudio.com](https://online.visualstudio.com), you're going to take the following steps: 48 | 49 | - Ensure you're on the `/environments` page at [online.visualstudio.com/environments](https://online.visualstudio.com/environments) 50 | - In the top right corner, there'll be a "Create environment" button. Click this button, which will open up a panel from the right side of the screen. Fill in the details of this panel: 51 | - **Codespace Name:** This will be the visible name of your environment within Codespaces. The value here doesn't particularly matter. 52 | - **Git Repository:** This is going to be either the URL you'd `git clone` the repo from or the GitHub `/` shorthand. For this repo, the easier value would be `codespaces-examples/rust`. 53 | - **Instance Type:** For this, you're going to choose your plan - in my case, I'm just going to go with the `Standard (Linux)` plan. For most use cases of this starter, `Basic (Linux)` should suffice. You can also change your plan at any time, as your workload demands. 54 | - **Suspend idle environment after:** This is the period of time you want your environment to automatically suspend after you've stopped actively using it. I generally chose 5 minutes and have not had any problems to date. 55 | - **Dotfiles (optional):** These are entirely optional, and are available for advanced users. 56 | - **Dotfiles Repository:** Using the `git clone` URL or the GitHub `/` syntax, you can define the repo to pull your dotfiles from. For examples, see [jessfraz/dotfiles](https://github.com/jessfraz/dotfiles) or [fnichol/dotfiles](https://github.com/fnichol/dotfiles). 57 | - **Dotfiles Install Command:** The name of the file or the command to run to install your dotfiles. 58 | - **Dotfiles Target Path:** The path where your dotfiles should be installed. 59 | - Once you've filled out all of those (and resolved any errors in the form validation, if any occurred), you'll be able to click "Create" at the bottom of the panel and your environment will start creating. 60 | 61 | #### Connecting to your Environment 62 | 63 | Once you've completed the Creation steps, your environment will be usable from Codespaces until you delete it. You can access it by going to [online.visualstudio.com](https://online.visualstudio.com) and selecting the vertical elipsis menu to connect to it from the browser or launch it in VS Code / VS Code Insiders. 64 | 65 | When inside of the environment you can change envrionments themselves from the command pallete with the `Codespaces: Connect`. 66 | 67 | > **Note:** See the [VS Online in the Browser](https://docs.microsoft.com/en-us/visualstudio/online/quickstarts/browser) quickstart for more information. 68 | 69 | Additionally, if you've installedthe [Visual Studio Codespaces](https://marketplace.visualstudio.com/items?itemName=ms-vsonline.vsonline) extension in VS Code locally, you'll be able to directly connect from VS Code itself. 70 | 71 | > **Note:** See the [VS Online in VS Code](https://docs.microsoft.com/en-us/visualstudio/online/quickstarts/vscode) quickstart for more information. 72 | 73 | #### Working 74 | 75 | Now that you're set up and connected, you should be able to work within your Codespaces environment. 76 | 77 | ### Developing inside a Container 78 | 79 | Using [Visual Studio Code](https://code.visualstudio.com/) and a [specific extension](https://aka.ms/vscode-remote/download/extension), we can load this setup in a brand new local [Docker](https://docker.com/) container and use it as a full-featured development environment. Note that this approach requires a few more steps than using the online setup mentioned above. The advantages being that this works offline and there are no costs associated with this approach. It is a great way to play with a setup without having to install everything globally on one's machine! 80 | 81 | #### Requirements 82 | 83 | There are 3 main requirements: **VSCode**, **the Remote - Containers VSCode extension** and **Docker**. 84 | 85 | Follow the instruction [guide here](https://code.visualstudio.com/docs/remote/containers#_installation) and come back here once those 3 components are installed locally. 86 | 87 | ### Setup 88 | 89 | To load this setup in a container, we need to point to it. We have many options here, the main ones being to connect to a repository and the other one to open a local folder with the codespace repo checked out. We are going to take the easiest approach and setup the code space directly from this repository. 90 | 91 | 1. In VSCode, click on the green icon in the lower left corner. 92 | 93 | ![](https://code.visualstudio.com/assets/docs/remote/common/remote-dev-status-bar.png) 94 | 95 | 2. Choose `Remote-Containers: Open Repository in container` 96 | 3. Type `codespaces-examples/rust` in the prompt. 97 | 4. Chose to create a unique volume. 98 | 5. Wait until the container is setup and you are connected to it, at this point, it should ask you to install the Language server for the rust-analyzer, go ahead and click "Download now". 99 | ![](https://user-images.githubusercontent.com/113/84297926-2ad3da00-ab03-11ea-8045-690eb0763d9f.png) 100 | 101 | That's it, you are all setup, you can modify and run the code in your local VSCode instance but the code and extensions will run in your container. 102 | 103 | 104 | ## Contributing 105 | 106 | Contributions are welcome. Please refrain from opinionated additions like linters. However, adding package managers and other DX improvements that are additive like `yarn` are welcome. Contributors must follow the [Code of Conduct](./CODE_OF_CONDUCT.md). 107 | --------------------------------------------------------------------------------