Skip to content
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

Default exec=target assumptions on toolchains are too general when trying to use custom toolchains #2544

Open
illicitonion opened this issue Mar 5, 2024 · 0 comments

Comments

@illicitonion
Copy link
Collaborator

The musl_cross_compiling example doesn't work out of the box when compiling on linux-gnu for linux-musl.

In that case, we need two rust toolchains - one for our exec tools which compiles linux-gnu -> linux gnu, and another for our target output which compiles linux-gnu -> linux-musl. When doing a build currently, the correct C++ toolchain is chosen in each case, but the linux-gnu -> linux-gnu Rust toolchain is selected for both target platforms. This is incorrect - the linux-gnu -> linux-gnu toolchain should not be selected for linux-gnu -> linux-musl because it has a constraint it doesn't satisfy.

I believe this is because in a few places we hard-code an assumption basically that "any Linux toolchain is good enough for any Linux target".

One of these places is here:

if toolchain.target_triple == exec_triple:
# The exec triple implicitly gets a toolchain with itself as a target - use default_target_compatible_with for it
target_compatible_with = default_target_compatible_with
elif type(extra_target_triples) == "dict":
target_compatible_with = extra_target_triples.get(toolchain.target_triple)

where we prevent users from telling us "this toolchain actually has a more specific target platform than you expect" - we should swap the order of these if-branches.

Another is here:

for target_triple in depset([exec_triple] + extra_target_triples).to_list():

where we encode an assumption that every toolchain is appropriate for targeting its own exec triple.

Fixing these two is sufficient for building example that depends on libc.

See https://github.com/illicitonion/rules_rust/commits/musl-from-linux/ for an example of making this work - the top commit does some hacky changes to break these assumptions, but someone who knows more about the toolchain set-up and/or has more time to think about the consequences of these changes should work out what the best real fix for these problems is.

cc @matte1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant