rust-osdev / cargo-xbuild

Automatically cross-compiles the sysroot crates core, compiler_builtins, and alloc.
Apache License 2.0
258 stars 25 forks source link

Adds command xrustc #9

Closed qqwa closed 6 years ago

qqwa commented 6 years ago

Some options can only be passed to rustc with arguments e.g. --emit=link=path/exe. I'm not sure if it will break anything for others who would use cargo build instead of cargo rustc

phil-opp commented 6 years ago

Thanks for the PR! Support for cargo rustc building is something that we should definitely do.

I'm not sure if it will break anything for others who would use cargo build instead of cargo rustc

I don't know either. So how about adding a separate cargo xrustc executable that invokes cargo rustc? This would have the big advantage that we just need to remove an x when cargo becomes able to build the sysroot itself.

qqwa commented 6 years ago

Fine by me. I pushed a commit which splits it in two binaries. We probably want to move more stuff from the binaries to the lib. And minimize the imports, currently it's for all the same, just that the binaries also include xargo_lib.

qqwa commented 6 years ago

I left the main as it was, because its only error handling, which shouldn't change that much anyways.

And the help text for cargo xrustc will use the same as cargo xbuild. Should i add new one for xrustc or can we use something with !format?

qqwa commented 6 years ago

This would work to show the correct command name.

pub fn main() {
    fn show_backtrace() -> bool {
        env::var("RUST_BACKTRACE").as_ref().map(|s| &s[..]) == Ok("1")
    }

match xargo_lib::run("xrustc", &format!(include_str!("help.txt"), "xrustc"), true) {

Or inside the run function, something like this:

pub fn run(command_name: &str, help: &str, use_rustc: bool) -> Result<Option<ExitStatus>> {
    use cli::Command;

    let (command, args) = cli::args(command_name)?;
    match command {
        Command::Build => Ok(Some(build(args, use_rustc)?)),
        Command::Help => {
            print!("{}", help.replace("{command_name}", command_name);
            Ok(None)
        }
phil-opp commented 6 years ago

Thanks for the update!

I would like to move the main function to the lib too, e.g. as main_common(command_name: &str), because maybe we want to change the error handling. And it's an easy way to avoid the code duplication.

It would be cool to use a common help.txt, but note that we would also need to replace the cargo build instances in the text.

qqwa commented 6 years ago

I also removed the use_rustc bool and just pass the command name to cargo.

The help message should now also be correct for any command.

PS: I can squash the commits before you merge it.

phil-opp commented 6 years ago

@qqwa Could you also update the title of this PR?

qqwa commented 6 years ago

You can squash it^^

phil-opp commented 6 years ago

Thanks a lot!

phil-opp commented 6 years ago

Released as version 0.4.8