Debian Codegraph @

rpython/translator/platform/darwin.py

raw symbols SCIP
1 """Support for OS X."""
2 from __future__ import print_function
3
4 from rpython.translator.platform import posix
5 import os
6
7 #
8 # Although Intel 32bit is supported since Apple Mac OS X 10.4, (and PPC since, ever)
9 # the @rpath handling used in Darwin._args_for_shared is only availabe
10 # since 10.5, so we use that as minimum requirement. Bumped to 10.7
11 # to allow the use of thread-local in __thread in C.
12 # Bumped to 10.9 2021-11-22 to match CPython,
13 # see https://github.com/python/cpython/blob/42205ee51
14 #
15 # Bumped to 10.15 on py3.9+ for variadic arg handling in HPy
16 # Note this is not used on arm64 builds.
17 #
18 # Keep in sync with MACOSX_DEPLOYMENT_TARGET, for pypy see
19 # lib_pypy/_sysconfigdata.py
20 #
21 DARWIN_VERSION_MIN = '-mmacosx-version-min=10.13'
22
23 class Darwin(posix.BasePosix):
24 name = "darwin"
25
26 standalone_only = ('-mdynamic-no-pic',)
27 shared_only = ()
28
29 link_flags = (DARWIN_VERSION_MIN,)
30 cflags = ('-O3',
31 '-fomit-frame-pointer',
32 # The parser turns 'const char *const *includes' into 'const const char **includes'
33 '-Wno-duplicate-decl-specifier',
34 DARWIN_VERSION_MIN,)
35
36 so_ext = 'dylib'
37 DEFAULT_CC = 'clang'
38 rpath_flags = ['-Wl,-rpath', '-Wl,@executable_path/']
39
40 def get_multiarch(self):
41 return 'darwin'
42
43 def get_rpath_flags(self, rel_libdirs):
44 # needed for cross compiling on ARM, needs fixing if relevant for darwin
45 if len(rel_libdirs) > 0:
46 print('in get_rpath_flags, rel_libdirs is not fixed up',rel_libdirs)
47 return self.rpath_flags
48
49 def _args_for_shared(self, args, **kwds):
50 if 'exe_name' in kwds:
51 target_basename = kwds['exe_name'].basename
52 else:
53 target_basename = '$(TARGET)'
54 # The default '$(TARGET)' is used inside a Makefile. Otherwise
55 # we get the basename of the executable we're trying to build.
56 return (list(self.shared_only)
57 + ['-dynamiclib', '-install_name', '@rpath/' + target_basename,
58 '-undefined', 'dynamic_lookup', '-flat_namespace',
59 '-headerpad_max_install_names',
60 ]
61 + args)
62
63 def _include_dirs_for_libffi(self):
64 return self._pkg_config("libffi", "--cflags-only-I",
65 ['/usr/include/ffi'],
66 check_result_dir=True)
67
68 def _library_dirs_for_libffi(self):
69 return self._pkg_config("libffi", "--libs-only-L",
70 ['/usr/lib'],
71 check_result_dir=True)
72
73 def _include_dirs_for_openssl(self):
74 return self._pkg_config("openssl", "--cflags-only-I",
75 ['/usr/include', '/usr/local/opt/openssl/include'],
76 check_result_dir=True)
77
78 def _library_dirs_for_openssl(self):
79 return self._pkg_config("openssl", "--libs-only-L",
80 ['/usr/lib', '/usr/local/opt/openssl/lib'],
81 check_result_dir=True)
82
83 def _frameworks(self, frameworks):
84 args = []
85 for f in frameworks:
86 args.append('-framework')
87 args.append(f)
88 return args
89
90 def _link_args_from_eci(self, eci, standalone):
91 args = super(Darwin, self)._link_args_from_eci(eci, standalone)
92 frameworks = self._frameworks(eci.frameworks)
93 include_dirs = self._includedirs(eci.include_dirs)
94 return (args + frameworks + include_dirs)
95
96 def _exportsymbols_link_flags(self):
97 # XXX unsure if OS/X requires an option to the linker to tell
98 # "please export all RPY_EXPORTED symbols even in the case of
99 # making a binary and not a dynamically-linked library".
100 # It's not "-exported_symbols_list" but something close.
101 return []
102
103 def gen_makefile(self, cfiles, eci, exe_name=None, path=None,
104 shared=False, headers_to_precompile=[],
105 no_precompile_cfiles = [], profopt=False, config=None):
106 # ensure frameworks are passed in the Makefile
107 fs = self._frameworks(eci.frameworks)
108 extra_libs = self.extra_libs
109 if len(fs) > 0:
110 # concat (-framework, FrameworkName) pairs
111 self.extra_libs += tuple(map(" ".join, zip(fs[::2], fs[1::2])))
112 mk = super(Darwin, self).gen_makefile(cfiles, eci, exe_name, path,
113 shared=shared,
114 headers_to_precompile=headers_to_precompile,
115 no_precompile_cfiles = no_precompile_cfiles,
116 profopt=profopt, config=config)
117 self.extra_libs = extra_libs
118 return mk
119
120 class Darwin_PowerPC(Darwin):#xxx fixme, mwp
121 name = "darwin_powerpc"
122 link_flags = Darwin.link_flags + ('-arch', 'ppc')
123 cflags = Darwin.cflags + ('-arch', 'ppc')
124
125 class Darwin_i386(Darwin):
126 name = "darwin_i386"
127 link_flags = Darwin.link_flags + ('-arch', 'i386')
128 cflags = Darwin.cflags + ('-arch', 'i386')
129
130 class Darwin_x86_64(Darwin):
131 name = "darwin_x86_64"
132 link_flags = Darwin.link_flags + ('-arch', 'x86_64')
133 cflags = Darwin.cflags + ('-arch', 'x86_64')
134
135 class Darwin_arm64(Darwin):
136 name = 'darwin_arm64'
137 link_flags = Darwin.link_flags + ('-arch', 'arm64')
138 cflags = Darwin.cflags + ('-arch', 'arm64')