-
-
Notifications
You must be signed in to change notification settings - Fork 419
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
Make clang our default compiler on Linux, macOS, and FreeBSD #3506
Conversation
If `CC` is not defined when running make, or is equal to `cc`, and `clang` is in the PATH, this sets `CC=clang` and `CXX=clang++`.
Searching for "clang" by itself doesn't work right on Ubuntu, because the output of automatically suggesting the right apt package to install contains the string "clang".
# By default, CC is cc and CXX is g++ | ||
# So if you use standard alternatives on many Linuxes | ||
# You can get clang and g++ and then bad things will happen | ||
ifneq (,$(shell $(CC) --version 2>&1 | grep clang)) | ||
ifneq (,$(shell $(CC) --version 2>&1 | grep 'clang version')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the clang version change?
i know what i had previously worked for what i tested. unfortunately i don't remember what i tested so i have no idea if this change still covers whatever i tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Ubuntu if you call clang --version
when clang is not installed, it prints some helpful info about running apt install clang
, which contains the string "clang", so the makefile thinks that clang is installed when it is not. Searching for "clang version" in the output only matches the actual output of clang --version
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I definitely didn't test that. Nice catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be good to update the comments around the checks to explain why "clang version" rather than just "clang".
CC = clang | ||
CXX = clang++ | ||
endif | ||
else ifeq ($(CC), cc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if I have cc set to gcc. And I say CC=cc, we are going to override as clang?
My first thought is "that sounds like a bad idea". However, I am guessing that the default behavior on many distros is to do CC=cc right?
Which is probably gcc.
So basically, we need to tell people "you need to explicitly set CC to gcc and CXX to g++ if you want to use gcc." I think that should be noted in BUILD.md.
I would find it surprising as a user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it also makes sense to note in a comment here that overriding CC being set to gcc is intentional and not an oversite as some folks might think it is a bug rather than intentional give the comment is "clang as default".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, added a comment to that effect and notes in INSTALL.md and BUILD.md.
I think as part of this PR we should also update INSTALL.md where it says: "All ponyc Linux installations need a C compiler such as gcc or clang installed. The following distributions have additional requirements:" To say something like: "All ponyc Linux installations need to have a C compiler such as clang installed. Compilers other than clang might work, but clang is the officially supported C compiler. The following distributions have additional requirements:" |
BUILD.md
Outdated
- `make distclean` will delete the `build` directory, including the libraries. | ||
- `make distclean` will delete the entire `build` directory, including the libraries. | ||
|
||
The build system defaults to using Clang on Unix. In order to use GCC, you must explicitly set it in the `configure` step: `make configure CC=gcc`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to tell them to set CXX to g++ as well. Doesn't it? Or is that pairing now handled automatically? (I feel like I did something to handle it automatically).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, fixed. The makefile will complain if CC and CXX are using different compilers, but it won't auto-fix it.
If
CC
is not defined when running make, or is equal tocc
, andclang
is in the PATH, this setsCC=clang
andCXX=clang++
.