Skip to content

Commit

Permalink
Add GETDEPS_CABAL_FLAGS env var
Browse files Browse the repository at this point in the history
Summary:
X-link: facebookincubator/zstrong#871

The problem I need to solve is that projects without a pkg-config
can't be found by Cabal. I need to pass extra flags to Cabal for it to
find the includes and libraries for these projects. So here I'm
creating a `GETDEPS_CABAL_FLAGS` env with all the necessary flags.

It's a bit horrible. Really I want to do this only for the direct
deps, but where the env is being setup we don't have access to the
direct vs. non-direct deps currently, only the install_dirs.

Reviewed By: josefs

Differential Revision: D58200841

fbshipit-source-id: 03f8630610691485561438d69fe8e1182396cd04
  • Loading branch information
Simon Marlow authored and facebook-github-bot committed Jun 7, 2024
1 parent e1c5270 commit 7582943
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions build/fbcode_builder/getdeps/buildopts.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,17 @@ def add_prefix_to_env(
) -> bool: # noqa: C901
bindir = os.path.join(d, "bin")
found = False
has_pkgconfig = False
pkgconfig = os.path.join(d, "lib", "pkgconfig")
if os.path.exists(pkgconfig):
found = True
has_pkgconfig = True
add_path_entry(env, "PKG_CONFIG_PATH", pkgconfig, append=append)

pkgconfig = os.path.join(d, "lib64", "pkgconfig")
if os.path.exists(pkgconfig):
found = True
has_pkgconfig = True
add_path_entry(env, "PKG_CONFIG_PATH", pkgconfig, append=append)

add_path_entry(env, "CMAKE_PREFIX_PATH", d, append=append)
Expand All @@ -369,6 +372,15 @@ def add_prefix_to_env(
add_flag(env, "CPPFLAGS", f"-I{ncursesincludedir}", append=append)
elif "/bz2-" in d:
add_flag(env, "CPPFLAGS", f"-I{includedir}", append=append)
# For non-pkgconfig projects Cabal has no way to find the includes or
# libraries, so we provide a set of extra Cabal flags in the env
if not has_pkgconfig:
add_flag(
env,
"GETDEPS_CABAL_FLAGS",
f"--extra-include-dirs={includedir}",
append=append,
)

# The thrift compiler's built-in includes are installed directly to the include dir
includethriftdir = os.path.join(d, "include", "thrift")
Expand Down Expand Up @@ -407,6 +419,13 @@ def add_prefix_to_env(
add_flag(env, "LDFLAGS", f"-L{libdir}", append=append)
if add_library_path:
add_path_entry(env, "LIBRARY_PATH", libdir, append=append)
if not has_pkgconfig:
add_flag(
env,
"GETDEPS_CABAL_FLAGS",
f"--extra-lib-dirs={libdir}",
append=append,
)

# Allow resolving binaries (eg: cmake, ninja) and dlls
# built by earlier steps
Expand Down

0 comments on commit 7582943

Please sign in to comment.