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

Cross-compiling with clang and (c)dylibs in the dependency graph is broken #413

Open
jschwe opened this issue Jun 25, 2023 · 0 comments
Open

Comments

@jschwe
Copy link
Collaborator

jschwe commented Jun 25, 2023

Bug Scenario:

  • Cross-compiling
  • Linker driver is clang (i.e. requires --target=triple option to link for the correct target)
  • OS is not MacOS (rustc adds --target automatically on Darwin).
  • The dependency graph contains a target that requires the linker to be invoked for the cross-compilation target. This should only be dynamic libraries. Note: This does not include the final artifact - We already pass the the --target flag via cargo rustc to the final linker invocation.

Untested, but probably this requirement also applies:

  • compiler option to use lld (-fuse-ld=lld) is NOT set.

If such a dependency exists in the graph, then linking it will fail, since clang will call the host linker instead of the target linker.

Constraints for solutions:

  • Adding the argument to the global RUSTFLAGS has the side-effect of overriding any rustflags set via .cargo/config.toml, which may be unexpected, especially since it only happens in the cross-compiling with clang scenario.
  • Setting the linker to clang --target=xxx does not work, since this is treated as the executable name.
  • Writing a small wrapper shell script would be possible on Linux, but on Windows it looks like there is no guaranteed way to pass through arguments without changing them with a small script. We could instead compile a small Rust program which calls the linker-driver without going over the shell again.
  • It is unclear if this will be fixed upstream in Rust, since currently gcc and clang are treated entirely the same (except on mac).
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