@@ -84,10 +84,11 @@ def path_to_label(path, pkgroot, output=None):
84
84
else :
85
85
print ("WARN: could not handle" , path , file = sys .stderr )
86
86
87
- def hs_library_pattern (name , mode = "static" , profiling = False ):
87
+ def hs_library_pattern (package_name , name , mode = "static" , profiling = False ):
88
88
"""Convert hs-libraries entry to glob patterns.
89
89
90
90
Args:
91
+ package_name: The name of the package.
91
92
name: The library name. E.g. HSrts or Cffi.
92
93
mode: The linking mode. Either "static" or "dynamic".
93
94
profiling: Look for profiling mode libraries.
@@ -96,30 +97,41 @@ def hs_library_pattern(name, mode = "static", profiling = False):
96
97
List of globbing patterns for the library file.
97
98
98
99
"""
100
+ configs = ["_p" ] if profiling else ["" ]
101
+
102
+ # Library names must either be prefixed with "HS" or "C" and corresponding
103
+ # library file names must match:
104
+ # - Libraries with name "HS<library-name>":
105
+ # - `libHS<library-name>.a`
106
+ # - `libHS<library-name>-ghc<ghc-flavour><ghc-version>.<dyn-library-extension>*`
107
+ # - Libraries with name "C<library-name>":
108
+ # - `libC<library-name>.a`
109
+ # - `lib<library-name>.<dyn-library-extension>*`
110
+ if name .startswith ("C" ):
111
+ libname = name [1 :] if mode == "dynamic" else name
112
+ elif name .startswith ("HS" ):
113
+ libname = name
114
+ else :
115
+ sys .error ("do not know how to handle hs-library `{}` in package {}" .format (name , package_name ))
116
+
99
117
# The RTS configuration suffix.
100
118
# See https://gitlab.haskell.org/ghc/ghc/wikis/commentary/rts/config#rts-configurations
101
- configs = ["_p" ] if profiling else ["" ]
102
- # Special case HSrts or Cffi - include both libXYZ and libXYZ_thr.
103
- if name == "HSrts" or name == "Cffi" :
119
+ # Special case for rts - include multi threaded and single threaded, and debug / non-debug variants
120
+ if package_name == "rts" :
104
121
configs = [
105
122
prefix + config
106
123
for config in configs
107
- for prefix in ["" , "_thr" ]
124
+ for prefix in ["" , "_thr" , "_debug" , "_thr_debug" ]
108
125
]
109
- # Special case libCffi - dynamic lib has no configs and is called libffi.
110
- if name == "Cffi" and mode == "dynamic" :
111
- libname = "ffi"
112
- configs = ["" ]
113
- else :
114
- libname = name
126
+
115
127
libnames = [libname + config for config in configs ]
116
- # Special case libCffi - dynamic lib has no version suffix.
117
- if mode == "dynamic" and name != "Cffi" :
118
- libnames = [libname + "-ghc*" for libname in libnames ]
128
+
119
129
if mode == "dynamic" :
120
- exts = ["so" , "so.*" , "dylib" , "dll" ]
130
+ libnames = [libname + "-ghc*" for libname in libnames ]
131
+ exts = ["so" , "so.*" , "dylib" , "dll" ] if mode == "dynamic" else ["a" ]
121
132
else :
122
133
exts = ["a" ]
134
+
123
135
return [
124
136
"lib{}.{}" .format (libname , ext )
125
137
for libname in libnames
@@ -235,21 +247,21 @@ def hs_library_pattern(name, mode = "static", profiling = False):
235
247
static_libraries = join_paths ([
236
248
[path_to_label (library_dir , pkgroot , output ), library ]
237
249
for hs_library in pkg .hs_libraries
238
- for pattern in hs_library_pattern (hs_library , mode = "static" , profiling = False )
250
+ for pattern in hs_library_pattern (pkg . name , hs_library , mode = "static" , profiling = False )
239
251
for library_dir in pkg .library_dirs
240
252
for library in match_glob (resolve (library_dir , pkgroot ), pattern )
241
253
]),
242
254
static_profiling_libraries = join_paths ([
243
255
[path_to_label (library_dir , pkgroot , output ), library ]
244
256
for hs_library in pkg .hs_libraries
245
- for pattern in hs_library_pattern (hs_library , mode = "static" , profiling = True )
257
+ for pattern in hs_library_pattern (pkg . name , hs_library , mode = "static" , profiling = True )
246
258
for library_dir in pkg .library_dirs
247
259
for library in match_glob (resolve (library_dir , pkgroot ), pattern )
248
260
]),
249
261
shared_libraries = join_paths ([
250
262
[path_to_label (dynamic_library_dir , pkgroot , output ), library ]
251
263
for hs_library in pkg .hs_libraries
252
- for pattern in hs_library_pattern (hs_library , mode = "dynamic" , profiling = False )
264
+ for pattern in hs_library_pattern (pkg . name , hs_library , mode = "dynamic" , profiling = False )
253
265
for dynamic_library_dir in set (pkg .dynamic_library_dirs + pkg .library_dirs )
254
266
for library in match_glob (resolve (dynamic_library_dir , pkgroot ), pattern )
255
267
]),
0 commit comments