Skip to content

Commit 9c4e23c

Browse files
authored
Merge pull request #2202 from tweag/cb/fix-threaded-so-symlink
Fix using the single threaded RTS lib
2 parents 759e4f5 + ea41a91 commit 9c4e23c

File tree

2 files changed

+49
-18
lines changed

2 files changed

+49
-18
lines changed

haskell/private/pkgdb_to_bzl.py

+30-18
Original file line numberDiff line numberDiff line change
@@ -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
]),

haskell/toolchain.bzl

+19
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,28 @@ def _haskell_toolchain_libraries(ctx, libraries):
250250
if len(ext_components) == 2 and ext_components[0] == "so":
251251
libs[libname]["dynamic"] = lib
252252
else:
253+
# with GHC >= 9.4.1 the rts library has a version number
254+
# included in the name.
255+
# for handling single-threaded and threading variants below,
256+
# we normalize the name and strip the version number
257+
if libname.startswith("HSrts-"):
258+
idx = libname.find("_")
259+
suffix = libname[idx:] if idx > 0 else ""
260+
libname = "HSrts" + suffix
261+
253262
libs[libname] = {"dynamic": lib}
254263
for lib in target[HaskellImportHack].static_libraries.to_list():
255264
name = get_static_hs_lib_name(with_profiling, lib)
265+
266+
# with GHC >= 9.4.1 the rts library has a version number
267+
# included in the name.
268+
# for handling single-threaded and threading variants below,
269+
# we normalize the name and strip the version number
270+
if name.startswith("HSrts-"):
271+
idx = name.find("_")
272+
suffix = name[idx:] if idx > 0 else ""
273+
name = "HSrts" + suffix
274+
256275
entry = libs.get(name, {})
257276
entry["static"] = lib
258277
libs[name] = entry

0 commit comments

Comments
 (0)