mirror of
https://github.com/MeiK2333/river.git
synced 2025-11-04 14:49:40 +08:00
add language: Rust
This commit is contained in:
parent
26d8727db7
commit
05986d6923
4
example/.gitignore
vendored
4
example/.gitignore
vendored
@ -1,3 +1,5 @@
|
||||
*.pyc
|
||||
venv/
|
||||
__pycache__/
|
||||
__pycache__/
|
||||
*.out
|
||||
*.class
|
||||
|
||||
@ -15,6 +15,8 @@ def judge(path, language):
|
||||
filename = "main.py"
|
||||
elif language == river_pb2.Java:
|
||||
filename = "Main.java"
|
||||
elif language == river_pb2.Rust:
|
||||
filename = "main.rs"
|
||||
with open(path.joinpath(filename), "rb") as fr:
|
||||
code = fr.read()
|
||||
with open(path.joinpath("in.txt"), "rb") as fr:
|
||||
@ -27,9 +29,6 @@ def judge(path, language):
|
||||
judge_type=river_pb2.Standard,
|
||||
compile_data=river_pb2.CompileData(code=code),
|
||||
)
|
||||
# if language == river_pb2.Java:
|
||||
# import time
|
||||
# time.sleep(1000)
|
||||
# judge
|
||||
yield river_pb2.JudgeRequest(
|
||||
language=language,
|
||||
@ -38,9 +37,6 @@ def judge(path, language):
|
||||
in_data=in_data, out_data=out_data, time_limit=10000, memory_limit=65535
|
||||
),
|
||||
)
|
||||
# if language == river_pb2.Java:
|
||||
# import time
|
||||
# time.sleep(1000)
|
||||
|
||||
|
||||
def run():
|
||||
@ -66,6 +62,11 @@ def run():
|
||||
for item in stub.Judge(judge(path, river_pb2.Python)):
|
||||
print(item)
|
||||
print(f"{path} 评测完成")
|
||||
for path in Path("rust").iterdir():
|
||||
print(f"开始评测 {path}")
|
||||
for item in stub.Judge(judge(path, river_pb2.Rust)):
|
||||
print(item)
|
||||
print(f"{path} 评测完成")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
0
example/rust/1000/in.txt
Normal file
0
example/rust/1000/in.txt
Normal file
3
example/rust/1000/main.rs
Normal file
3
example/rust/1000/main.rs
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println!("Hello World!");
|
||||
}
|
||||
1
example/rust/1000/out.txt
Normal file
1
example/rust/1000/out.txt
Normal file
@ -0,0 +1 @@
|
||||
Hello World!
|
||||
1
example/rust/1001/in.txt
Normal file
1
example/rust/1001/in.txt
Normal file
@ -0,0 +1 @@
|
||||
2 3
|
||||
15
example/rust/1001/main.rs
Normal file
15
example/rust/1001/main.rs
Normal file
@ -0,0 +1,15 @@
|
||||
use std::io;
|
||||
|
||||
fn main() {
|
||||
let mut input = String::new();
|
||||
|
||||
io::stdin().read_line(&mut input).expect("correct input");
|
||||
let res = input
|
||||
.trim()
|
||||
.split(' ')
|
||||
.map(|a| a.parse::<i32>())
|
||||
.map(|a| a.expect("parsed integer"))
|
||||
.fold(0i32, |sum, a| sum + a);
|
||||
|
||||
println!("{}", res);
|
||||
}
|
||||
1
example/rust/1001/out.txt
Normal file
1
example/rust/1001/out.txt
Normal file
@ -0,0 +1 @@
|
||||
5
|
||||
@ -48,12 +48,15 @@ pub fn gen_rules() -> Vec<SyscallRuleSet> {
|
||||
allow_syscall(libc::SYS_nanosleep),
|
||||
allow_syscall(libc::SYS_open),
|
||||
allow_syscall(libc::SYS_openat),
|
||||
allow_syscall(libc::SYS_pipe2),
|
||||
allow_syscall(libc::SYS_poll),
|
||||
allow_syscall(libc::SYS_prctl),
|
||||
allow_syscall(libc::SYS_pread64),
|
||||
allow_syscall(libc::SYS_prlimit64),
|
||||
allow_syscall(libc::SYS_read),
|
||||
allow_syscall(libc::SYS_readlink),
|
||||
allow_syscall(libc::SYS_rename),
|
||||
allow_syscall(libc::SYS_rmdir),
|
||||
allow_syscall(libc::SYS_rt_sigaction),
|
||||
allow_syscall(libc::SYS_rt_sigprocmask),
|
||||
allow_syscall(libc::SYS_rt_sigreturn),
|
||||
@ -67,7 +70,9 @@ pub fn gen_rules() -> Vec<SyscallRuleSet> {
|
||||
allow_syscall(libc::SYS_socket),
|
||||
allow_syscall(libc::SYS_socketpair),
|
||||
allow_syscall(libc::SYS_stat),
|
||||
allow_syscall(libc::SYS_statx),
|
||||
allow_syscall(libc::SYS_sysinfo),
|
||||
allow_syscall(libc::SYS_tgkill),
|
||||
allow_syscall(libc::SYS_umask),
|
||||
allow_syscall(libc::SYS_uname),
|
||||
allow_syscall(libc::SYS_unlink),
|
||||
|
||||
@ -152,6 +152,10 @@ pub async fn compile(
|
||||
if request.language == Language::Java as i32 {
|
||||
runner.memory_limit = -1;
|
||||
}
|
||||
if request.language == Language::Rust as i32 {
|
||||
// https://github.com/rust-lang/rust/issues/46345
|
||||
runner.memory_limit = -1;
|
||||
}
|
||||
let status = runner.await?;
|
||||
resp.set_process_status(&status);
|
||||
if status.exit_code != 0 || status.signal != 0 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user