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

Allow explicitly selecting the linker for a rust target #208

Merged
merged 4 commits into from
Sep 1, 2022

Conversation

jschwe
Copy link
Collaborator

@jschwe jschwe commented Aug 31, 2022

  • Allow explicitily setting a linker for when linking is done via cargo.
  • Use VERBATIM option when invoking cargo build so that CMake quotes as necessary. This should improve the experience for passing some parameters, but is a breaking change.

Closes #133
Closes #88

jschwe added 4 commits August 30, 2022 15:22
There is no point in selecting the CXX compiler as the linker driver for the corrosion-generator.
We might as well let cargo choose the appropriate linker based on the target.
Let CMake deal with the correct quoting.
This change makes it easier to e.g. pass --cfg options via Rustflags.
Allow explicitly defining a linker for when linking is done on the Rust side.
Previously Corrosion offered an corrosion_set_linker_language(), which
effectively enabled a language, but still determined the linker by choosing
the compiler with the highest priority as determined by CMake.
This is probably not what most users actually want.

Explicitly setting a linker should be less surprising and more in line with
what a user would actually want to do.
Since setting a linker may happen multiple times for different targets and
potentially with different linkers, we don't use find_program to verify
if the linker can actually be found (for performance reasons).

However, we do not allow explicitely setting the linker for MSVC toolchains.
Setting the linker causes strange problems with MSVC, where build-script-build
fails with a file not found os-error, and I'm not exactly sure why. Since with
MSVC the build should anyway be run from a visual studio command prompt, the
correct `cl.exe` will be in PATH, so we can just let cargo find it in this
case.
It's not possible for corrosion to automatically add this if the linker
is manually set.
Since cargo does actually automatically add the `--target` linker option
when appropriate, there should also be no need for corrosion to set it.
@jschwe jschwe changed the title Allow explicitily selecting the linker for a rust target Allow explicitly selecting the linker for a rust target Aug 31, 2022
@jschwe jschwe requested a review from ogoffart August 31, 2022 14:04
@jschwe jschwe merged commit cb4e49e into corrosion-rs:master Sep 1, 2022
@jschwe jschwe deleted the set_linker branch September 1, 2022 11:19
@jschwe jschwe added this to the v0.3 milestone Sep 18, 2022
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.

Fix corrosion_set_linker_language Link with C compiler instead of C++ compiler
2 participants