An open API service indexing awesome lists of open source software.

https://github.com/yiwiy9/atcoder-rust-devcontainer

This is a repository that provides a development environment for Rust programming language, pre-configured with tools and settings optimized for participating in AtCoder competitions.
https://github.com/yiwiy9/atcoder-rust-devcontainer

atcoder automation competitive-programming docker rust vscode

Last synced: 20 days ago
JSON representation

This is a repository that provides a development environment for Rust programming language, pre-configured with tools and settings optimized for participating in AtCoder competitions.

Awesome Lists containing this project

README

          

# ๐Ÿ†๐Ÿฆ€ AtCoder Rust Devcontainer

[![CI](https://github.com/yiwiy9/atcoder-rust-devcontainer/actions/workflows/ci.yml/badge.svg)](https://github.com/yiwiy9/atcoder-rust-devcontainer/actions)
[![License: MIT OR Apache-2.0](https://img.shields.io/badge/license-MIT_OR_Apache--2.0-blue)](#-license)

## ๐ŸŒ Overview

The `atcoder-rust-devcontainer` repository offers a tailored development environment for competitive programming in the Rust language, specifically for AtCoder contests. Utilizing a devcontainer setup, it simplifies the task of setting up and diving straight into coding challenges without the usual overhead of environment configuration.

## ๐Ÿš€ Key Features, Benefits, and Available Tools

- **๐Ÿ”ง Integrated Toolset**: Equip yourself with general Rust tools like [rust-analyzer](https://github.com/rust-lang/rust-analyzer), [rustfmt](https://github.com/rust-lang/rustfmt), [clippy](https://github.com/rust-lang/rust-clippy), and the VS Code-specific debugger [vscode-lldb](https://github.com/vadimcn/codelldb). For competitive programming, this environment also integrates [cargo-compete](https://github.com/qryxip/cargo-compete) and [cargo-snippet](https://github.com/hatoo/cargo-snippet).

- **๐ŸŒŸ Hassle-Free Setup**: Bypass the tedious process of setting up tools individually. Jump directly into competitive programming with everything set up for you.

- **๐Ÿ” Optimized for Rust**: This devcontainer is fine-tuned for Rust, offering features such as auto-formatting, linting, and debugging for a smooth coding experience.

- **๐Ÿ“ฆ Quick Code Snippets**: Leverage the integrated cargo-snippet to create and utilize Rust code snippets effortlessly in Visual Studio Code.

## ๐Ÿ›  Prerequisites

- [Visual Studio Code](https://code.visualstudio.com/)
- [Docker](https://www.docker.com/)

## ๐Ÿšถ Getting Started

๐Ÿ“‹ **Setting Up Your Environment**:

- Copy the `.devcontainer/.env.example` file to `.devcontainer/.env`.
- Inside the `.devcontainer/.env` file, make sure to set the following:
- `ATCODER_REVEL_SESSION`: Replace with your AtCoder Session Cookie.

After updating the values, you'll need to rebuild the devcontainer for the changes to take effect.

By configuring these values correctly, the devcontainer will be able to automatically sign you into the AtCoder platform upon successful rebuild.

> ๐Ÿ’ก How to get your `REVEL_SESSION` cookie: See the [aclogin README (Japanese)](https://github.com/key-moon/aclogin/blob/main/README.md).

## ๐Ÿ”‘ Key Files and Usage

### `entrypoint.sh` ๐Ÿ“„

This script initializes the development environment:

1. ๐Ÿ–‡ Copies the example VS Code settings file for rust-analyzer to the appropriate location, if it doesn't already exist.
1. ๐Ÿ“ Generates Rust code snippets using `cargo_snippet.sh`.
1. ๐Ÿ”’ Writes the AtCoder session cookie (`REVEL_SESSION`) and attempts login via `cargo compete login atcoder`.

### `cargo_compete_new.sh` ๐Ÿ“‚

This script sets up a new contest directory and updates the rust-analyzer configuration in the VS Code settings.

#### ๐Ÿš€ Usage

1. ๐Ÿ–ฅ Open the terminal within the devcontainer.
1. โ–ถ Run `cargo_compete_new.sh ` where `` is the contest's name.

### `create_gitkeep_in_testcases.sh` ๐Ÿ“‚

This script is a workaround for the issue detailed in [qryxip/cargo-compete#198](https://github.com/qryxip/cargo-compete/pull/198). It automates the creation of `.gitkeep` files within the `in/out` directories of the `cargo compete` testcases, ensuring that these directories are tracked by Git even if they are empty.

#### ๐Ÿš€ Usage

1. ๐Ÿ–ฅ Open the terminal within the devcontainer.
1. โ–ถ Run the script by typing `create_gitkeep_in_testcases.sh `.

The script will iterate over all `.yml` files in the `/testcases` directory and ensure that each corresponding `in/out` directory has a `.gitkeep` file.

๐Ÿ“ **Note**:

- When you execute `cargo_compete_new.sh`, the `create_gitkeep_in_testcases.sh` script is automatically run for the new contest directory.
- If you're using `cargo compete add` to add problems, you'll need to run `create_gitkeep_in_testcases.sh` manually for the specific contest directory.

### `cargo_snippet.sh` ๐Ÿ–‡

This script generates Rust code snippets for Visual Studio Code, tailored for competitive programming. It allows you to create custom snippets in the `src/lib` directory and make them available for use within Visual Studio Code.

#### ๐Ÿš€ Usage

1. ๐Ÿ–ฅ Open the terminal within the devcontainer.
1. โ–ถ Run the script by typing `cargo_snippet.sh`.

This updates the `rust.code-snippets` file in the `.vscode` directory, making your custom snippets available in Visual Studio Code.

## ๐Ÿ›  Usage Examples

### ๐Ÿ Setting up and Solving Problems (e.g., AtCoder Beginner Contest 317)

1. ๐Ÿ“ **Create a new contest directory**:
- `cargo_compete_new.sh abc317`
1. ๐Ÿšถ **Navigate to the created directory**:
- `cd $WORKSPACE_FOLDER/src/contest/abc317/`
1. ๐Ÿ“ **Solving a Problem (e.g., Problem A)**:
- ๐Ÿงช Execute sample test cases: `cargo compete test a`
- ๐Ÿ“ค Submit your solution: `cargo compete submit a`

### ๐ŸŽฏ Solving a Specific Problem (e.g., ABC317 problem a)

1. ๐Ÿšถ **Navigate to your preferred directory**:
- `cd $WORKSPACE_FOLDER/src/{your_directory_of_choice}`
1. โž• **Add the desired problem**:
- `cargo compete add abc317_a`
1. ๐Ÿงช **Execute sample test cases**:
- `cargo compete test abc317_a`
1. ๐Ÿ“ค **Submit your solution**:
- `cargo compete submit abc317_a`

### ๐ŸŒŸ Yukicoder Support

This setup also supports solving problems from [yukicoder](https://yukicoder.me). Follow these steps to set up your environment and submit your solutions:

#### โš  Important Note: Differences in Execution Environments

The execution environments for AtCoder and yukicoder are different. While AtCoder allows the use of most Rust crates, yukicoder imposes stricter restrictions on the available crates. Before using a crate in your solution, ensure it is supported in yukicoder's environment. You can refer to yukicoder's [execution environment documentation](https://yukicoder.me/help/environments) for details.

#### ๐Ÿ“‹ Setting Up for Yukicoder

1. **Environment Variable**:
- If you'd like to use the Yukicoder API, set the following environment variable in `.devcontainer/.env`:

```bash
YUKICODER_API_KEY=your_api_key
```

- This key is optional but necessary if you're using features that rely on the Yukicoder API.

2. **Rebuild the Devcontainer**:
After setting the API key, rebuild the devcontainer for the changes to take effect:

```bash
Ctrl+Shift+P -> Dev Containers: Rebuild Container
```

#### โž• Adding Problems

To add a yukicoder problem, include `"yukicoder"` as the second argument when using the `add` command:

```bash
cargo compete add yukicoder
```

#### ๐Ÿ“ค Submission

Before submitting to yukicoder, update the `language_id` in the `[submit]` section of `compete.toml`. Replace the default value with `"rust"`:

```toml
[submit]
kind = "file"
path = "{{ src_path }}"
# language_id = "5054" # Rust 1.70.0
# language_id = "6088" # Rust 1.89.0
language_id = "rust" # for yukicoder
```

After updating `compete.toml`, you can submit the solution as usual:

```bash
cargo compete submit
```

## ๐Ÿ“œ License

This project is dual-licensed under MIT or Apache-2.0. For more details, see [LICENSE-MIT](LICENSE-MIT) and [LICENSE-APACHE](LICENSE-APACHE).