-
Notifications
You must be signed in to change notification settings - Fork 381
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
cross picking up wrong target options in cargos config.toml #621
Comments
We shouldn't currently use that at all, instead you'd have to place the config in perhaps we should support this automatically, but currently you should be able to workaround it by mounting the |
Note that that feature is currently unreleased, you'd have to install from git
|
Thing is, I don't want cross to pick that file up at all. It currently contains only configuration related to my host machine and target. But when compiling with cross on x86_64 for target aarch64, it picks up the options for the x86_64 target. |
Thank you so much for this issue, as this was driving me up the wall why my cross compiling was failing. I'm a little confused as to why it was happening though. I was compiling a simple program, and it would compile until I added "libc" as a dependency. The failure was:
This would happen because my ~/.cargo/config.toml contained:
The confusing thing to me is that I'm targetting Anyway, this was surprising to me here and I agree with @oliverbestmann. |
Any update on this @Emilgardis? The issue still exists in 7599e1a. cross still tries to use the target configuration of the host system, not the actual cross target system. |
I'll try to get in a fix for this. Not sure exactly what is happening but have an idea how to solve it. |
Just wanted to post an issue on this exact behavior. Any progress on it? |
I'd forgotten about this, this can be solved by us setting |
I'm working on this now, since I'm also trying to support aliases. A simple solution is the one above, while also parsing the aliases (which we would have to do anyway). The complex solution, which I want to support, is below: However, this would require using |
I tried the environment variable solution, but if the I tried |
It does seem that way. For now I'm just renaming the config with a script. A pity though, an env variable fix would be less cumber some. Thanks for the fast feedback, I wasn't completely sure if that was the correct linker. |
Trying to find the best solution right now, and sorry for the convenience. Working on a few issues but this is pretty high on my priority list. |
This is correct, however you need to forward it to the container @sadilekivan so in [target.aarch64-unknown-linux-gnu.env]
passthrough = ["CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc"] |
That should be handled automatically though from the latest main as of #869. This was not in v0.2.2 though. You can use the |
Yes, the flag does pass, as I mentioned earlier if I specify a non-existing linker like
I tried this, the flag gets passed too, but it still prioritizes |
Ah sorry, that's the default behavior of Cargo itself (although I believe it's [undocumented[(https://doc.rust-lang.org/cargo/reference/config.html#target), and not of |
So this is a breaking change no matter how we look at it: some programs likely rely on cargo's The behavior you desire, to ignore all This would likely be done with the
In case we can't restore the files (say, via a |
I'm unsure of how cross is exactly implemented with cargo, but I would expect that cross has the ability to read CLI arguments and act based upon them. I imagine that CLI arguments should be prioritized over config variables. So that |
The problem is we mount both So the issue is not how |
By playing around I tried to understand this issue and thought I'd post this description of it. The
|
It does, but |
Edit: Nevermind the original issue did. |
That we can very easily support (as in, skipping it). This is because the cargo subdirectory of the project won't be used for anything else (unless it's cargo's home, in which case we need to mount it), and Docker has ways of preventing subdirectories from being mounted. To do so, you mount an anonymous data volume at the resulting path, and it prevents the data in bind mount (the volume being mounted on the host) at that subdirectory from being mounted. We actually do this already in cross, for example, to prevent the binaries in cargo home from being mounted. |
It's also probably worth noting that renaming the file is less iffy than it might appear: |
do we need to mount with write? |
I don't think so, since we'd either need a data volume (guaranteed to be correctly but costly, and we could simply remove the config files after copying), or we can handle it outside the container (in which case, we don't need write permissions). Also, the data volume would require setup and shutdown like our remote logic which I think we should avoid as long as we can. |
I think the correct thing to do is to do this upstream in cargo. If it's not something in scope for cargo, maybe then we can consider supporting this in a "hacky" way. (I don't think renaming on host is a good solution, since then you'd probably break some simultaneous compilation where a specific config is expected to be present. rust-lang/cargo#6728 seems like a possible fix rust-lang/cargo#5416 seems to be the issue at hand |
Since both would be breaking changes, so it might take a deprecation period. But yeah, I don't want renaming on the host unless it can be done as opt-in behavior, with clear implications of what that means. Actually, this might have been solved by rust-lang/cargo#6699, which I didn't see. I wonder... let me check (ah it's unstable). |
|
We've got a working solution in #931 which once rebased will support both ignoring all configurations outside of [build.env]
# This can be "complete", "default", or "ignore".
cargo-config = "complete" |
Which cargo-config should I use in this case? |
For users of Create # This avoids cross picking up custom linker from ~/.cargo/config.toml
# See: https://github.com/cross-rs/cross/issues/621
[build.env]
passthrough = [
"CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-linux-gnu-gcc",
"RUSTFLAGS",
] Invoke RUSTFLAGS="" cross build --target x86_64-unknown-linux-gnu --release |
I work around this by renaming my cargo config and renaming back when cross is finished
Sincerely,
Jack
…On 5 Jan 2023 at 8:24 AM +0800, Sergii Mikhtoniuk ***@***.***>, wrote:
For users of mold here's an ugly workaround that worked for me:
Create Cross.toml file:
# This avoids cross picking up custom linker from ~/.cargo/config.toml
# See: #621
[build.env]
passthrough = [
"CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-linux-gnu-gcc",
"RUSTFLAGS",
]
Invoke cross as:
RUSTFLAGS="" cross build --target x86_64-unknown-linux-gnu --release
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
I'm on an x86_64 Arch Linux using I tried #621 (comment) but didn't mange to get it to work. The mold "How to use" section mentioned newer versions of My [target.x86_64-unknown-linux-gnu]
rustflags = ["-C", "link-arg=-fuse-ld=mold"] my versions
|
I've added a
[target.target.x86_64-unknown-linux-gnu]
section to my$HOME/.cargo/config.toml
. If i am now using cross to compile for a different target, saycross build --target aarch64-unknown-linux-gnu
, the build picks up the config for x86_64-unknown-linux-gnu.In my case, i've configured
And the build fails with
doesn't work with rust
1.57.0
either.cross version
0.2.1
The text was updated successfully, but these errors were encountered: