From 9713203e2bd10d5b3b623561564c82a8d7614ec8 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Sun, 25 Feb 2024 15:22:53 -0600 Subject: [PATCH] Update installation package --- CHANGELOG.md | 4 +++ Setup.hs | 49 +++++++++++++++++++++++++++++++-- configure | 4 +-- librustzcash-wrapper/Cargo.toml | 3 -- zcash-haskell.cabal | 11 ++++++-- 5 files changed, 61 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6b0375..a2fed36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Update installation to `cabal` +### Removed + +- `Makefile` ## [0.3.0] diff --git a/Setup.hs b/Setup.hs index ad6bb6a..5efaca2 100644 --- a/Setup.hs +++ b/Setup.hs @@ -1,3 +1,5 @@ +import Control.Exception (throw) +import Control.Monad (forM_, when) import Data.Maybe (fromMaybe) import Distribution.PackageDescription import Distribution.Simple @@ -15,8 +17,23 @@ import Distribution.Simple.Utils ) import Distribution.Verbosity (Verbosity) import qualified Distribution.Verbosity as Verbosity -import System.Directory (getCurrentDirectory) +import GHC.Generics +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 @@ -58,10 +75,13 @@ execCargo verbosity command args = do IODataModeBinary rsMake :: Verbosity -> IO () -rsMake verbosity = execCargo verbosity "cbuild" [] +rsMake verbosity = do + execCargo verbosity "cbuild" [] rsAddDirs :: LocalBuildInfo -> IO LocalBuildInfo rsAddDirs lbi' = do + localData <- getXdgDirectory XdgData "zcash-haskell" + createDirectoryIfMissing True localData dir <- getCurrentDirectory let rustIncludeDir = dir rsFolder "target/x86_64-unknown-linux-gnu/debug" @@ -73,8 +93,12 @@ rsAddDirs lbi' = do updateLibBi libBuild = libBuild { includeDirs = rustIncludeDir : includeDirs libBuild + , extraLibs = "rustzcash_wrapper" : extraLibs libBuild , extraLibDirs = rustLibDir : extraLibDirs libBuild + , extraBundledLibs = "rustzcash_wrapper" : extraBundledLibs libBuild + , ldOptions = ("-L" ++ localData) : ldOptions libBuild } + copyDir rustLibDir localData pure $ updateLbi lbi' rsClean :: Verbosity -> IO () @@ -93,3 +117,24 @@ applyUnlessM :: FlagName -> ConfigFlags -> (a -> IO a) -> a -> IO a applyUnlessM name flags apply a | cabalFlag name flags = pure a | otherwise = apply a + +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/configure b/configure index 21dc7bb..bb38dfe 100755 --- a/configure +++ b/configure @@ -1,5 +1,5 @@ #!/bin/bash -echo "export PKG_CONFIG_PATH=$(pwd)/librustzcash-wrapper/target/x86_64-unknown-linux-gnu/debug:\$PKG_CONFIG_PATH" | tee -a ~/.bashrc -echo "export LD_LIBRARY_PATH=$(pwd)/librustzcash-wrapper/target/x86_64-unknown-linux-gnu/debug:\$LD_LIBRARY_PATH" | tee -a ~/.bashrc +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 diff --git a/librustzcash-wrapper/Cargo.toml b/librustzcash-wrapper/Cargo.toml index cf068e4..fa4fb55 100644 --- a/librustzcash-wrapper/Cargo.toml +++ b/librustzcash-wrapper/Cargo.toml @@ -4,9 +4,6 @@ version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[lib] -crate-type=["staticlib"] - [dependencies] haskell-ffi.git = "https://github.com/BeFunctional/haskell-rust-ffi.git" haskell-ffi.rev = "2bf292e2e56eac8e9fb0fb2e1450cf4a4bd01274" diff --git a/zcash-haskell.cabal b/zcash-haskell.cabal index 1a54fba..79b6db2 100644 --- a/zcash-haskell.cabal +++ b/zcash-haskell.cabal @@ -1,11 +1,11 @@ -cabal-version: 3.0 +cabal-version: 3.8 -- This file has been generated from package.yaml by hpack version 0.36.0. -- -- see: https://github.com/sol/hpack name: zcash-haskell -version: 0.4.2.2 +version: 0.4.2.3 synopsis: Utilities to interact with the Zcash blockchain description: Please see the README on the repo at category: Blockchain @@ -15,6 +15,8 @@ copyright: (c)2022-2024 Vergara Technologies LLC license: MIT license-file: LICENSE build-type: Custom +extra-source-files: + Setup.hs extra-doc-files: README.md CHANGELOG.md @@ -25,6 +27,9 @@ custom-setup , Cabal >= 3.0.0.0 , directory >= 1.3.6.0 , filepath >= 1.3.0.2 + , envy + , regex-compat + , regex-base library exposed-modules: @@ -69,5 +74,5 @@ test-suite zcash-haskell-test , hspec , text , zcash-haskell - extra-libraries: rustzcash_wrapper + pkgconfig-depends: rustzcash_wrapper default-language: GHC2021