File: apple.py

package info (click to toggle)
numpy 1%3A2.2.4%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 83,420 kB
  • sloc: python: 248,499; asm: 232,365; ansic: 216,874; cpp: 135,657; f90: 1,540; sh: 938; fortran: 558; makefile: 409; sed: 139; xml: 109; java: 92; perl: 79; cs: 54; javascript: 53; objc: 29; lex: 13; yacc: 9
file content (57 lines) | stat: -rw-r--r-- 2,045 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# SPDX-License-Identifier: Apache-2.0
# Copyright © 2024 Intel Corporation

"""Provides mixins for Apple compilers."""

from __future__ import annotations
import typing as T

from ...mesonlib import MesonException

if T.TYPE_CHECKING:
    from ..._typing import ImmutableListProtocol
    from ...environment import Environment
    from ..compilers import Compiler
else:
    # This is a bit clever, for mypy we pretend that these mixins descend from
    # Compiler, so we get all of the methods and attributes defined for us, but
    # for runtime we make them descend from object (which all classes normally
    # do). This gives up DRYer type checking, with no runtime impact
    Compiler = object


class AppleCompilerMixin(Compiler):

    """Handle differences between Vanilla Clang and the Clang shipped with XCode."""

    __BASE_OMP_FLAGS: ImmutableListProtocol[str] = ['-Xpreprocessor', '-fopenmp']

    def openmp_flags(self, env: Environment) -> T.List[str]:
        """Flags required to compile with OpenMP on Apple.

        The Apple Clang Compiler doesn't have builtin support for OpenMP, it
        must be provided separately. As such, we need to add the -Xpreprocessor
        argument so that an external OpenMP can be found.

        :return: A list of arguments
        """
        m = env.machines[self.for_machine]
        assert m is not None, 'for mypy'
        if m.cpu_family.startswith('x86'):
            root = '/usr/local'
        else:
            root = '/opt/homebrew'
        return self.__BASE_OMP_FLAGS + [f'-I{root}/opt/libomp/include']

    def openmp_link_flags(self, env: Environment) -> T.List[str]:
        m = env.machines[self.for_machine]
        assert m is not None, 'for mypy'
        if m.cpu_family.startswith('x86'):
            root = '/usr/local'
        else:
            root = '/opt/homebrew'

        link = self.find_library('omp', env, [f'{root}/opt/libomp/lib'])
        if not link:
            raise MesonException("Couldn't find libomp")
        return self.__BASE_OMP_FLAGS + link