- Notifications
You must be signed in to change notification settings - Fork 62
Add Rust #346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Rust #346
Changes from all commits
6ce7592 8f6c759 43e55ba 9e8a52f 2f6a531 ae99c7b b55759c ae69757 35ebfcb 9226ea5 7d7fec8 835d5dd 6016508 ffcc800 3c94d54 5f65a52 907ad4d ee5dcb3 007b15e 94c171a f9570de e0cadc8 7e3290d 9514528 5e5bf17 3807d5e ba00ec3 bfd3c2e eae8662 0bc062f 9373a77 aff6c7b 22a5042 aeaa747 18bb792 20cefe4 b448bc6 3cc03d8 5352b76 ffdf3be 4ce326e 050f1e2 99d0047 92bec30 c4e3257 d995ee7 fc56bee 95e89a3 589e4f3 d03321d c449e83 567f681 db5cbe2 3c24627 586c525 8c4adef 6e9fb98 4660a3a f7225ad 7639796 67beabc 1fa912a 0b8b583 f071111 8f50eec 2f3bc69 80dbb88 ad250ae 8c69e1b e598473 fa18b1d fa23b67 cf91456 eaf6cd0 4bfb9af e6475ff 019ec08 817375d dc179fa 92dd291 b917527 49668da e8313b7 1474439 d9f2675 3f264c2 9981c41 379e452 ee33de0 27f9fcb 7a6a213 6299607 337883c 9181364 84db367 68f5fa2 ee41c50 29a181e 497e81a 97bf2b5 443d415 bae159e 4e9a355 068c87e 0a454dc 8ea259c 052da00 20731a2 c649ca2 bb52cd7 1fcf031 43a0c97 File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| | @@ -45,6 +45,27 @@ jobs: | |||||||||||||||||||
| - name: Install dependencies (Nim) | ||||||||||||||||||||
| run: sudo apt install nim | ||||||||||||||||||||
| | ||||||||||||||||||||
| - name: Set up Rust (1.42.0) | ||||||||||||||||||||
| uses: actions-rs/toolchain@v1 | ||||||||||||||||||||
| with: | ||||||||||||||||||||
| toolchain: 1.42.0-x86_64-unknown-linux-gnu | ||||||||||||||||||||
| default: true | ||||||||||||||||||||
| profile: minimal | ||||||||||||||||||||
| | ||||||||||||||||||||
| # required by cargo-udeps | ||||||||||||||||||||
| - name: Set up Rust (nightly) | ||||||||||||||||||||
| uses: actions-rs/toolchain@v1 | ||||||||||||||||||||
| with: | ||||||||||||||||||||
| toolchain: nightly-x86_64-unknown-linux-gnu | ||||||||||||||||||||
| default: true | ||||||||||||||||||||
| profile: minimal | ||||||||||||||||||||
| | ||||||||||||||||||||
| # required only if you set `languages.rust.list_dependencies_backend.kind` to `"cargo-udeps"` | ||||||||||||||||||||
| - name: Install cargo-udeps for Rust | ||||||||||||||||||||
| uses: actions-rs/install@v0.1 | ||||||||||||||||||||
| with: | ||||||||||||||||||||
| crate: cargo-udeps | ||||||||||||||||||||
| use-tool-cache: true | ||||||||||||||||||||
qryxip marked this conversation as resolved. Show resolved Hide resolved Comment on lines +65 to +68 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kmyk actions-rs/installはunmaintainedだし、結局他に良い方法が思い浮かばなかったのでGitHub Releasesからダウンロードする方法に戻していいでしょうか。 ( Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @qryxip 戻した方がよさそうということならお願いします。このプルリクはもうマージしてしまったので、新しいプルリクを作ってください | ||||||||||||||||||||
| | ||||||||||||||||||||
| - name: Run tests | ||||||||||||||||||||
| env: | ||||||||||||||||||||
| | ||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -16,6 +16,7 @@ | |
| | 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) | | ||
| | 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) | | ||
| | 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) | | ||
| | 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) | | ||
| | ||
| ### C++ の設定 | ||
| | ||
| | @@ -59,6 +60,38 @@ NIMFLAGS = ["--warning:on", "--opt:none"] | |
| | ||
| 設定項目は特にありません。 | ||
| | ||
| ### Rust の設定 | ||
| | ||
| [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`](#利用可能な属性)が設定されてあるソースファイルがテストファイルだと認識されます。 | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
これのリンク先をもうすこし分かりやすいドキュメントで置き換えられませんか? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. うーん他に言及されているのだとこれの真ん中ら辺? /* Absolute path to the root source file of the target. */ "src_path": "/path/to/my-package/src/main.rs", | ||
| | ||
| 依存ファイルを列挙する動作は `.verify-helper/config.toml` の `languages.rust.list_dependencies_backend` で変更できます。 | ||
| | ||
| - `kind = "none"` | ||
| | ||
| デフォルトの動作です。 | ||
| | ||
| ```toml | ||
| [languages.rust.list_dependencies_backend] | ||
| kind = "none" | ||
| ``` | ||
| | ||
| - あるターゲットの root source file であるならば、そのターゲット及びローカルにある依存クレートの、 | ||
| - どのターゲットの root source file でもなければ、自身を含むターゲットの、 | ||
| | ||
| `.rs`ファイルすべてを列挙して返します。 | ||
| | ||
| ターゲットに関連する `.rs` ファイルはすべてひとまとまりとして扱われ、「モジュール間の依存関係」等については調べません。 | ||
| | ||
| - `kind = "cargo-udeps"` | ||
| | ||
| 基本的に `kind = "none"` と同じですが、 `$PATH` 内にある [cargo-udeps](https://github.com/est31/cargo-udeps) を使い「パッケージからクレートへの依存」からさらに「クレート間の依存」を絞り込みます。 | ||
| | ||
| ```toml | ||
| [languages.rust.list_dependencies_backend] | ||
| kind = "cargo-udeps" | ||
| toolchain = "nightly-yyyy-mm-dd" # defaults to "nightly" | ||
| ``` | ||
| | ||
| ### その他の言語の設定 | ||
| | ||
| 上記以外の言語でも実行可能です (例: [examples/awk/circle.test.awk](https://github.com/online-judge-tools/verification-helper/blob/master/examples/awk/circle.test.awk))。 | ||
| | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| /Cargo.lock | ||
| /target/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| [workspace] | ||
| members = ["verification/"] | ||
| | ||
| [package] | ||
| name = "verification-helper-rust-example" | ||
| version = "0.0.0" | ||
| edition = "2018" | ||
| publish = false | ||
| | ||
| [lib] | ||
| name = "crate" # This crate itself is not intended to be used directly. | ||
| | ||
| [dependencies] | ||
| verification-helper-rust-example-hello = { path = "crates/helloworld/hello" } | ||
| verification-helper-rust-example-input = { path = "crates/io/input" } | ||
| verification-helper-rust-example-scanner = { path = "crates/io/scanner" } | ||
| verification-helper-rust-example-world = { path = "crates/helloworld/world" } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| [package] | ||
| name = "verification-helper-rust-example-hello" | ||
| version = "0.0.0" | ||
| edition = "2018" | ||
| publish = false | ||
| | ||
| [lib] | ||
| name = "hello" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| //! Provides `"Hello"`. | ||
| | ||
| pub static HELLO: &str = "Hello"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| [package] | ||
| name = "verification-helper-rust-example-world" | ||
| version = "0.0.0" | ||
| edition = "2018" | ||
| publish = false | ||
| | ||
| [lib] | ||
| name = "world" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| //! Provides `"World"`. | ||
| | ||
| pub static WORLD: &str = "World"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| [package] | ||
| name = "verification-helper-rust-example-input" | ||
| version = "0.1.0" | ||
| authors = ["Ryo Yamashita <qryxip@gmail.com>"] | ||
| edition = "2018" | ||
| | ||
| [lib] | ||
| name = "input" | ||
| | ||
| [dependencies] | ||
| verification-helper-rust-example-scanner = { path = "../scanner" } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| //! A limited `input!` macro. | ||
| //! | ||
| //! ```no_run | ||
| //! use input::input; | ||
| //! | ||
| //! input! { | ||
| //! a: u32, | ||
| //! b: u32, | ||
| //! } | ||
| //! ``` | ||
| | ||
| pub use scanner::Scanner; | ||
| | ||
| /// A limited `input!` macro. | ||
| #[macro_export] | ||
| macro_rules! input { | ||
| ($($var:ident : $ty:ty),* $(,)?) => { | ||
| let mut __scanner = $crate::Scanner::from_stdin(); | ||
| $( | ||
| let $var = __scanner.read::<$ty>(); | ||
| )* | ||
| }; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| [package] | ||
| name = "verification-helper-rust-example-scanner" | ||
| version = "0.1.0" | ||
| authors = ["Ryo Yamashita <qryxip@gmail.com>"] | ||
| edition = "2018" | ||
| | ||
| [lib] | ||
| name = "scanner" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| //! A quite simple input scanner. | ||
| //! | ||
| //! ```no_run | ||
| //! use scanner::Scanner; | ||
| //! | ||
| //! let mut sc = Scanner::from_stdin(); | ||
| //! let _: u64 = sc.read(); | ||
| //! ``` | ||
| | ||
| use std::{ | ||
| any, fmt, | ||
| io::{self, Read as _}, | ||
| str::{FromStr, SplitAsciiWhitespace}, | ||
| }; | ||
| | ||
| /// A quite simple input scanner. | ||
| pub struct Scanner { | ||
| tokens: SplitAsciiWhitespace<'static>, | ||
| } | ||
| | ||
| impl Scanner { | ||
| /// Constructs a new `Self` with while input from stdin. | ||
| /// | ||
| /// # Panics | ||
| /// | ||
| /// Panics if an IO error occurred. | ||
| pub fn from_stdin() -> Self { | ||
| let mut input = "".to_owned(); | ||
| io::stdin().read_to_string(&mut input).unwrap(); | ||
| Self { | ||
| tokens: Box::leak(input.into_boxed_str()).split_ascii_whitespace(), | ||
| } | ||
| } | ||
| | ||
| /// Consumes and parses the next token. | ||
| /// | ||
| /// # Panics | ||
| /// | ||
| /// Panics if: | ||
| /// | ||
| /// - no token left | ||
| /// - failed to parse the token | ||
| pub fn read<T>(&mut self) -> T | ||
| where | ||
| T: FromStr, | ||
| T::Err: fmt::Display, | ||
| { | ||
| let token = self.tokens.next().expect("reached EOF"); | ||
| token.parse().unwrap_or_else(|err| { | ||
| panic!( | ||
| "could not parse {:?} as `{}`: {}", | ||
| token, | ||
| any::type_name::<T>(), | ||
| err, | ||
| ); | ||
| }) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 1.42.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| //! Re-exports the crates for rustdoc. | ||
| //! | ||
| //! This crate itself is not intended to be used directly. | ||
| | ||
| // With `custom-build` and `syn` crate, we can expand crate-level rustdocs. | ||
| | ||
| macro_rules! re_export(($($name:ident),* $(,)?) => ($(pub mod $name { pub use ::$name::*; })*)); | ||
| | ||
| pub mod helloworld { | ||
| //! Crates of "hello" and "world". | ||
| | ||
| re_export!(hello, world); | ||
| } | ||
| | ||
| pub mod io { | ||
| //! Crates about IO. | ||
| | ||
| re_export!(input, scanner); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| [package] | ||
| name = "verification" | ||
| version = "0.0.0" | ||
| edition = "2018" | ||
| publish = false | ||
| | ||
| [dependencies] | ||
| verification-helper-rust-example-hello = { path = "../crates/helloworld/hello" } | ||
| verification-helper-rust-example-input = { path = "../crates/io/input" } | ||
| verification-helper-rust-example-world = { path = "../crates/helloworld/world" } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| // verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_A | ||
| | ||
| fn main() { | ||
| println!("{} {}", hello::HELLO, world::WORLD); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // verification-helper: PROBLEM https://judge.yosupo.jp/problem/aplusb | ||
| | ||
| use input::input; | ||
| | ||
| fn main() { | ||
| input! { | ||
| a: u32, | ||
| b: u32, | ||
| } | ||
| | ||
| println!("{}", a + b); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cargo-udeps v0.16.0をリリースしたのでoj-verify-playgroundに空コミットしたところよくないことに...
毎日実行されていたactions-rs/tool-cacheのジョブが「60日間activity無し」によって20日ほど前に停止されていて、
0.15.0を明示的に指定しない限り4分近くかかるようになってしまいました (しかもこの場合1.42でcargo-udepsをビルドしようとして失敗してる)。というかactions-rs/install共々issue/prが結構放置されているような...https://github.com/qryxip/oj-verify-playground/runs/1432309559?check_suite_focus=true
インストール方法の代替を考えると
cargo install+ actions/cache.tar.gzをwgetしてtar xfの2つですがどっちにしても設定ファイルが膨らむ気がします。1.に至っては数時間試行錯誤してますがベストな方法がわからないです。