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

Add CRYSTAL_CONFIG_CC compiler config #14318

Merged

Conversation

straight-shoota
Copy link
Member

This environment variable allows to bake into the compiler a default path for CC pointing to a specific linker.
Currently, the fixed default default is cc (cl.exe on Windows). Changing this when compiling the compiler allows taking into account a linker designed for a specific build environment. An example for this would be homebrew, where the compiler should use the linker installed in homebrew because it knows where to find libraries installed via homebrew.

An alternative would be patching the source when necessary, but that's more fragile. An environment variable is more reliable. It serves as a reference that this value can be configured.

Originally suggested in https://forum.crystal-lang.org/t/crystal-installation-using-linuxbrew-is-not-working/6559/10?u=straight-shoota

@crysbot
Copy link

crysbot commented Feb 24, 2024

This pull request has been mentioned on Crystal Forum. There might be relevant details there:

https://forum.crystal-lang.org/t/crystal-installation-using-linuxbrew-is-not-working/6559/15

@HertzDevil
Copy link
Contributor

I'm wondering about the discoverability of this value. IMO crystal build --verbose shouldn't be the only way to find out the default compiler / linker

@straight-shoota
Copy link
Member Author

It should probably be in the output of crystal env. But then it should be the actual value, taking runtime configuration (i.e. CC) into account.
That's however not trivial due to the complexity of Compiler#linker_command. We should think about how to extract the static linker information.

@straight-shoota straight-shoota added this to the 1.12.0 milestone Mar 7, 2024
@straight-shoota straight-shoota merged commit 12cd092 into crystal-lang:master Mar 9, 2024
57 checks passed
@straight-shoota straight-shoota deleted the feat/config-cc branch March 9, 2024 08:59
@straight-shoota
Copy link
Member Author

straight-shoota commented Mar 14, 2024

For stdlib/compiler development, there's a catch: This approach doesn't work when using the makefile because it defines $CC and thus overrides the compiler default.

EXPORT_CC ?= CC="$(CC) -fuse-ld=lld"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants