From 485b1ae3b129d439b657f98e1eabaa0f5f13e652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=90=91=E5=A4=9C?= <46275354+fu050409@users.noreply.github.com> Date: Wed, 4 Dec 2024 08:03:25 +0800 Subject: [PATCH] fix(compile): fix compile error (#16) --- .changes/compile.md | 5 +++++ .changes/lang.md | 5 +++++ .changes/runtime.md | 5 +++++ .config/config.toml | 2 ++ .cspell.json | 1 + Cargo.lock | 4 ++-- Cargo.toml | 9 +++++++++ rust-toolchain.toml | 3 +++ src/compile.rs | 20 ++++++++++---------- src/engine/runtime.rs | 11 ++++++++++- 10 files changed, 52 insertions(+), 13 deletions(-) create mode 100644 .changes/compile.md create mode 100644 .changes/lang.md create mode 100644 .changes/runtime.md create mode 100644 .config/config.toml create mode 100644 rust-toolchain.toml diff --git a/.changes/compile.md b/.changes/compile.md new file mode 100644 index 0000000..e057500 --- /dev/null +++ b/.changes/compile.md @@ -0,0 +1,5 @@ +--- +"eval-stack": patch:fix +--- + +Fixed compile error caused some compiler don't recognize unknown file extension. diff --git a/.changes/lang.md b/.changes/lang.md new file mode 100644 index 0000000..2f8ad22 --- /dev/null +++ b/.changes/lang.md @@ -0,0 +1,5 @@ +--- +"eval-stack": patch:fix +--- + +Fixed `serde` renaming to `lowercase` instead of `camelCase`. diff --git a/.changes/runtime.md b/.changes/runtime.md new file mode 100644 index 0000000..1221178 --- /dev/null +++ b/.changes/runtime.md @@ -0,0 +1,5 @@ +--- +"eval-stack": patch:chore +--- + +Specify the release profile in `Cargo.toml` to improve the performance. diff --git a/.config/config.toml b/.config/config.toml new file mode 100644 index 0000000..bdd49ff --- /dev/null +++ b/.config/config.toml @@ -0,0 +1,2 @@ +[build] +rustflags = ["-C", "target-cpu=native", "-Z", "threads=8"] diff --git a/.cspell.json b/.cspell.json index f4c8dae..26c92e4 100644 --- a/.cspell.json +++ b/.cspell.json @@ -4,6 +4,7 @@ "bitcode", "chdir", "chrono", + "codegen", "covector", "fmax", "getuid", diff --git a/Cargo.lock b/Cargo.lock index 618856c..6852dce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "Inflector" @@ -922,7 +922,7 @@ dependencies = [ [[package]] name = "eval-stack" -version = "0.2.1" +version = "0.3.0" dependencies = [ "anyhow", "chrono", diff --git a/Cargo.toml b/Cargo.toml index f97e7cb..9cdeae3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..8e275b7 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "nightly" +components = ["rustfmt", "clippy"] diff --git a/src/compile.rs b/src/compile.rs index a14ac18..b7e7102 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -1,7 +1,5 @@ use std::{ - env, - path::{Path, PathBuf}, - process::Stdio, + env, ffi::OsStr, path::{Path, PathBuf}, process::Stdio }; use anyhow::Result; @@ -9,7 +7,7 @@ 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, @@ -98,13 +96,15 @@ pub async fn compile, S: Into, O: AsRef>( 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) } diff --git a/src/engine/runtime.rs b/src/engine/runtime.rs index f05d85d..6d9768c 100644 --- a/src/engine/runtime.rs +++ b/src/engine/runtime.rs @@ -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}; @@ -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?;