Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a c-stub for the placeholder. #5231

Merged
merged 1 commit into from May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions cardano-git-rev/cardano-git-rev.cabal
Expand Up @@ -31,11 +31,11 @@ library
import: project-config

hs-source-dirs: src
c-sources: cbits/rev.c

exposed-modules: Cardano.Git.Rev
Cardano.Git.RevFromGit

build-depends: file-embed
, process
build-depends: process
, template-haskell
, text
11 changes: 11 additions & 0 deletions cardano-git-rev/cbits/rev.c
@@ -0,0 +1,11 @@
// <magic: fe> <marker: gitrev> <size: padded to 20 bytes> <space for gitrev (40 char)>
char _cardano_git_rev[68]
= "fe"
"gitrev"
"0000000000"
"0000000040"
"0000000000"
"0000000000"
"0000000000"
"0000000000"
;
11 changes: 8 additions & 3 deletions cardano-git-rev/src/Cardano/Git/Rev.hs
@@ -1,17 +1,22 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ForeignFunctionInterface #-}

module Cardano.Git.Rev
( gitRev
) where

import Data.FileEmbed (dummySpaceWith)
import Data.Text (Text)
import qualified Data.Text as T
import Data.Text.Encoding (decodeUtf8)

import Cardano.Git.RevFromGit (gitRevFromGit)
import GHC.Foreign (peekCStringLen)
import Foreign.C.String (CString)
import System.IO (utf8)
import System.IO.Unsafe (unsafeDupablePerformIO)

foreign import ccall "&_cardano_git_rev" c_gitrev :: CString

gitRev :: Text
gitRev | gitRevEmbed /= zeroRev = gitRevEmbed
Expand All @@ -22,7 +27,7 @@ gitRev | gitRevEmbed /= zeroRev = gitRevEmbed
-- Data.FileEmbed.injectWith. If nothing has been injected,
-- this will be filled with 0 characters.
gitRevEmbed :: Text
gitRevEmbed = decodeUtf8 $(dummySpaceWith "gitrev" 40)
gitRevEmbed = T.pack $ drop 28 $ unsafeDupablePerformIO (peekCStringLen utf8 (c_gitrev, 68))

-- Git revision found during compilation by running git. If
-- git could not be run, then this will be empty.
Expand Down