Cabal跨开发者配置:统一with-compiler与extra-lib-dirs方案问询
Handling with-compiler Without Absolute Paths
Use version-based compiler references with a GHC manager
If all developers use a GHC version manager like GHCup, specify the required GHC version in your trackedcabal.projectfile instead of an absolute path:with-compiler: ghc-9.6.4As long as each developer has that version installed, the
ghc-<version>executable will be in their system PATH, so Cabal will find it automatically without needing a hardcoded path.Provide a template for
cabal.project.local
Sincecabal.project.localisn't tracked in Git, create a trackedcabal.project.local.examplefile with clear instructions:# Copy this file to cabal.project.local and update the path to your GHC executable with-compiler: /path/to/your/ghc/exeTell other developers to copy this template and adjust the path to their local GHC installation.
Fixing extra-lib-dirs Relative Path Issues
Cabal supports relative paths for extra-lib-dirs (resolved relative to the cabal.project file's directory). Try these fixes:
Explicitly use a project-root-relative path
Update yourcabal.projectto use./to make the relative path unambiguous:extra-lib-dirs: ./libs/mylibThis works if
libs/mylibis directly under your project root (wherecabal.projectresides).Update Cabal to a newer version
Older Cabal versions (pre-3.0) had issues with relativeextra-lib-dirspaths. Ensure everyone uses Cabal 3.0 or later. Check your version with:cabal --versionWrap the library as a Cabal package (if possible)
If you control themylibcode, convert it into a proper Cabal package. Add its.cabalfile tolibs/mylib, then include it in yourcabal.projectas a local package:packages: . ./libs/mylibThis eliminates the need for
extra-lib-dirsentirely—Cabal will handle building and linking the library automatically across all systems.Platform-specific path conditionals (if needed)
If your library has platform-specific binaries, use Cabal's conditional syntax to target different paths:if os(windows) extra-lib-dirs: ./libs/mylib/windows else if os(linux) extra-lib-dirs: ./libs/mylib/linux else if os(darwin) extra-lib-dirs: ./libs/mylib/macos
内容的提问来源于stack exchange,提问作者RandomB

