Skip to content

Commit a465dd2

Browse files
committed
fix compilation output filepath
1 parent 1746619 commit a465dd2

File tree

2 files changed

+54
-23
lines changed

2 files changed

+54
-23
lines changed

playground-worker/src/lib.rs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use std::fs;
44
use std::io::{Read, Write};
55
use std::os::unix::net::{UnixListener, UnixStream};
66
use std::path::Path;
7-
use std::process::Child;
87
use std::process::Command;
98
use std::process::Stdio;
9+
use std::process::{Child, Output};
1010
use std::str::from_utf8;
1111
use std::{io, thread};
1212
use worker_message::{ExecuteOutput, Pid, Request, Response};
@@ -45,20 +45,36 @@ fn handle_socket(request_stream: UnixStream, stdio_stream: UnixStream) {
4545
envs,
4646
cwd,
4747
} => {
48+
dbg!(&args);
4849
let result = Command::new(cmd)
4950
.args(args)
5051
.envs(envs)
5152
.current_dir(cwd)
5253
.output();
53-
let response = Response::ExecuteResult(
54-
result
55-
.map(|output| ExecuteOutput {
56-
status: output.status.code(),
57-
stderr: output.stderr,
58-
stdout: output.stdout,
59-
})
60-
.map_err(|e| e.to_string()),
61-
);
54+
let response = Response::ExecuteResult(match result {
55+
Ok(output) => {
56+
let Output {
57+
status,
58+
stderr,
59+
stdout,
60+
} = output;
61+
if status.success() {
62+
Ok(ExecuteOutput {
63+
status: status.code(),
64+
stderr,
65+
stdout,
66+
})
67+
} else {
68+
Err(format!(
69+
"exit_status: {:#?}, stderr: {}, stdout: {}",
70+
status.code(),
71+
std::str::from_utf8(&stderr).unwrap(),
72+
std::str::from_utf8(&stdout).unwrap()
73+
))
74+
}
75+
}
76+
Err(err) => Err(err.to_string()),
77+
});
6278
bincode::serialize_into(&request_stream, &response).unwrap();
6379
}
6480
Request::StreamCommand {

ui/src/coordinator.rs

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use std::os::unix::net::UnixStream;
55
use bincode::{deserialize_from, serialize_into};
66
use log::info;
77

8-
use crate::sandbox::{CrateType, Edition, ExecuteRequest, Mode, CompileRequest, CompileTarget, Channel};
8+
use crate::sandbox::{
9+
Channel, CompileRequest, CompileTarget, CrateType, Edition, ExecuteRequest, Mode,
10+
};
911

1012
type JobBatch = Vec<worker_message::Request>;
1113

@@ -35,16 +37,20 @@ fn compile_request_to_batch(req: CompileRequest) -> JobBatch {
3537
)
3638
.into(),
3739
});
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+
};
3945
if let Mode::Release = req.mode {
4046
args.push("--release");
4147
}
42-
args.extend(&["--", "-o", "/tmp/playground/compilation"]);
48+
let output_path: &str = "/tmp/playground/compilation";
4349
match req.target {
4450
Assembly(flavor, _, _) => {
4551
use crate::sandbox::AssemblyFlavor::*;
4652

47-
args.push("--emit=asm");
53+
args.extend(&["--", "--emit", "asm=/tmp/playground/compilation"]);
4854

4955
// Enable extra assembly comments for nightly builds
5056
if let Channel::Nightly = req.channel {
@@ -58,10 +64,10 @@ fn compile_request_to_batch(req: CompileRequest) -> JobBatch {
5864
Intel => args.push("llvm-args=-x86-asm-syntax=intel"),
5965
}
6066
}
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]),
6571
}
6672
let mut envs = HashMap::new();
6773
if req.backtrace {
@@ -77,7 +83,7 @@ fn compile_request_to_batch(req: CompileRequest) -> JobBatch {
7783
cwd: "/tmp/playground".to_owned(),
7884
});
7985
batch.push(ReadFile {
80-
path: "/tmp/playground/compilation".to_owned()
86+
path: "/tmp/playground/compilation".to_owned(),
8187
});
8288
batch
8389
}
@@ -136,6 +142,7 @@ fn process_batch(stream: &mut UnixStream, batch: JobBatch) -> Option<worker_mess
136142
let mut response = None;
137143
for job in batch {
138144
let res = work(stream, job);
145+
dbg!(&res);
139146
if !res.is_ok() {
140147
return Some(res);
141148
} else {
@@ -152,15 +159,17 @@ fn work(stream: &mut UnixStream, req: worker_message::Request) -> worker_message
152159

153160
#[cfg(test)]
154161
mod tests {
162+
use std::io::{Read, Write};
155163
use std::path::Path;
156164
use std::str::from_utf8;
157165
use std::time::SystemTime;
158166
use std::{fs, os::unix::net::UnixStream, thread, time::Duration};
159-
use std::io::{Read, Write};
160167

161168
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+
},
164173
};
165174
use playground_worker;
166175

@@ -191,7 +200,11 @@ mod tests {
191200
}
192201

193202
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();
195208
format!("/tmp/playground_test_socket_{timestamp}")
196209
}
197210

@@ -219,6 +232,7 @@ mod tests {
219232
let batch = compile_request_to_batch(request);
220233
let result = process_batch(&mut request_socket, batch).unwrap();
221234
println!("{result}");
235+
assert!(result.is_ok());
222236
}
223237

224238
#[test]
@@ -254,6 +268,7 @@ mod tests {
254268
}
255269
});
256270
println!("{result}");
271+
assert!(result.is_ok());
257272
// handle.join().unwrap();
258273
thread::sleep(Duration::from_secs(1));
259274
}

0 commit comments

Comments
 (0)