Skip to content

Commit

Permalink
fix(compile): fix compile error (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
fu050409 authored Dec 4, 2024
1 parent 6d4a863 commit 485b1ae
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changes/compile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eval-stack": patch:fix
---

Fixed compile error caused some compiler don't recognize unknown file extension.
5 changes: 5 additions & 0 deletions .changes/lang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eval-stack": patch:fix
---

Fixed `serde` renaming to `lowercase` instead of `camelCase`.
5 changes: 5 additions & 0 deletions .changes/runtime.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eval-stack": patch:chore
---

Specify the release profile in `Cargo.toml` to improve the performance.
2 changes: 2 additions & 0 deletions .config/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
rustflags = ["-C", "target-cpu=native", "-Z", "threads=8"]
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"bitcode",
"chdir",
"chrono",
"codegen",
"covector",
"fmax",
"getuid",
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,12 @@ futures = { version = "0.3.31", optional = true }
default = ["engine"]
engine = ["surrealdb", "serde", "chrono", "futures"]
serde = ["dep:serde"]

[profile.release]
lto = "fat"
opt-level = 3
debug = false
debug-assertions = false
overflow-checks = false
panic = "abort"
codegen-units = 1
3 changes: 3 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "nightly"
components = ["rustfmt", "clippy"]
20 changes: 10 additions & 10 deletions src/compile.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use std::{
env,
path::{Path, PathBuf},
process::Stdio,
env, ffi::OsStr, path::{Path, PathBuf}, process::Stdio
};

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

#[derive(Default, Debug, Clone, Copy)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
pub enum Language {
#[default]
Rust,
Expand Down Expand Up @@ -98,13 +96,15 @@ pub async fn compile<B: Into<PathBuf>, S: Into<PathBuf>, O: AsRef<str>>(
Some(command)
}
Language::Java => {
let java_path = base_path.join("Main.java");
let mut command = Command::new("javac");
io::copy(
&mut File::open(source_path_str.as_ref()).await?,
&mut File::create(&java_path).await?,
)
.await?;
let java_path = base_path.join("Main.java");
if source_path.file_name() != Some(OsStr::new("Main.java")) {
io::copy(
&mut File::open(source_path_str.as_ref()).await?,
&mut File::create(&java_path).await?,
)
.await?;
}
command.arg(java_path.to_string_lossy().as_ref());
Some(command)
}
Expand Down
11 changes: 10 additions & 1 deletion src/engine/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use tokio::fs::File;
use tokio::io::AsyncWriteExt;

use crate::case::run_test_cases;
use crate::compile::Language;
use crate::config::JudgeOptions;
use crate::engine::models::Status;
use crate::judge::{JudgeResult, JudgeStatus};
Expand Down Expand Up @@ -71,7 +72,15 @@ pub async fn handle_submission(
create_dir_all(&workspace)?;
}

let source_file_path = workspace.join("source.code");
let source_file_path = workspace.join(match submission.lang {
Language::C => "main.c",
Language::CPP => "main.cpp",
Language::Java => "Main.java",
Language::Python => "main.py",
Language::Rust => "main.rs",
Language::NodeJs => "main.js",
Language::Golang => "main.go",
});
let mut file = File::create(&source_file_path).await?;
file.write_all(submission.code.as_bytes()).await?;

Expand Down

0 comments on commit 485b1ae

Please sign in to comment.