Skip to content

Commit 5867664

Browse files
authored
feat: support nodejs (#9)
* feat: support nodejs * chore: remove useless code
1 parent beaba06 commit 5867664

23 files changed

+555
-131
lines changed

.changes/nodejs.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"eval-stack": minor:feat
3+
---
4+
5+
Add support for Deno.js, and other changes:
6+
7+
- Use deno instead of node for executing JavaScript files, deny all permissions by default.
8+
- Allow stderr to be piped since we can capture it for error messages.
9+
- Disable core dumps by default.
10+
- Set CPU time limits using `libc`.
11+
- Use seccomp to restrict sys calls and fs operations.
12+
- Prevent process to create subprocesses.

.cspell.json

+3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
"NEWNS",
1111
"prctl",
1212
"PRIVS",
13+
"pycache",
1314
"rlim",
1415
"rlimit",
1516
"rustc",
1617
"rustup",
18+
"seccomp",
19+
"seccompiler",
1720
"serde",
1821
"setrlimit",
1922
"SIGBUS",

Cargo.lock

+86-39
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ anyhow = "1.0.92"
1515
libc = "0.2.161"
1616
tokio = { version = "1.41.0", features = ["full"] }
1717

18-
nix = { version = "0.29.0", features = ["user"], optional = true }
1918
serde = { version = "1.0.215", features = ["derive"], optional = true }
19+
seccompiler = "0.4.0"
20+
which = "7.0.0"
2021

2122
[features]
2223
default = ["serde"]
23-
rerun = ["nix"]
2424
serde = ["dep:serde"]

src/case.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{fs::create_dir_all, path::PathBuf, time::Duration};
22

33
use anyhow::Result;
4+
use which::which;
45

56
use crate::{
67
compile::{compile, Language},
@@ -31,7 +32,8 @@ where
3132
.to_string_lossy()
3233
.to_string();
3334
let exec_path = match &language {
34-
Language::Python => PathBuf::from("python"),
35+
Language::Python => which("python")?,
36+
Language::NodeJs => which("deno")?,
3537
_ => workspace.join("out"),
3638
};
3739

@@ -52,9 +54,20 @@ where
5254
}]);
5355
};
5456

55-
let args = vec![source_file_path.as_str()];
57+
let py_args = vec![source_file_path.as_str()];
58+
let deno_args = vec![
59+
"run",
60+
format!("--v8-flags=--max-old-space-size={}", options.memory_limit).leak(),
61+
"--deny-read=*",
62+
"--deny-write=*",
63+
"--deny-env=*",
64+
"--deny-run=*",
65+
"--deny-ffi=*",
66+
source_file_path.as_str(),
67+
];
5668
let args = match language {
57-
Language::Python => Some(&args),
69+
Language::Python => Some(&py_args),
70+
Language::NodeJs => Some(&deno_args),
5871
_ => None,
5972
}
6073
.map(|v| &**v);
@@ -73,7 +86,7 @@ where
7386
workspace.join("test.out"),
7487
)
7588
.await?;
76-
if options.fast_fail && !matches!(result.status, JudgeStatus::Accepted) {
89+
if options.fail_fast && !matches!(result.status, JudgeStatus::Accepted) {
7790
results.push(result);
7891
break;
7992
}

0 commit comments

Comments
 (0)