-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
runner script #53
runner script #53
Conversation
|
||
let args: Vec<String> = env::args().collect(); | ||
|
||
let mut ftxsgx_elf2sgxs_command = Command::new("ftxsgx-elf2sgxs"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can have a help option, which could mention something on the line of "ftxsgx-elf2sgxs, ftxsgx-runner etc." should be available in $PATH.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that's necessary. This tool will always be installed alongside those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how command::new works, would that require Command::new("./ftxsgx-elf2sgxs")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it will look up the commands in your path
Offline Review Comments: |
cd998fb
to
03cd031
Compare
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe I need to remove Cargo.lock
}); | ||
} | ||
|
||
process::exit(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unnecessary.
} | ||
None => { | ||
println!("{} is not defined in the environment.", key); | ||
process::exit(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not sure because in this case the sub-commands don't run, so they can't error out, and so parent process shouldn't have non-zero exit status. But I believe the inability to run the process also classifies as a error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not running anything is definitely an error, yes.
10b5cf2
to
dc68783
Compare
This PR can be reviewed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve error handling.
- Add at the top:
#[macro_use]
extern crate failure;
#[macro_use]
extern crate failure_derive;
use failure::{Error, ResultExt};
#[derive(Debug, Fail)]
enum CommandFail {
#[fail(display = "failed to run {}, {}", _0, _1)]
Io(String, io::Error),
#[fail(display = "while running {} got {}", _0, _1)]
Status(String, ExitStatus),
}
fn run_command(cmd: Command) -> Result<(), CommandFail> {
match cmd.status() {
Err(e) => Err(CommandFail::Io(format!("{:?}", cmd), e)),
Ok(status) if status.success() => Ok(()),
Ok(status) => Err(CommandFail::Status(format!("{:?}", cmd), status)),
}
}
- Move the code in
fn main()
into a new function:
fn run() -> Result<(), Error> {
...
Ok(())
}
- Replace the
match env::var_os(key)
block with:
let mut filepath = env::var_os(key)
.ok_or_else(|| format_err!("{} is not defined in the environment.", key))?;
-
Replace the first three occurences of
.expect(...)
by.context(...)?
. -
Replace the command execution blocks by
run_command(...)?
. -
New
fn main()
:
fn main() {
if let Err(e) = run() {
eprintln!("ERROR: {}", e);
process::exit(match e.downcast_ref::<CommandFail>() {
Some(CommandFail::Status(_, status)) => status.code().unwrap(),
_ => 1,
})
}
}
fortanix-sgx-tools/Cargo.toml
Outdated
@@ -26,3 +26,6 @@ sgx-isa = { version = "0.2.0-rc1", path = "../sgx-isa" } | |||
xmas-elf = "0.6.0" # Apache-2.0/MIT | |||
clap = "2.2.5" # MIT | |||
failure = "0.1.1" # MIT/Apache-2.0 | |||
serde_derive = "1.0.84" | |||
serde = "1.0.84" | |||
toml = "0.4.10" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add license info like for the other crates above.
use std::io::Read; | ||
use std::process::{self, Command}; | ||
|
||
const HEAP_SIZE: u32 = 0x20000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please increase default heap size
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to 32MB as per last discussion.
const HEAP_SIZE: u32 = 0x20000; | ||
const SSAFRAMESIZE: u32 = 1; | ||
const STACK_SIZE: u32 = 0x20000; | ||
const THREADS: u32 = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we set default number of threads based on num_cpus
crate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, done.
#[derive(Deserialize, Debug)] | ||
#[serde(rename_all = "kebab-case")] | ||
struct Target { | ||
heap_size: Option<u32>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be u64
.expect("Unable to execute ftxsgx-elf2sgxs"); | ||
|
||
if !ftxsgx_elf2sgxs_status.success() { | ||
println!("{:?}", ftxsgx_elf2sgxs_command); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat!
if debug { | ||
ftxsgx_elf2sgxs_command.arg("--debug"); | ||
} | ||
let mut ftxsgx_elf2sgxs_status = ftxsgx_elf2sgxs_command.status() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think mut
is necessary here? And you should get a lint for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it wasn't necessary, but wasn't getting any lint either.
|
||
let mut bin_with_ext = String::new(); | ||
bin_with_ext.push_str(&args[1]); | ||
bin_with_ext.push_str(".sgxs"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let bin_with_ext = args[1].clone() + ".sgxs";
dc68783
to
d430452
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great now. r=me after minor nits
fortanix-sgx-tools/Cargo.toml
Outdated
serde_derive = "1.0.84" # MIT/Apache-2.0 | ||
serde = "1.0.84" # MIT/Apache-2.0 | ||
toml = "0.4.10" # MIT/Apache-2.0 | ||
num_cpus = "1.9.0" # MIT/Apache-2.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing newline. Please configure your editor to automatically add a newline at the end of a file
let key = "CARGO_MANIFEST_DIR"; | ||
let mut filepath = env::var_os(key) | ||
.ok_or_else(|| format_err!("{} is not defined in the environment.", key))?; | ||
filepath.push(OsString::from("/Cargo.toml")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can just write filepath.push("/Cargo.toml");
d430452
to
96f2038
Compare
bors r=jethrogb |
👎 Rejected by code reviews |
bors r+ |
53: runner script r=jethrogb a=akash-fortanix This script encapsulates the three steps listed [here](#49) under `Running`. To trigger this script on `cargo run`, add .cargo/config file within crate with content: > [target.x86_64-fortanix-unknown-sgx] > runner = "ftxsgx-runner-cargo" And to set custom values for arguments to `ftxsgx-elf2sgxs` script, add `package.metadata` section in Cargo.toml > [package.metadata] > threads=15 Co-authored-by: akashfortanix <[email protected]>
Build succeeded
|
This script encapsulates the three steps listed here under
Running
.To trigger this script on
cargo run
, add .cargo/config file within crate with content:And to set custom values for arguments to
ftxsgx-elf2sgxs
script, addpackage.metadata
section in Cargo.toml