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

BLD: handle gcc on MacOS #3234

Merged
merged 1 commit into from
Apr 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion package/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,19 @@ def using_clang():
compiler = new_compiler()
customize_compiler(compiler)
compiler_ver = getoutput("{0} -v".format(compiler.compiler[0]))
return 'clang' in compiler_ver
if 'Spack GCC' in compiler_ver:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I have no issues with the setup file as-is, but I do wonder if this is opening a pandora's box in supporting the peculiarities for various build tools (for example, does EasyBuild also need handling differently?).

Is this the same way numpy/scipy is handling compiler identification @tylerjereddy ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, SciPy uses scipy/_build_utils/compiler_helper.py, which is a module dedicated to compiler handling. As discussed in the matching issue, they implement a small try_compile() function to only allow flags to get appended to the compile line if the compiler genuinely supports them.

We could redesign to use something like that--that may be biting off a bit more than I was hoping to chew here, though we could probably even copy-paste a decent bit of the code.

Here's an example of how it works:

    if sys.platform == 'darwin':
        # Set min macOS version
        min_macos_flag = '-mmacosx-version-min=10.9'
        if has_flag(cc, min_macos_flag):
            args.append(min_macos_flag)
            ext.extra_link_args.append(min_macos_flag)

That has_flag() function checks that the compile flag works "for real" with the compiler:

def has_flag(compiler, flag, ext=None):
    """Returns True if the compiler supports the given flag"""
    return try_compile(compiler, flags=[flag], ext=ext)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this starting to re-implement what automake and cmake build systems do?

# when gcc toolchain is built from source with spack
# using clang, the 'clang' string may be present in
# the compiler metadata, but it is not clang
is_clang = False
elif 'clang' in compiler_ver:
# by default, Apple will typically alias gcc to
# clang, with some mention of 'clang' in the
# metadata
is_clang = True
else:
is_clang = False
return is_clang


def extensions(config):
Expand Down