@@ -84,10 +84,11 @@ def path_to_label(path, pkgroot, output=None):
8484 else :
8585 print ("WARN: could not handle" , path , file = sys .stderr )
8686
87- def hs_library_pattern (name , mode = "static" , profiling = False ):
87+ def hs_library_pattern (package_name , name , mode = "static" , profiling = False ):
8888 """Convert hs-libraries entry to glob patterns.
8989
9090 Args:
91+ package_name: The name of the package.
9192 name: The library name. E.g. HSrts or Cffi.
9293 mode: The linking mode. Either "static" or "dynamic".
9394 profiling: Look for profiling mode libraries.
@@ -96,30 +97,41 @@ def hs_library_pattern(name, mode = "static", profiling = False):
9697 List of globbing patterns for the library file.
9798
9899 """
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+
99117 # The RTS configuration suffix.
100118 # 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" :
104121 configs = [
105122 prefix + config
106123 for config in configs
107- for prefix in ["" , "_thr" ]
124+ for prefix in ["" , "_thr" , "_debug" , "_thr_debug" ]
108125 ]
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+
115127 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+
119129 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" ]
121132 else :
122133 exts = ["a" ]
134+
123135 return [
124136 "lib{}.{}" .format (libname , ext )
125137 for libname in libnames
@@ -235,21 +247,21 @@ def hs_library_pattern(name, mode = "static", profiling = False):
235247 static_libraries = join_paths ([
236248 [path_to_label (library_dir , pkgroot , output ), library ]
237249 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 )
239251 for library_dir in pkg .library_dirs
240252 for library in match_glob (resolve (library_dir , pkgroot ), pattern )
241253 ]),
242254 static_profiling_libraries = join_paths ([
243255 [path_to_label (library_dir , pkgroot , output ), library ]
244256 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 )
246258 for library_dir in pkg .library_dirs
247259 for library in match_glob (resolve (library_dir , pkgroot ), pattern )
248260 ]),
249261 shared_libraries = join_paths ([
250262 [path_to_label (dynamic_library_dir , pkgroot , output ), library ]
251263 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 )
253265 for dynamic_library_dir in set (pkg .dynamic_library_dirs + pkg .library_dirs )
254266 for library in match_glob (resolve (dynamic_library_dir , pkgroot ), pattern )
255267 ]),
0 commit comments