corrosion
corrosion copied to clipboard
Fix corrosion_set_linker_language
It seems that LINKER_LANGUAGE of custom target in generator expression is always empty so make it as custom property.
I don't understand what this fixes. Is it possible to make a test?
I don't understand what this fixes. Is it possible to make a test?
Added a test in envvar
I think I start to see. There exists a cmake target property called LINKER_LANGUAGE, which is meant to be set on executable targets, shared libraries or modules. However cargo-build_${target_name}
is a custom target, so it's possible that setting this target property on a custom target makes cmake just ignore it and later always return an empty string.
I suspect however that the original idea of using this property was to respect's CMake's choice of linker (via CMAKE_<LANG>_LINKER_PREFERENCE), which is something that goes away with this workaround of prefixing.
@crabtw can you elaborate in what context you're calling corrosion_set_linker_language?
Actually my project don't use corrosion_set_linker_language. I was trying to figure out how corrosion's LINKER_LANGUAGE works and found that the value is always empty.
I suspect however that the original idea of using this property was to respect's CMake's choice of linker (via CMAKE__LINKER_PREFERENCE), which is something that goes away with this workaround of prefixing.
We do still have the loop in build_crates.rs which chooses the language with the highest CMAKE_
I do have to admit that LINKER_LANGUAGE
confuses me. There are the (probably related) genexes `$<LINK_LANGUAGE>, which have some constraints. So I think prefixing the override option and if not set choosing the language with the highest linker preference ourselves may indeed be the better option.
I was trying to figure out how corrosion's LINKER_LANGUAGE works and found that the value is always empty.
I can confirm that.
If tgt
is a rust crate (so a CMake interface library), this produces an empty file:
set_target_properties(${tgt} PROPERTIES LINKER_LANGUAGE C)
file(GENERATE OUTPUT ${tgt}_linker_language.txt CONTENT
"$<TARGET_PROPERTY:${tgt},LINKER_LANGUAGE>")
And this produces a file with "C".
set_target_properties(${tgt} PROPERTIES AA_LINKER_LANGUAGE C)
file(GENERATE OUTPUT ${tgt}_linker_language.txt CONTENT
"$<TARGET_PROPERTY:${tgt},AA_LINKER_LANGUAGE>")
So I do think this makes sense.
@ogoffart Since we have released version 0.1
, I would go ahead and merge this and the other open PR if that is okay with you.
Ok. I must admit i don't understand this one. But if you do, go ahead!
I had another look at this, and openend issue #133 for a more general discussion of what we should do.
Closing, since #208 deprecated corrosion_set_linker_language.