-
Notifications
You must be signed in to change notification settings - Fork 379
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
Read target architecture from cross-compiled binaries. #822
Conversation
I also removed the |
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 good!
why not run readelf
on the host?
xtask/src/readelf.rs
Outdated
println!("{{"); | ||
for (key, value) in lines { | ||
let value = value.trim_matches('"'); | ||
println!(" \"{key}\": \"{value}\"",); | ||
} | ||
println!("}}"); | ||
} |
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.
same spirit as #818, can you store this in a struct/serde_json::Value,
make the function return the struct and make the print in the readelf
function
xtask/src/readelf.rs
Outdated
|
||
if !verbose { | ||
// capture stderr to avoid polluting table | ||
command.stderr(Stdio::null()); | ||
} | ||
let stdout = command.run_and_get_stdout(verbose)?; | ||
let trimmed = stdout.trim(); | ||
if trimmed.is_empty() { | ||
eprintln!("no target information: target is likely same architecture as host."); |
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.
if !verbose { | |
// capture stderr to avoid polluting table | |
command.stderr(Stdio::null()); | |
} | |
let stdout = command.run_and_get_stdout(verbose)?; | |
let trimmed = stdout.trim(); | |
if trimmed.is_empty() { | |
eprintln!("no target information: target is likely same architecture as host."); | |
let out = command.run_and_get_output(verbose)?; | |
let stdout = out.stdout()?; | |
if stdout.trim().is_empty() { | |
let stderr = out.stderr()?; | |
if !stderr.trim().is_empty() { | |
if stderr.contains("target may not be installed") { | |
eprintln!("warning: target {target} is not installed"); | |
return Ok(()); | |
} else if !stderr.contains("Finished dev") { | |
eprintln!("{}", stderr.header("stderr")); | |
return Ok(()); | |
} | |
} | |
eprintln!("no target information: target `{target}` is likely same architecture as host."); | |
if verbose { | |
eprintln!("{}", stderr.header("stderr")); | |
} |
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.
uses color_eyre::SectionExt
to output it nicely
xtask/src/readelf.sh
Outdated
cargo init --bin hello >/dev/null | ||
cd hello | ||
cargo build --target "${TARGET}" "${@}" >/dev/null | ||
readelf -A "target/${TARGET}/debug/hello" |
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.
cargo init --bin hello >/dev/null | |
cd hello | |
cargo build --target "${TARGET}" "${@}" >/dev/null | |
readelf -A "target/${TARGET}/debug/hello" | |
cargo init --bin hello 1>&2 | |
cd hello | |
cargo build --target "${TARGET}" "${@}" 1>&2 | |
readelf -A "target/${TARGET}/debug/hello" |
xtask/src/util.rs
Outdated
if !verbose { | ||
// capture output to avoid polluting table | ||
command.stdout(Stdio::null()); | ||
command.stderr(Stdio::null()); | ||
} | ||
command.run(verbose, false).map_err(Into::into) |
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 know this is old but I think this should be changed to
if !verbose { | |
// capture output to avoid polluting table | |
command.stdout(Stdio::null()); | |
command.stderr(Stdio::null()); | |
} | |
command.run(verbose, false).map_err(Into::into) | |
let out = command.run_and_get_output(verbose)?; | |
command.status_result(verbose, out.status, Some(&out))?; | |
Ok(()) |
Use `readelf -A` on generated binaries to read the target architecture information and output the data as JSON, simplifying verifying that new targets produce code for the desired architecture. Closes cross-rs#821. Related to cross-rs#426.
This actually needs to install the target architecture via rustup if it's not present. |
yup, I don't know if maybe it makes sense to do it only when wanted, eg |
Actually this might be more difficult than I thought. MIPS is giving me some very weird data. Probably will close this. You can submit the other changes as a separate PR. |
824: Minor xtask restructuring. r=Emilgardis a=Alexhuszagh Remove the `-it` flag from `target-info`, which can the command to not complete. Also changes `pull_image` to use `run_and_get_output` rather than `run`, which is how we should capture the output. Finally, it moves `format_repo` and `pull_image` to `util`, so they can be used by other commands. This applies a few of the changes mentioned in #822. Co-authored-by: Alex Huszagh <ahuszagh@gmail.com>
Use
readelf -A
on generated binaries to read the target architecture information and output the data as JSON, simplifying verifying that new targets produce code for the desired architecture.Closes #821.
Related to #426.