Skip to content

Commit b3a7f9e

Browse files
authored
Merge pull request #1350 from tweag/cc-wrapper
Fix issues around cc_wrapper with Cabal builds
2 parents 7687765 + 97647cc commit b3a7f9e

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

haskell/private/cabal_wrapper.py.tpl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,16 @@ def tmpdir():
121121
# Executables are placed into `<distdir>/build/<package-name>/<binary>`.
122122
# Libraries are placed into `<distdir>/build/<library>`. I.e. there is an
123123
# extra subdirectory for libraries.
124-
if component.startswith("exe:"):
125-
distdir = tempfile.mkdtemp(dir=os.path.dirname(os.path.dirname(pkgroot)))
124+
#
125+
# On Windows we don't do dynamic linking and prefer shorter paths to avoid
126+
# exceeding `MAX_PATH`.
127+
if "%{is_windows}" == "True":
128+
distdir = tempfile.mkdtemp()
126129
else:
127-
distdir = tempfile.mkdtemp(dir=os.path.dirname(pkgroot))
130+
if component.startswith("exe:"):
131+
distdir = tempfile.mkdtemp(dir=os.path.dirname(os.path.dirname(pkgroot)))
132+
else:
133+
distdir = tempfile.mkdtemp(dir=os.path.dirname(pkgroot))
128134
try:
129135
yield distdir
130136
finally:
@@ -140,6 +146,7 @@ with tmpdir() as distdir:
140146
# absolute ones before doing so (using $execroot).
141147
old_cwd = os.getcwd()
142148
os.chdir(srcdir)
149+
os.putenv("RULES_HASKELL_EXEC_ROOT", old_cwd)
143150
os.putenv("HOME", "/var/empty")
144151
os.putenv("TMPDIR", os.path.join(distdir, "tmp"))
145152
os.putenv("TMP", os.path.join(distdir, "tmp"))
@@ -165,7 +172,7 @@ with tmpdir() as distdir:
165172
# absolute paths refer the temporary directory that GHC uses for
166173
# intermediate template Haskell outputs. `cc_wrapper` should improved
167174
# in that regard.
168-
"--builddir=" + os.path.relpath(distdir), \
175+
"--builddir=" + (os.path.relpath(distdir) if "%{is_windows}" != "True" else distdir), \
169176
"--prefix=" + pkgroot, \
170177
"--libdir=" + libdir, \
171178
"--dynlibdir=" + dynlibdir, \

haskell/private/cc_wrapper.py.tpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -711,17 +711,17 @@ def find_solib_rpath(rpaths, output):
711711
"""
712712
for rpath in rpaths:
713713
components = rpath.replace("\\", "/").split("/")
714-
solib_rpath = []
714+
solib_rpath = ""
715715
for comp in components:
716-
solib_rpath.append(comp)
717-
if comp.startswith("_solib_"):
718-
return "/".join(solib_rpath)
716+
solib_rpath = os.path.join(solib_rpath, comp)
717+
if comp.startswith("_solib_") and os.path.isdir(resolve_rpath(solib_rpath, output)[1]):
718+
return solib_rpath
719719

720720
if is_temporary_output(output):
721721
# GHC generates temporary libraries outside the execroot. In that case
722722
# the Bazel generated RPATHs are not forwarded, and the solib directory
723723
# is not visible on the command-line.
724-
for (root, dirnames, _) in breadth_first_walk("."):
724+
for (root, dirnames, _) in breadth_first_walk(os.environ.get("RULES_HASKELL_EXEC_ROOT", ".")):
725725
if "_solib_{:cpu:}" in dirnames:
726726
return os.path.join(root, "_solib_{:cpu:}")
727727

0 commit comments

Comments
 (0)