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

Make clang our default compiler on Linux, macOS, and FreeBSD #3506

Merged
merged 4 commits into from
Apr 19, 2020

Conversation

chalcolith
Copy link
Member

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

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'))
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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!

Copy link
Member

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

@SeanTAllen SeanTAllen added the changelog - changed Automatically add "Changed" CHANGELOG entry on merge label Apr 19, 2020
CC = clang
CXX = clang++
endif
else ifeq ($(CC), cc)
Copy link
Member

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.

Copy link
Member

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

Copy link
Member Author

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.

@SeanTAllen
Copy link
Member

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`.
Copy link
Member

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

Copy link
Member Author

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.

@SeanTAllen SeanTAllen changed the title Make the Unix makefile default to clang Make clang our default compiler on Linux, macOS, and FreeBSD Apr 19, 2020
@chalcolith chalcolith merged commit 9bb0888 into master Apr 19, 2020
@chalcolith chalcolith deleted the default_to_clang branch April 19, 2020 18:13
github-actions bot pushed a commit that referenced this pull request Apr 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog - changed Automatically add "Changed" CHANGELOG entry on merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants