corrosion icon indicating copy to clipboard operation
corrosion copied to clipboard

Fix corrosion_set_linker_language

Open crabtw opened this issue 2 years ago • 9 comments

It seems that LINKER_LANGUAGE of custom target in generator expression is always empty so make it as custom property.

crabtw avatar Jan 08 '22 14:01 crabtw

I don't understand what this fixes. Is it possible to make a test?

ogoffart avatar Jan 08 '22 15:01 ogoffart

I don't understand what this fixes. Is it possible to make a test?

Added a test in envvar

crabtw avatar Jan 09 '22 04:01 crabtw

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?

tronical avatar Jan 10 '22 14:01 tronical

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.

crabtw avatar Jan 11 '22 10:01 crabtw

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__LINKER_PREFERENCE, so I think prefixing would be ok.

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.

jschwe avatar Jan 16 '22 18:01 jschwe

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.

jschwe avatar Jan 24 '22 08:01 jschwe

@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.

jschwe avatar Feb 02 '22 12:02 jschwe

Ok. I must admit i don't understand this one. But if you do, go ahead!

ogoffart avatar Feb 02 '22 13:02 ogoffart

I had another look at this, and openend issue #133 for a more general discussion of what we should do.

jschwe avatar Feb 03 '22 10:02 jschwe

Closing, since #208 deprecated corrosion_set_linker_language.

jschwe avatar Sep 01 '22 11:09 jschwe