@@ -5,7 +5,9 @@ use std::os::unix::net::UnixStream;
5
5
use bincode:: { deserialize_from, serialize_into} ;
6
6
use log:: info;
7
7
8
- use crate :: sandbox:: { CrateType , Edition , ExecuteRequest , Mode , CompileRequest , CompileTarget , Channel } ;
8
+ use crate :: sandbox:: {
9
+ Channel , CompileRequest , CompileTarget , CrateType , Edition , ExecuteRequest , Mode ,
10
+ } ;
9
11
10
12
type JobBatch = Vec < worker_message:: Request > ;
11
13
@@ -35,16 +37,20 @@ fn compile_request_to_batch(req: CompileRequest) -> JobBatch {
35
37
)
36
38
. into ( ) ,
37
39
} ) ;
38
- let mut args = vec ! [ "rustc" ] ;
40
+ let mut args = if let Wasm = req. target {
41
+ vec ! [ "wasm" , "build" ]
42
+ } else {
43
+ vec ! [ "rustc" ]
44
+ } ;
39
45
if let Mode :: Release = req. mode {
40
46
args. push ( "--release" ) ;
41
47
}
42
- args . extend ( & [ "--" , "-o" , "/tmp/playground/compilation" ] ) ;
48
+ let output_path : & str = "/tmp/playground/compilation" ;
43
49
match req. target {
44
50
Assembly ( flavor, _, _) => {
45
51
use crate :: sandbox:: AssemblyFlavor :: * ;
46
52
47
- args. push ( "--emit= asm" ) ;
53
+ args. extend ( & [ "--" , "-- emit" , " asm=/tmp/playground/compilation" ] ) ;
48
54
49
55
// Enable extra assembly comments for nightly builds
50
56
if let Channel :: Nightly = req. channel {
@@ -58,10 +64,10 @@ fn compile_request_to_batch(req: CompileRequest) -> JobBatch {
58
64
Intel => args. push ( "llvm-args=-x86-asm-syntax=intel" ) ,
59
65
}
60
66
}
61
- LlvmIr => args. push ( "--emit= llvm-ir" ) ,
62
- Mir => args. push ( "--emit= mir" ) ,
63
- Hir => args. push ( "- Zunpretty=hir") ,
64
- Wasm => { panic ! ( "Wasm target not supported now" ) ; }
67
+ LlvmIr => args. extend ( & [ "--" , "-- emit" , " llvm-ir=/tmp/playground/compilation" ] ) ,
68
+ Mir => args. extend ( & [ "--" , "-- emit" , " mir=/tmp/playground/compilation" ] ) ,
69
+ Hir => args. extend ( & [ "--" , "- Zunpretty=hir", "-o" , output_path ] ) ,
70
+ Wasm => args . extend ( & [ "-o" , output_path ] ) ,
65
71
}
66
72
let mut envs = HashMap :: new ( ) ;
67
73
if req. backtrace {
@@ -77,7 +83,7 @@ fn compile_request_to_batch(req: CompileRequest) -> JobBatch {
77
83
cwd : "/tmp/playground" . to_owned ( ) ,
78
84
} ) ;
79
85
batch. push ( ReadFile {
80
- path : "/tmp/playground/compilation" . to_owned ( )
86
+ path : "/tmp/playground/compilation" . to_owned ( ) ,
81
87
} ) ;
82
88
batch
83
89
}
@@ -136,6 +142,7 @@ fn process_batch(stream: &mut UnixStream, batch: JobBatch) -> Option<worker_mess
136
142
let mut response = None ;
137
143
for job in batch {
138
144
let res = work ( stream, job) ;
145
+ dbg ! ( & res) ;
139
146
if !res. is_ok ( ) {
140
147
return Some ( res) ;
141
148
} else {
@@ -152,15 +159,17 @@ fn work(stream: &mut UnixStream, req: worker_message::Request) -> worker_message
152
159
153
160
#[ cfg( test) ]
154
161
mod tests {
162
+ use std:: io:: { Read , Write } ;
155
163
use std:: path:: Path ;
156
164
use std:: str:: from_utf8;
157
165
use std:: time:: SystemTime ;
158
166
use std:: { fs, os:: unix:: net:: UnixStream , thread, time:: Duration } ;
159
- use std:: io:: { Read , Write } ;
160
167
161
168
use crate :: {
162
- coordinator:: { execute_request_to_batch, compile_request_to_batch} ,
163
- sandbox:: { Channel , Edition , ExecuteRequest , Mode , CompileRequest , CompileTarget , CrateType } ,
169
+ coordinator:: { compile_request_to_batch, execute_request_to_batch} ,
170
+ sandbox:: {
171
+ Channel , CompileRequest , CompileTarget , CrateType , Edition , ExecuteRequest , Mode ,
172
+ } ,
164
173
} ;
165
174
use playground_worker;
166
175
@@ -191,7 +200,11 @@ mod tests {
191
200
}
192
201
193
202
fn generate_temporary_socket ( ) -> String {
194
- let timestamp = SystemTime :: now ( ) . duration_since ( SystemTime :: UNIX_EPOCH ) . unwrap ( ) . as_nanos ( ) . to_string ( ) ;
203
+ let timestamp = SystemTime :: now ( )
204
+ . duration_since ( SystemTime :: UNIX_EPOCH )
205
+ . unwrap ( )
206
+ . as_nanos ( )
207
+ . to_string ( ) ;
195
208
format ! ( "/tmp/playground_test_socket_{timestamp}" )
196
209
}
197
210
@@ -219,6 +232,7 @@ mod tests {
219
232
let batch = compile_request_to_batch ( request) ;
220
233
let result = process_batch ( & mut request_socket, batch) . unwrap ( ) ;
221
234
println ! ( "{result}" ) ;
235
+ assert ! ( result. is_ok( ) ) ;
222
236
}
223
237
224
238
#[ test]
@@ -254,6 +268,7 @@ mod tests {
254
268
}
255
269
} ) ;
256
270
println ! ( "{result}" ) ;
271
+ assert ! ( result. is_ok( ) ) ;
257
272
// handle.join().unwrap();
258
273
thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
259
274
}
0 commit comments