Skip to content

Commit 485b1ae

Browse files
authored
fix(compile): fix compile error (#16)
1 parent 6d4a863 commit 485b1ae

File tree

10 files changed

+52
-13
lines changed

10 files changed

+52
-13
lines changed

.changes/compile.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eval-stack": patch:fix
3+
---
4+
5+
Fixed compile error caused some compiler don't recognize unknown file extension.

.changes/lang.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eval-stack": patch:fix
3+
---
4+
5+
Fixed `serde` renaming to `lowercase` instead of `camelCase`.

.changes/runtime.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eval-stack": patch:chore
3+
---
4+
5+
Specify the release profile in `Cargo.toml` to improve the performance.

.config/config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build]
2+
rustflags = ["-C", "target-cpu=native", "-Z", "threads=8"]

.cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"bitcode",
55
"chdir",
66
"chrono",
7+
"codegen",
78
"covector",
89
"fmax",
910
"getuid",

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,12 @@ futures = { version = "0.3.31", optional = true }
2626
default = ["engine"]
2727
engine = ["surrealdb", "serde", "chrono", "futures"]
2828
serde = ["dep:serde"]
29+
30+
[profile.release]
31+
lto = "fat"
32+
opt-level = 3
33+
debug = false
34+
debug-assertions = false
35+
overflow-checks = false
36+
panic = "abort"
37+
codegen-units = 1

rust-toolchain.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[toolchain]
2+
channel = "nightly"
3+
components = ["rustfmt", "clippy"]

src/compile.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
use std::{
2-
env,
3-
path::{Path, PathBuf},
4-
process::Stdio,
2+
env, ffi::OsStr, path::{Path, PathBuf}, process::Stdio
53
};
64

75
use anyhow::Result;
86
use tokio::{fs::File, io, process::Command};
97

108
#[derive(Default, Debug, Clone, Copy)]
119
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
12-
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
10+
#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
1311
pub enum Language {
1412
#[default]
1513
Rust,
@@ -98,13 +96,15 @@ pub async fn compile<B: Into<PathBuf>, S: Into<PathBuf>, O: AsRef<str>>(
9896
Some(command)
9997
}
10098
Language::Java => {
101-
let java_path = base_path.join("Main.java");
10299
let mut command = Command::new("javac");
103-
io::copy(
104-
&mut File::open(source_path_str.as_ref()).await?,
105-
&mut File::create(&java_path).await?,
106-
)
107-
.await?;
100+
let java_path = base_path.join("Main.java");
101+
if source_path.file_name() != Some(OsStr::new("Main.java")) {
102+
io::copy(
103+
&mut File::open(source_path_str.as_ref()).await?,
104+
&mut File::create(&java_path).await?,
105+
)
106+
.await?;
107+
}
108108
command.arg(java_path.to_string_lossy().as_ref());
109109
Some(command)
110110
}

src/engine/runtime.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use tokio::fs::File;
1212
use tokio::io::AsyncWriteExt;
1313

1414
use crate::case::run_test_cases;
15+
use crate::compile::Language;
1516
use crate::config::JudgeOptions;
1617
use crate::engine::models::Status;
1718
use crate::judge::{JudgeResult, JudgeStatus};
@@ -71,7 +72,15 @@ pub async fn handle_submission(
7172
create_dir_all(&workspace)?;
7273
}
7374

74-
let source_file_path = workspace.join("source.code");
75+
let source_file_path = workspace.join(match submission.lang {
76+
Language::C => "main.c",
77+
Language::CPP => "main.cpp",
78+
Language::Java => "Main.java",
79+
Language::Python => "main.py",
80+
Language::Rust => "main.rs",
81+
Language::NodeJs => "main.js",
82+
Language::Golang => "main.go",
83+
});
7584
let mut file = File::create(&source_file_path).await?;
7685
file.write_all(submission.code.as_bytes()).await?;
7786

0 commit comments

Comments
 (0)