Skip to content

Commit 3f15271

Browse files
authored
Merge pull request #346 from qryxip/rust
Add Rust
2 parents 499f3d1 + 43a0c97 commit 3f15271

File tree

20 files changed

+1139
-0
lines changed

20 files changed

+1139
-0
lines changed

.github/workflows/verify.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,27 @@ jobs:
4545
- name: Install dependencies (Nim)
4646
run: sudo apt install nim
4747

48+
- name: Set up Rust (1.42.0)
49+
uses: actions-rs/toolchain@v1
50+
with:
51+
toolchain: 1.42.0-x86_64-unknown-linux-gnu
52+
default: true
53+
profile: minimal
54+
55+
# required by cargo-udeps
56+
- name: Set up Rust (nightly)
57+
uses: actions-rs/toolchain@v1
58+
with:
59+
toolchain: nightly-x86_64-unknown-linux-gnu
60+
default: true
61+
profile: minimal
62+
63+
# required only if you set `languages.rust.list_dependencies_backend.kind` to `"cargo-udeps"`
64+
- name: Install cargo-udeps for Rust
65+
uses: actions-rs/[email protected]
66+
with:
67+
crate: cargo-udeps
68+
use-tool-cache: true
4869

4970
- name: Run tests
5071
env:

.verify-helper/docs/static/document.ja.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
| Ruby | `.rb` | `.test.rb` | `# verification-helper: [KEY] [VALUE]` | :heavy_check_mark: / :x: / :warning: | [hello_world.test.rb](https://github.com/online-judge-tools/verification-helper/blob/master/examples/ruby/hello_world.test.rb) |
1717
| Go | `.go` | `.test.go` | `// verification-helper: [KEY] [VALUE]` | :heavy_check_mark: / :x: / :warning: | [helloworld.test.go](https://github.com/online-judge-tools/verification-helper/blob/master/examples/go/helloworld.test.go) |
1818
| Java | `.java` | `_test.java` | `// verification-helper: [KEY] [VALUE]` | :heavy_check_mark: / :x: / :warning: | [HelloWorld_test.java](https://github.com/online-judge-tools/verification-helper/blob/master/examples/java/HelloWorld_test.java) |
19+
| Rust | `.rs` | 特殊 | `// verification-helper: [KEY] [VALUE]` | :heavy_check_mark: / :x: / :warning: | [itp1-1-a.rs](https://github.com/online-judge-tools/verification-helper/blob/master/examples/rust/verification/src/bin/aizu-online-judge-itp1-1-a.rs) |
1920

2021
### C++ の設定
2122

@@ -59,6 +60,38 @@ NIMFLAGS = ["--warning:on", "--opt:none"]
5960

6061
設定項目は特にありません。
6162

63+
### Rust の設定
64+
65+
[binary ターゲット](https://doc.rust-lang.org/cargo/reference/cargo-targets.html#binaries)[example ターゲット](https://doc.rust-lang.org/cargo/reference/cargo-targets.html#examples) (ただし`crate-type`が指定されているのは除く) の [root source file](https://docs.rs/cargo_metadata/0.12.0/cargo_metadata/struct.Target.html#structfield.src_path) のうち、[`PROBLEM`](#利用可能な属性)が設定されてあるソースファイルがテストファイルだと認識されます。
66+
67+
依存ファイルを列挙する動作は `.verify-helper/config.toml``languages.rust.list_dependencies_backend` で変更できます。
68+
69+
- `kind = "none"`
70+
71+
デフォルトの動作です。
72+
73+
```toml
74+
[languages.rust.list_dependencies_backend]
75+
kind = "none"
76+
```
77+
78+
- あるターゲットの root source file であるならば、そのターゲット及びローカルにある依存クレートの、
79+
- どのターゲットの root source file でもなければ、自身を含むターゲットの、
80+
81+
`.rs`ファイルすべてを列挙して返します。
82+
83+
ターゲットに関連する `.rs` ファイルはすべてひとまとまりとして扱われ、「モジュール間の依存関係」等については調べません。
84+
85+
- `kind = "cargo-udeps"`
86+
87+
基本的に `kind = "none"` と同じですが、 `$PATH` 内にある [cargo-udeps](https://github.com/est31/cargo-udeps) を使い「パッケージからクレートへの依存」からさらに「クレート間の依存」を絞り込みます。
88+
89+
```toml
90+
[languages.rust.list_dependencies_backend]
91+
kind = "cargo-udeps"
92+
toolchain = "nightly-yyyy-mm-dd" # defaults to "nightly"
93+
```
94+
6295
### その他の言語の設定
6396

6497
上記以外の言語でも実行可能です (例: [examples/awk/circle.test.awk](https://github.com/online-judge-tools/verification-helper/blob/master/examples/awk/circle.test.awk))。

examples/rust/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/Cargo.lock
2+
/target/

examples/rust/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[workspace]
2+
members = ["verification/"]
3+
4+
[package]
5+
name = "verification-helper-rust-example"
6+
version = "0.0.0"
7+
edition = "2018"
8+
publish = false
9+
10+
[lib]
11+
name = "crate" # This crate itself is not intended to be used directly.
12+
13+
[dependencies]
14+
verification-helper-rust-example-hello = { path = "crates/helloworld/hello" }
15+
verification-helper-rust-example-input = { path = "crates/io/input" }
16+
verification-helper-rust-example-scanner = { path = "crates/io/scanner" }
17+
verification-helper-rust-example-world = { path = "crates/helloworld/world" }
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "verification-helper-rust-example-hello"
3+
version = "0.0.0"
4+
edition = "2018"
5+
publish = false
6+
7+
[lib]
8+
name = "hello"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//! Provides `"Hello"`.
2+
3+
pub static HELLO: &str = "Hello";
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "verification-helper-rust-example-world"
3+
version = "0.0.0"
4+
edition = "2018"
5+
publish = false
6+
7+
[lib]
8+
name = "world"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//! Provides `"World"`.
2+
3+
pub static WORLD: &str = "World";
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "verification-helper-rust-example-input"
3+
version = "0.1.0"
4+
authors = ["Ryo Yamashita <[email protected]>"]
5+
edition = "2018"
6+
7+
[lib]
8+
name = "input"
9+
10+
[dependencies]
11+
verification-helper-rust-example-scanner = { path = "../scanner" }
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//! A limited `input!` macro.
2+
//!
3+
//! ```no_run
4+
//! use input::input;
5+
//!
6+
//! input! {
7+
//! a: u32,
8+
//! b: u32,
9+
//! }
10+
//! ```
11+
12+
pub use scanner::Scanner;
13+
14+
/// A limited `input!` macro.
15+
#[macro_export]
16+
macro_rules! input {
17+
($($var:ident : $ty:ty),* $(,)?) => {
18+
let mut __scanner = $crate::Scanner::from_stdin();
19+
$(
20+
let $var = __scanner.read::<$ty>();
21+
)*
22+
};
23+
}

0 commit comments

Comments
 (0)