From 758294343d6efa9ecfe73d69e31c18f071448e00 Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Fri, 7 Jun 2024 11:19:29 -0700 Subject: [PATCH] Add GETDEPS_CABAL_FLAGS env var Summary: X-link: https://github.com/facebookincubator/zstrong/pull/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 --- build/fbcode_builder/getdeps/buildopts.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/build/fbcode_builder/getdeps/buildopts.py b/build/fbcode_builder/getdeps/buildopts.py index bf70265..6bda130 100644 --- a/build/fbcode_builder/getdeps/buildopts.py +++ b/build/fbcode_builder/getdeps/buildopts.py @@ -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) @@ -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") @@ -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