cargo-xbuild icon indicating copy to clipboard operation
cargo-xbuild copied to clipboard

color option does not work

Open arjanmels opened this issue 5 years ago • 3 comments

The --color (never, always) does not work on xbuild (cargo-xbuild 0.5.28)

arjanmels avatar May 01 '20 08:05 arjanmels

Thanks for reporting! The reason that this doesn't properly work is that we do two cargo invocations behind the scenes. The first invocation is for building the sysroot crates (core, alloc, etc.), while the second invocation builds the actual project. We currently only pass given arguments to the second cargo invocation because you normally don't want to change the sysroot building command.

I think the best way to fix this would be to special-case the --color flag to also apply it to the sysroot build (but not other flags). We already do something similar for the --verbose flag, so it shouldn't be too difficult to add something like this. The relevant parts of the code for the --verbose flag are:

https://github.com/rust-osdev/cargo-xbuild/blob/10287ffc4af6d5b8b6e2eba60b42126c7520705c/src/sysroot.rs#L121-L123

https://github.com/rust-osdev/cargo-xbuild/blob/10287ffc4af6d5b8b6e2eba60b42126c7520705c/src/lib.rs#L154

https://github.com/rust-osdev/cargo-xbuild/blob/10287ffc4af6d5b8b6e2eba60b42126c7520705c/src/cli.rs#L106-L111 https://github.com/rust-osdev/cargo-xbuild/blob/10287ffc4af6d5b8b6e2eba60b42126c7520705c/src/cli.rs#L145-L147

Handling of the color flag could be added in a similar way. I don't have the time to implement this myself right now, but pull requests are welcome!


As a side node, have you tried to directly use cargo's new -Z build-std flag instead of cargo-xbuild. A simple way to try it out is to create an alias named x in a .cargo/config:

[alias]
x = "-Z build-std=core"

Now you should be able to run cargo x build instead of cargo xbuild. This should fix your --color problem since now you're using cargo directly.

phil-opp avatar May 06 '20 13:05 phil-opp

Thanks for the hints, will see if I find the time for a pull request.

~~I tried the build-std=core flag, but get an error during compile on "extern crate alloc;" in the linked_list_allocator lib.rs file.~~

I got the -Z option working by using -Z build-std=core,alloc.

arjanmels avatar May 08 '20 08:05 arjanmels

I got the -Z option working by using -Z build-std=core,alloc.

Sorry, I forgot about alloc.

phil-opp avatar May 08 '20 09:05 phil-opp