diff --git a/example/.gitignore b/example/.gitignore index 6782972..482683f 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -1,3 +1,5 @@ *.pyc venv/ -__pycache__/ \ No newline at end of file +__pycache__/ +*.out +*.class diff --git a/example/main.py b/example/main.py index 9fa84dc..ad8be8c 100644 --- a/example/main.py +++ b/example/main.py @@ -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__": diff --git a/example/rust/1000/in.txt b/example/rust/1000/in.txt new file mode 100644 index 0000000..e69de29 diff --git a/example/rust/1000/main.rs b/example/rust/1000/main.rs new file mode 100644 index 0000000..47ad8c6 --- /dev/null +++ b/example/rust/1000/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello World!"); +} diff --git a/example/rust/1000/out.txt b/example/rust/1000/out.txt new file mode 100644 index 0000000..c57eff5 --- /dev/null +++ b/example/rust/1000/out.txt @@ -0,0 +1 @@ +Hello World! \ No newline at end of file diff --git a/example/rust/1001/in.txt b/example/rust/1001/in.txt new file mode 100644 index 0000000..1ed0fb7 --- /dev/null +++ b/example/rust/1001/in.txt @@ -0,0 +1 @@ +2 3 \ No newline at end of file diff --git a/example/rust/1001/main.rs b/example/rust/1001/main.rs new file mode 100644 index 0000000..56f9665 --- /dev/null +++ b/example/rust/1001/main.rs @@ -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::()) + .map(|a| a.expect("parsed integer")) + .fold(0i32, |sum, a| sum + a); + + println!("{}", res); +} diff --git a/example/rust/1001/out.txt b/example/rust/1001/out.txt new file mode 100644 index 0000000..7813681 --- /dev/null +++ b/example/rust/1001/out.txt @@ -0,0 +1 @@ +5 \ No newline at end of file diff --git a/src/allow.rs b/src/allow.rs index ff49fb7..5657487 100644 --- a/src/allow.rs +++ b/src/allow.rs @@ -48,12 +48,15 @@ pub fn gen_rules() -> Vec { 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 { 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), diff --git a/src/judger.rs b/src/judger.rs index 6c7e8e9..972e5e6 100644 --- a/src/judger.rs +++ b/src/judger.rs @@ -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 {