axodotdev / cargo-dist

📦 shippable application packaging
https://axodotdev.github.io/cargo-dist/
Apache License 2.0
1.51k stars 72 forks source link

Enable cross compiling on non Rustup systems #621

Open benwis opened 11 months ago

benwis commented 11 months ago

I and a lot of NixOs users, use rust-overlay(or fenix) to manage the installed rust toolchain, selecting and installing targets and Rust versions in our flake.nix or similiar files.

I wanted to test the musl build for our project via cargo-dist, so I did cargo dist build and got this warning:

 WARN You're trying to cross-compile for musl from glibc, but I can't find rustup to ensure you have the rust toolchains for it!

and it only built for the current target. Can we widen that check to not use rustup, perhaps by checking for installed targets as cargo does?

Gankra commented 11 months ago

Asking some rust toolchain experts what the Correct approach is

Gankra commented 11 months ago

Context for what's up here:

cargo dist is functionally serving as a replacement for cargo build that handles far more setup details for you. One of those details is trying to smooth over Simple cross compilations by detecting you have rustup installed and running rustup target add SOME_NON_HOST_TARGET.

If rustup isn't present we currently refuse to proceed with building a non-host target, absent a way to prove that it's setup (me being overly conservative). We can just remove that restriction and let you blow yourself up with an opaque lower-level error in non-rustup setups, but, it would be nice if there was a way to query what targets are properly setup.

Because cargo dist is invoked as a subcommand, the only env-var we have access to is $CARGO (but we're tolerant of even not having that, because people really like invoking cargo subcommands as not subcommands sigh).


So at the end of the day if I'm being 100% "responsible" I only have access to "the ability to opaquely invoke cargo" (not even rustc). This means I need a way to do one of the following, which I can't seem to find:


I have considered the following options:

Gankra commented 11 months ago

more refined can-do-it-today approach (approved by upstream toolchain criminals):

Gankra commented 11 months ago

correction, instead of fucking with sysroot:

Gankra commented 11 months ago

So all of the above is still correct and worth doing but just to clarify the issue the OP actually ran into:

These warnings are overzealous, we should probably do something like supress them if --artifacts=all is set.

benwis commented 11 months ago

Appreciate you taking the time to dive into this, we've been loving cargo-dist