From 54681e8f0d51980a1698f4863210f5932a7d2133 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Sun, 25 Feb 2024 16:23:32 -0600 Subject: [PATCH 1/3] Update to new installer of `zcash-haskell` --- zcash-haskell | 2 +- zenith.cabal | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/zcash-haskell b/zcash-haskell index 75cc947..ef93147 160000 --- a/zcash-haskell +++ b/zcash-haskell @@ -1 +1 @@ -Subproject commit 75cc947dda2dd24acd166cf17fadd5fb3243c22a +Subproject commit ef93147f22a72cf3a5ffc2db686626d75704024a diff --git a/zenith.cabal b/zenith.cabal index 148635e..adf7787 100644 --- a/zenith.cabal +++ b/zenith.cabal @@ -62,6 +62,7 @@ library , vector , vty , zcash-haskell + --pkgconfig-depends: rustzcash_wrapper default-language: GHC2021 executable zenith @@ -80,7 +81,7 @@ executable zenith , text , time , zenith - extra-libraries: rustzcash_wrapper + pkgconfig-depends: rustzcash_wrapper default-language: GHC2021 test-suite zenith-tests @@ -102,5 +103,5 @@ test-suite zenith-tests , hspec , zcash-haskell , zenith - extra-libraries: rustzcash_wrapper + pkgconfig-depends: rustzcash_wrapper default-language: GHC2021 From 74b9de2a9c995ad823fadf15ecd0d81648faa1c1 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Sun, 25 Feb 2024 16:29:57 -0600 Subject: [PATCH 2/3] Update cabal.project --- cabal.project | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cabal.project b/cabal.project index cf9dbbc..8fa9866 100644 --- a/cabal.project +++ b/cabal.project @@ -1,6 +1,6 @@ packages: - ./*.cabal zcash-haskell/zcash-haskell.cabal + ./*.cabal with-compiler: ghc-9.4.8 From 12be74fcd6cb8bd5660c841c67150e1ff05ba81c Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Mon, 26 Feb 2024 09:52:30 -0600 Subject: [PATCH 3/3] Implement new custom `cabal` build --- Setup.hs | 101 +++++++++++++++++++++++++++++++++++++++++++++++++- cabal.project | 2 +- configure | 6 +++ zcash-haskell | 2 +- zenith.cabal | 21 ++++++----- 5 files changed, 119 insertions(+), 13 deletions(-) create mode 100755 configure diff --git a/Setup.hs b/Setup.hs index 4cf4c9c..3ca9c28 100644 --- a/Setup.hs +++ b/Setup.hs @@ -1,17 +1,93 @@ +import Control.Exception (throw) +import Control.Monad (forM_, when) +import Data.Maybe (isNothing) import Distribution.PackageDescription import Distribution.Simple import Distribution.Simple.LocalBuildInfo (LocalBuildInfo(..), localPkgDescr) import Distribution.Simple.PreProcess +import Distribution.Simple.Program.Find + ( defaultProgramSearchPath + , findProgramOnSearchPath + ) import Distribution.Simple.Setup -import System.Directory (getCurrentDirectory) +import Distribution.Simple.Utils + ( IODataMode(IODataModeBinary) + , maybeExit + , rawSystemStdInOut + ) +import Distribution.Verbosity (Verbosity) +import qualified Distribution.Verbosity as Verbosity +import System.Directory + ( XdgDirectory(..) + , copyFile + , createDirectory + , createDirectoryIfMissing + , doesDirectoryExist + , doesFileExist + , getCurrentDirectory + , getDirectoryContents + , getHomeDirectory + , getXdgDirectory + ) +import System.Environment import System.FilePath (()) +import Text.Regex +import Text.Regex.Base main :: IO () main = defaultMainWithHooks hooks where hooks = simpleUserHooks - {confHook = \a flags -> confHook simpleUserHooks a flags >>= rsAddDirs} + { preConf = + \_ flags -> do + prepDeps (fromFlag $ configVerbosity flags) + pure emptyHookedBuildInfo + --, confHook = \a flags -> confHook simpleUserHooks a flags >>= rsAddDirs + } + +execCargo :: Verbosity -> String -> [String] -> IO () +execCargo verbosity command args = do + cargoPath <- + findProgramOnSearchPath Verbosity.silent defaultProgramSearchPath "cargo" + dir <- getCurrentDirectory + let cargoExec = + case cargoPath of + Just (p, _) -> p + Nothing -> "cargo" + cargoArgs = command : args + workingDir = Just (dir rsFolder) + thirdComponent (_, _, c) = c + maybeExit . fmap thirdComponent $ + rawSystemStdInOut + verbosity + cargoExec + cargoArgs + workingDir + Nothing + Nothing + IODataModeBinary + +rsMake :: Verbosity -> IO () +rsMake verbosity = do + execCargo verbosity "cbuild" [] + +prepDeps :: Verbosity -> IO () +prepDeps verbosity = do + ldPath <- lookupEnv "LD_LIBRARY_PATH" + pkgPath <- lookupEnv "PKG_CONFIG_PATH" + if maybe False (matchTest (mkRegex ".*zcash-haskell.*")) ldPath && + maybe False (matchTest (mkRegex ".*zcash-haskell.*")) pkgPath + then do + execCargo verbosity "cbuild" [] + localData <- getXdgDirectory XdgData "zcash-haskell" + createDirectoryIfMissing True localData + dir <- getCurrentDirectory + let rustLibDir = + dir rsFolder "target/x86_64-unknown-linux-gnu/debug" + copyDir rustLibDir localData + else throw $ + userError "Paths not set correctly, please run the 'configure' script." rsFolder :: FilePath rsFolder = "zcash-haskell/librustzcash-wrapper" @@ -32,3 +108,24 @@ rsAddDirs lbi' = do , extraLibDirs = rustLibDir : extraLibDirs libBuild } pure $ updateLbi lbi' + +copyDir :: FilePath -> FilePath -> IO () +copyDir src dst = do + whenM (not <$> doesDirectoryExist src) $ + throw (userError "source does not exist") + --whenM (doesFileOrDirectoryExist dst) $ + --throw (userError "destination already exists") + createDirectoryIfMissing True dst + content <- getDirectoryContents src + let xs = filter (`notElem` [".", ".."]) content + forM_ xs $ \name -> do + let srcPath = src name + let dstPath = dst name + isDirectory <- doesDirectoryExist srcPath + if isDirectory + then copyDir srcPath dstPath + else copyFile srcPath dstPath + where + doesFileOrDirectoryExist x = orM [doesDirectoryExist x, doesFileExist x] + orM xs = or <$> sequence xs + whenM s r = s >>= flip when r diff --git a/cabal.project b/cabal.project index 8fa9866..cf9dbbc 100644 --- a/cabal.project +++ b/cabal.project @@ -1,6 +1,6 @@ packages: - zcash-haskell/zcash-haskell.cabal ./*.cabal + zcash-haskell/zcash-haskell.cabal with-compiler: ghc-9.4.8 diff --git a/configure b/configure new file mode 100755 index 0000000..df9fc8d --- /dev/null +++ b/configure @@ -0,0 +1,6 @@ +#!/bin/bash + +echo "export PKG_CONFIG_PATH=$HOME/.local/share/zcash-haskell:\$PKG_CONFIG_PATH" | tee -a ~/.bashrc +echo "export LD_LIBRARY_PATH=$HOME/.local/share/zcash-haskell:\$LD_LIBRARY_PATH" | tee -a ~/.bashrc +source ~/.bashrc +cd zcash-haskell && cabal build diff --git a/zcash-haskell b/zcash-haskell index ef93147..419f041 160000 --- a/zcash-haskell +++ b/zcash-haskell @@ -1 +1 @@ -Subproject commit ef93147f22a72cf3a5ffc2db686626d75704024a +Subproject commit 419f041ca9d1dd921673721c56a673fe1dc058e8 diff --git a/zenith.cabal b/zenith.cabal index adf7787..d3e5b78 100644 --- a/zenith.cabal +++ b/zenith.cabal @@ -1,6 +1,6 @@ cabal-version: 3.0 name: zenith -version: 0.4.2.1 +version: 0.4.3.0 license: MIT license-file: LICENSE author: Rene Vergara @@ -18,10 +18,12 @@ common warnings custom-setup setup-depends: - base >= 4.7 && < 5 - , Cabal >= 3.0.0.0 + base >= 4.12 && < 5 + , Cabal >= 3.2.0.0 , directory >= 1.3.6.0 , filepath >= 1.3.0.2 + , regex-base + , regex-compat library import: warnings @@ -39,7 +41,7 @@ library Clipboard , aeson , array - , base >=4.7 && <5 + , base >=4.12 && <5 , base64-bytestring , brick , bytestring @@ -63,7 +65,7 @@ library , vty , zcash-haskell --pkgconfig-depends: rustzcash_wrapper - default-language: GHC2021 + default-language: Haskell2010 executable zenith import: warnings @@ -71,7 +73,7 @@ executable zenith hs-source-dirs: app build-depends: - base >=4.7 && <5 + base >=4.12 && <5 , brick , bytestring , configurator @@ -81,8 +83,9 @@ executable zenith , text , time , zenith + , zcash-haskell pkgconfig-depends: rustzcash_wrapper - default-language: GHC2021 + default-language: Haskell2010 test-suite zenith-tests import: warnings @@ -91,7 +94,7 @@ test-suite zenith-tests hs-source-dirs: test build-depends: - base >=4.7 && <5 + base >=4.12 && <5 , bytestring , configurator , data-default @@ -104,4 +107,4 @@ test-suite zenith-tests , zcash-haskell , zenith pkgconfig-depends: rustzcash_wrapper - default-language: GHC2021 + default-language: Haskell2010