LoginSignup
0
0

More than 1 year has passed since last update.

VSCode serverを使って任意環境からブラウザ上でRust競プロ(+闇の力)をする

Last updated at Posted at 2023-02-10

TL;DR

  • Dellのシンクライアント上にProxmoxをインストールし、Ubuntu 22.04.1の仮想マシンを作った。
    • 仮想マシンの環境構築はこの記事の対象ではない
    • i5 6500Tの内2コア、8GB RAM、50GB SSDを割り当てた。
    • この仮想環境上にRustとvscode serverをインストールした。
    • vscode serverのtunnel機能を使うことで、ポートを手動で開けることなく、外部からRust環境にアクセスすることができるようになった。
    • 外部環境からはtunnelのリンクをブラウザで開き、githubのアカウントを使い認証するだけでつなぐことができる。
      • 信用できない場所からアクセスする場合はgithubアカウントはダミーのものを作ることを推奨
    • Rust環境はWindows上にも構築することができるが、闇の力(Linux用にコンパイルしてバイナリ提出をすること)はDockerその他が必要になり、かなり面倒である
      • 闇の力はAtcoderの古いRustバージョンとライブラリに縛られないので、本質的ではない制約に苦しめられずに開発ができる
      • AOJは文字数制限があって闇の力は使えなかった

初めに

ubuntu上でのコマンド

依存関係のインストール

sudo apt install curl ca-certificates gnupg lsb-release upx build-essential libssl-dev pkg-config

Rustupのインストール

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

ここでシェルを再起動(ターミナルを閉じてまた開く)

cargo-atcoderをインストール

cargo install cargo-atcoder
cargo atcoder login
  • atcoderアカウントでログインする

.tomlファイルを以下のように書き換える

nano $HOME/.config/cargo-atcoder.toml
[atcoder]
submit_via_binary = true  # submit via binary by default
use_cross = true          # use `cross` instead of `cargo` when g
enerating binaries
binary_column = 80        # maximum column number of generated bi
nary (0 for no wrapping)
update_interval = 1000    # interval time of fetching result (ms)
strip_path = "strip"      # specify `strip` command path. NOTE: if you use macOS, you have to install GNU strip and specify its path here.

[profile]
# target to use to generate binary
target = "x86_64-unknown-linux-musl"

[profile.release]
lto = true
panic = 'abort'

# dependencies added to new project
[dependencies]
proconio = "*"
# competitive = { git = "https://github.com/tanakh/competitive-rs.git" }

[project]
# to create `rust-toolchain` file, uncomment this line.
# rustc_version = "1.15.1"

# source code template
template = """
#[allow(unused_imports)]
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused)]
fn main() {
    input! {
        n: usize,
        k: i64,
        p: [i64; n],
        s: Bytes,
    }
    println!("{}", "");
}
"""
  • 詳しい設定の仕方はcargo-atcoderの記事を見ること

cargo-atcoderのテスト

cargo install cross
mkdir atcoder
cd atcoder
cargo atcoder new abc100
cd abc100
  • 詳しい使い方はcargo-atcoderの記事を見ること

vscode serverのインストール

sudo apt install software-properties-common apt-transport-https wget -y
wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main"
sudo apt install code
code tunnel --accept-server-license-terms --no-sleep
  • ターミナル上にウェブサイトのアドレスが出るため、それをクリックし、認証する
  • 認証後、vscode.dev/tunnel/??というリンクが表示される。これをメモする。アクセスしたのちに、認証した時と同じgithubアカウントにログインするとリモート開発環境を利用することができる。
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0