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

Make --target link arg non-local #444

Closed
wants to merge 1 commit into from

Conversation

russelltg
Copy link
Contributor

@russelltg russelltg commented Sep 22, 2023

I'm running into a situation where I filter imported targets with CRATE_TYPES to not include cdylib libraries, but have an executable that depends on a cdylib. Since I'm cross-compiling using clang, it needs that --target flag to compile, but since that flag is only being set locally it doesn't work.

It's possible more flags should be set like this, but this is the one I was running into. Is this a supported usecase?

@jschwe
Copy link
Collaborator

jschwe commented Sep 23, 2023

Basically, you are hitting issue #413, correct?

From the issue:

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.

Preferably I would like to solve the issue upstream, so that rustc automatically passes the --target parameter to clang when required. I already asked on zulip and there seems to be general support, but I haven't had time to work on it.

In the meantime (assuming you are on Linux), you could write a small bash script for your target platform like:

aarch64-linux-gnu-clang:

#!/usr/bin/env bash
clang  --target=aarch64-linux-gnu "${@}"

And then in corrosion call

corrosion_set_linker(your_target /path/to/aarch64-linux-gnu-clang)

Please note that the filename of the bash script should end with clang (or clang-XX, where XX is a version number e.g. 13 or 14 ), so that rustc can infer the linker type from the filename.

@russelltg
Copy link
Contributor Author

Yes, for some reason I assumed my use case was niche enough and didn't look a ton for issues, thanks!

That's a reasonable workaround. What I did it manually set that flag as non local on all the targets that it uses. (basically a workaround to implement what this PR does)

I'll close this considering it's known and you're (very reasonably) not interested in a fix within corrosion.

Thanks!

@russelltg russelltg closed this Sep 23, 2023
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

Successfully merging this pull request may close these issues.

2 participants