From c045b261c4f7d2c2514e858120950be6b3ddfba8 Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Mon, 17 Jun 2024 18:41:24 +0200 Subject: [PATCH] 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 --- src/PostgREST/Version.hs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/PostgREST/Version.hs b/src/PostgREST/Version.hs index 4e99b788d..e551413e0 100644 --- a/src/PostgREST/Version.hs +++ b/src/PostgREST/Version.hs @@ -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