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

Fix corrosion_set_linker_language #133

Closed
jschwe opened this issue Feb 3, 2022 · 1 comment · Fixed by #208
Closed

Fix corrosion_set_linker_language #133

jschwe opened this issue Feb 3, 2022 · 1 comment · Fixed by #208

Comments

@jschwe
Copy link
Collaborator

jschwe commented Feb 3, 2022

PR #126 brought up the topic that corrosion_set_linker_language currently does not do anything, since the used property LINKER_LANGUAGE is apparently special and can't be used in the way that it was.
Therefore the current behaviour of corrosion_set_linker_language is that nothing happens, and the choice of the linker is not influenced by using this function. E.g. adding corrosion_set_linker_language(rust-exe C) to cpp2rust/CMakeLists.txt does not break the build, since still the C++ linker is invoked.

As far as I can see this topic is only relevant for x2rust style projects, where linking is invoked via cargo.

#126 proposed to fix this by renaming the used property. Due to other corrosion code, the proposed change has the effect that the language specified in corrosion_set_linker_language is appended to a list of linker_languages and build_crate.rs will choose the language from the list with the highest CMAKE_<lang>_LINKER_PREFERENCE. This is probably not what a user would expect from the name of the function (In the case of cpp2rust, again still the C++ linker is invoked).

We could of course also fix that, but I would instead propose to just deprecate corrosion_set_linker_language (which should not be a breaking change, since it effectively doesn't do anything anyway). Instead I think it would make more sense to add a function corrosion_set_linker(<target> <linker>), which allows the user to directly specify the linker it wants to use. If you want to explicitely use the compiler/linker CMake chose for a certain language, you could still do corrosion_set_linker(my_target ${CMAKE_C_COMPILER}) instead of explicitely specifiying a linker.

The new behaviour would then be that if a linker was explictly set via corrosion_set_linker, then the linker_languages and CMAKE_<lang>_LINKER_PREFERENCE is just completely ignored and the linker specified by the user is passed to cargo via CARGO_TARGET_<target_triple>_LINKER

Any thoughts on this?

jschwe added a commit to jschwe/corrosion that referenced this issue Feb 6, 2022
The corrosion generator is a 100% rust executable, so I don't think
there is any benefit in us telling rust which
linker it should use.

Additionally corrosion_set_linker_language currently does not have any effect
 anyway (See corrosion-rs#133).

Closes corrosion-rs#88

Signed-off-by: Jonathan Schwender <[email protected]>
@jschwe
Copy link
Collaborator Author

jschwe commented Feb 6, 2022

When adding a test for #139, I noticed that corrosion_set_linker_language apparently does have an effect. I'm not sure what exactly changed in comparison to my previous tests, so I'll need to investigate that further.

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 a pull request may close this issue.

1 participant