@@ -5,27 +5,30 @@ use std::{
5
5
} ;
6
6
7
7
use anyhow:: Result ;
8
- use tokio:: process:: Command ;
8
+ use tokio:: { fs :: File , io , process:: Command } ;
9
9
10
- #[ derive( Clone , Copy ) ]
10
+ #[ derive( Default , Debug , Clone , Copy ) ]
11
11
#[ cfg_attr( feature = "serde" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
12
12
#[ cfg_attr( feature = "serde" , serde( rename_all = "snake_case" ) ) ]
13
13
pub enum Language {
14
+ #[ default]
15
+ Rust ,
14
16
C ,
15
17
CPP ,
16
- Rust ,
17
18
Python ,
18
19
NodeJs ,
20
+ Golang ,
21
+ Java ,
19
22
}
20
23
21
- pub async fn compile < B : Into < PathBuf > , E : AsRef < str > , O : AsRef < str > > (
24
+ pub async fn compile < B : Into < PathBuf > , S : Into < PathBuf > , O : AsRef < str > > (
22
25
language : Language ,
23
26
base : B ,
24
- source_file : E ,
27
+ source_file_path : S ,
25
28
output_file : O ,
26
29
) -> Result < ( ) > {
27
30
let base_path = Into :: < PathBuf > :: into ( base) ;
28
- let source_path = base_path . join ( source_file . as_ref ( ) ) ;
31
+ let source_path = Into :: < PathBuf > :: into ( source_file_path ) ;
29
32
let source_path_str = source_path. to_string_lossy ( ) ;
30
33
let output_path = base_path. join ( output_file. as_ref ( ) ) ;
31
34
let output_path_str = output_path. to_string_lossy ( ) ;
@@ -84,6 +87,27 @@ pub async fn compile<B: Into<PathBuf>, E: AsRef<str>, O: AsRef<str>>(
84
87
Some ( command)
85
88
}
86
89
Language :: NodeJs => None ,
90
+ Language :: Golang => {
91
+ let mut command = Command :: new ( "go" ) ;
92
+ command. args ( [
93
+ "build" ,
94
+ "-o" ,
95
+ output_path_str. as_ref ( ) ,
96
+ source_path_str. as_ref ( ) ,
97
+ ] ) ;
98
+ Some ( command)
99
+ }
100
+ Language :: Java => {
101
+ let java_path = base_path. join ( "Main.java" ) ;
102
+ 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 ?;
108
+ command. arg ( java_path. to_string_lossy ( ) . as_ref ( ) ) ;
109
+ Some ( command)
110
+ }
87
111
} ;
88
112
89
113
if let Some ( mut command) = command {
0 commit comments