Skip to content

Use Cabal PackageInfo_warp instead of Paths_warp#1042

Closed
lrworth wants to merge 2 commits intoyesodweb:masterfrom
bellroy:packageinfo
Closed

Use Cabal PackageInfo_warp instead of Paths_warp#1042
lrworth wants to merge 2 commits intoyesodweb:masterfrom
bellroy:packageinfo

Conversation

@lrworth
Copy link
Contributor

@lrworth lrworth commented Aug 27, 2025

Use of Paths_warp causes a large dependency closure when building with nix. See NixOS/nixpkgs#264434 for example.

This reduces the closure size of our application from 756Mb to 53Mb by virtue of not including GHC and GCC.

It makes a significant change to cabal-version and I'm not sure what compatibility we're trying to maintain in this project; also I made some incidental changes so that it would build with GHC 9.12.

This is not merge-ready — the PR is meant to open a discussion about using PackageInfo_.

Use of Paths_warp causes a huge runtime dependency closure because it
references GHC itself.
Copy link
Contributor

@Vlix Vlix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine, though does the cabal-version bump mean it won't build with GHC 9.10 anymore? That might be unacceptable.

We'd need to add conditionals etc. to add the Path/PackageInfo modules.

!mRange = getHeaderValue tokenRange reqvt
!mReferer = getHeaderValue tokenReferer reqvt
!mUserAgent = getHeaderValue tokenUserAgent reqvt
!mPath = getFieldValue tokenPath reqvt -- SHOULD
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requires an increase to the lower version bound of http2 (>= 5.2)

import qualified Data.ByteString as S
import Data.ByteString.Internal (create)
import qualified Data.CaseInsensitive as CI
import Data.List (foldl')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect this to fail on any GHC < 9.10, so this might need CPP around it.

-- | The version of Warp.
warpVersion :: String
warpVersion = showVersion Paths_warp.version
warpVersion = showVersion PackageInfo_warp.version
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did this end up in this module?

Can you move this to Network.Wai.Handler.Warp.Internal and re-export from here with a comment that it's for backwards compatibility?

, settingsNoParsePath = False
, settingsInstallShutdownHandler = const $ return ()
, settingsServerName = C8.pack $ "Warp/" ++ showVersion Paths_warp.version
, settingsServerName = C8.pack $ "Warp/" ++ showVersion PackageInfo_warp.version
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After moving warpVersion to Network.Wai.Handler.Warp.Internal, please import from there and use here.

@Vlix
Copy link
Contributor

Vlix commented Aug 27, 2025

Also please merge the current master branch, as it has fixed some CI issues.

@lrworth
Copy link
Contributor Author

lrworth commented Aug 29, 2025

The lts-21 / GHC 9.4 configuration listed in CI doesn't work:

$ stack test --system-ghc --resolver lts-21 --stack-yaml stack-lts-21.yaml

Warning: nix (Nix) 2.29.0 is on the PATH (at /nix/var/nix/profiles/default/bin/nix) but Stack's Nix integration is disabled. To mute this message in future, set notify-if-nix-on-path: false in Stack's
         configuration.

Selected snapshot: lts-21.25.
[...]
Populating package index cache ...
Package index cache populated

Error: [S-242]
       Unable to parse Cabal file from package $PWD/wai/warp/warp.cabal:
       * 0:0: Unsupported cabal-version 3.12. See https://github.com/haskell/cabal/issues/4899.

       The Cabal file uses the Cabal specification version 3.12, but we only support up to version 3.8. Recommended action: upgrade your build tool (e.g. stack upgrade).

If in principle this work might be merged at a later date, we are happy to maintain a fork in a mergeable state. What do you say, @Vlix?

@Vlix
Copy link
Contributor

Vlix commented Aug 29, 2025

I think we could work around this and keep the cabal-version at its current >= 1.10.

Adding a flag to warp that switches between using the Paths_warp or PackageInfo_warp generated module would be sufficient, no?
And we'll want to move over to the PackageInfo_warp module in the future, of course, since we only use the version, but while we still want to support earlier GHC's, this is not enforceable.

flag package-info
  description: Use 'PackageInfo_warp' instead of 'Paths_warp' (needs Cabal >= 3.10)
  default: False
  manual: True
if flag(package-info)
    other-modules: PackageInfo_warp
else
    other-modules: Paths_warp

@lrworth
Copy link
Contributor Author

lrworth commented Aug 30, 2025

haskell/cabal#9481 guards against using PackageInfo_* with cabal-version: >= 1.10, so that change would work with old versions of Cabal but not the ones that actually support PackageInfo_*. Building bellroy@5b6eb2c with Cabal 3.14.2 gives me:

> [autogen-guard] To use the autogenerated module PackageInfo_* you need to specify `cabal-version: 3.12` or higher.

@lrworth lrworth mentioned this pull request Aug 30, 2025
5 tasks
@lrworth
Copy link
Contributor Author

lrworth commented Aug 30, 2025

#1044 is a much more conservative approach — optionally removing dependency on Paths_* by disabling runtime version support altogether.

@Vlix Vlix closed this in #1044 Sep 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants