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

ENV.cc and ENV.cxx is not correctly set when depending on gcc formula #10170

Closed
iMichka opened this issue Dec 28, 2020 · 10 comments · Fixed by #10512
Closed

ENV.cc and ENV.cxx is not correctly set when depending on gcc formula #10170

iMichka opened this issue Dec 28, 2020 · 10 comments · Fixed by #10512
Labels
outdated PR was locked due to age

Comments

@iMichka
Copy link
Member

iMichka commented Dec 28, 2020

What you were trying to do (and why)

Trying to install a meson-based formula (https://github.com/Homebrew/linuxbrew-core/pull/21946) on linux with gcc@7.
The issues is also present on macOS.

What happened (include command output)

ENV["CC"], ENV["CXX"], ENV.cc, ENV.cxx is incorrectly set in the install and test block.

The wrong compiler is defined.

  • On Mac it is always set to clang/clang++, even if I define depends_on "gcc@x" in the formula.
  • On Linux it is always set to the biggest gcc installed: if gcc@10 is installed on the system, ENV.cc is always gcc-10.

meson (but maybe other build tools) will pick up the wrong compiler.
Some tests blocks are run with the wrong compiler too, as we use ENV.cc a lot.

What you expected to happen

ENV["CC"], ENV["CXX"], ENV.cc, ENV.cxx should point to the gcc formula defined in the formula.

Note

This issue might not be a bug but a design choice. In that case I would like to change that behaviour.

@carlocab
Copy link
Member

On Mac it is always set to clang/clang++, even if I define depends_on "gcc@x" in the formula.

I think this is intentional, as many of the formulae just depend on gcc for gfortran. If you want it not to use clang on macOS, I think you need fails_with.

@iMichka
Copy link
Member Author

iMichka commented Dec 28, 2020

I see. I can use (on Mac)

  fails_with :clang
  depends_on "gcc@9"

which gives me ... gcc-10, because I have gcc installed.

If I want gcc@9, I need to use:

  fails_with :clang
  fails_with gcc: "10"
  depends_on "gcc@9"

If I want gcc@7, I need to use:

  fails_with :clang
  fails_with gcc: "8"
  fails_with gcc: "9"
  fails_with gcc: "10"
  depends_on "gcc@7"

It's not the shortest syntax but it works.

@carlocab
Copy link
Member

Yes. I haven't managed to figure out how to use fails_with to get it to use LLVM clang instead of Apple clang, though. But I didn't try very hard, and that was a while ago.

@iMichka
Copy link
Member Author

iMichka commented Dec 29, 2020

Ok so I can live with the fails_with syntax for the time being.

I think the biggest issue I have right now is on Linux: ENV.cc and friends will always point to the highest gcc installed.
Historically brewed gcc on linux was gcc-5. I am changing it to align it with homebrew-core, so now brew gcc becomes gcc-10 (https://github.com/Homebrew/linuxbrew-core/pull/21380).

If I brew install gcc on linux, now all the ENV.cc will point to gcc-10, even with a pristine formula that does not define a specific gcc.

I would expect the following behaviour (on Linux):
ENV.CC points to /usr/bin/gcc by default
ENV.CC points to gcc@5 if /usr/bin/gcc != gcc-5 (this also means that gcc@5 needs to be installed)
ENV.CC points to gcc@x if gcc@x is defined in the formula

I have no clue how to change that behaviour right now.

@jonchang
Copy link
Contributor

The logic is in compilers.rb, but compiler selection is pretty hairy currently and we'd need to think carefully about how to handle this. In particular:

ENV.CC points to gcc@5 if /usr/bin/gcc != gcc-5 (this also means that gcc@5 needs to be installed)

Do we want gcc@5 to be used if the system compiler is newer?

@iMichka
Copy link
Member Author

iMichka commented Dec 29, 2020

Do we want gcc@5 to be used if the system compiler is newer?

I would like. Almost everything is compiled with gcc5 on linux CI: I would like to use brewed gcc5 as a fallback when no gcc5 is present. This makes sure the builds have more chances to pass if someone builds from source.

@carlocab
Copy link
Member

One thing I noticed though is that fails_with gcc "8" also appears to rule out any newer gcc, so it may be sufficient to just do

fails_with :clang
fails_with gcc: "8"
depends_on "gcc@7"

if you want gcc@7.

@MikeMcQuaid
Copy link
Member

Yes, fails_with is what's required to make this work as expected. We can't really change the behaviour of depends_on here without breaking lots of other formulae.

ENV.CC points to /usr/bin/gcc by default
ENV.CC points to gcc@5 if /usr/bin/gcc != gcc-5 (this also means that gcc@5 needs to be installed)

Something like this seems reasonable for Linux-only with a concept of preferring a specific compiler version that we use for building bottles.

@iMichka
Copy link
Member Author

iMichka commented Dec 31, 2020

ENV.CC points to /usr/bin/gcc by default
ENV.CC points to gcc@5 if /usr/bin/gcc != gcc-5 (this also means that gcc@5 needs to be installed)

Something like this seems reasonable for Linux-only with a concept of preferring a specific compiler version that we use for building bottles.

This is on the todo list then for the linuxbrew-core migration.

@BrewTestBot
Copy link
Member

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@BrewTestBot BrewTestBot added the stale No recent activity label Jan 22, 2021
@iMichka iMichka removed the stale No recent activity label Jan 22, 2021
iMichka added a commit to iMichka/brew that referenced this issue Feb 3, 2021
- Fixes Homebrew#10170 by preferring gcc@5 on linux (by using the PREFERRED_GCC const)
This makes sure ENV.cc and ENV.cxx is correctly set:
  - If a formula does not depend explicitely on a brewed gcc, ENV.cc is set to gcc-5 (system gcc-5 or brewed gcc-5)
    evend if other gcc versions are installed on the system

- Use fails_with as a way to remove all other compilers from the list of available compilers.
  This avoids having to set any fails_with on linux.
  A small workaround is present for the current setup where gcc == version 5 on linuxbrew-core,
  and we do not want to remove gcc-5 from the list unless explicitely specified. That workaround
  can be removed once https://github.com/Homebrew/linuxbrew-core/pull/21380 is merged
iMichka added a commit to iMichka/brew that referenced this issue Feb 8, 2021
Fixes Homebrew#10170 by preferring gcc@5 on linux
This makes sure ENV.cc and ENV.cxx is correctly set:

If a formula does not explicitely depend on a brewed gcc,
ENV.cc is set to gcc-5 (system gcc-5 or brewed gcc-5) with this change,
even if other gcc versions are installed on the system.
@BrewTestBot BrewTestBot added the outdated PR was locked due to age label Mar 11, 2021
@Homebrew Homebrew locked as resolved and limited conversation to collaborators Mar 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
5 participants