refactor: Remove dependency on Paths_ module

The cabal-provided Paths_ module allows us to use the version number
from postgrest.cabal. This can be done equally well with the GHC-defined
CPP macro "VERSION_postgrest".

By making this change we avoid the inclusion of the Paths_ module, which
also stores some paths related to the cabal configuration. Those are
problematic to go into the final executable, because for nix-based
builds those are paths to the /nix/store/... - which means that our
static executable then depends on those paths.. and we can't build a
minimal docker image anymore.

To counter this, we have been using dead code elimination when building
the static executable. This has been working well, but there is a
problem on aarch64-darwin, which we will hit once can finally make our
way there: GHC on aarch64-darwin (or darwin in general?) can't do dead
code elimination - and thus it'd be impossible to create those minimal
docker images for those platforms. More information upstream in nixpkgs:
https://github.com/NixOS/nixpkgs/issues/318013
This commit is contained in:
Wolfgang Walther
2024-06-18 08:28:57 +02:00
committed by Wolfgang Walther
parent d311fb17c4
commit c045b261c4
+6 -5
View File
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE TemplateHaskell #-}
module PostgREST.Version
( docsVersion
@@ -7,19 +8,19 @@ module PostgREST.Version
import qualified Data.ByteString as BS
import qualified Data.Text as T
import Data.Version (showVersion, versionBranch)
import Development.GitRev (gitHash)
import Paths_postgrest (version)
import Protolude
version :: [Text]
version = T.splitOn "." VERSION_postgrest
-- | User friendly version number such as '1.1.1'.
-- Pre-release versions are tagged as such, e.g., '1.1 (pre-release)'.
-- If a git hash is available, it's added to the version, e.g., '1.1.1 (abcdef0)'.
prettyVersion :: ByteString
prettyVersion =
toUtf8 (showVersion version) <> preRelease <> gitRev
VERSION_postgrest <> preRelease <> gitRev
where
gitRev =
if $(gitHash) == ("UNKNOWN" :: Text) then
@@ -35,10 +36,10 @@ prettyVersion =
docsVersion :: Text
docsVersion
| isPreRelease = "latest"
| otherwise = "v" <> (T.intercalate "." . map show . take 1 $ versionBranch version)
| otherwise = "v" <> (T.intercalate "." . map show . take 1 $ version)
-- | Versions with two components (e.g., '1.1') are treated as pre-releases.
isPreRelease :: Bool
isPreRelease =
length (versionBranch version) == 2
length version == 2