diff --git a/cddl/Setup.hs b/cddl/Setup.hs new file mode 100644 index 00000000000..0f0c409fcab --- /dev/null +++ b/cddl/Setup.hs @@ -0,0 +1,70 @@ +import Prelude + +import Data.Maybe + ( fromJust + ) +import Distribution.Simple + ( Args + , UserHooks (..) + , defaultMainWithHooks + , simpleUserHooks + ) +import Distribution.Simple.LocalBuildInfo + ( LocalBuildInfo (..), + ) +import Distribution.Simple.Setup + ( BuildFlags (..) + , ConfigFlags (..) + , fromFlag + ) +import Distribution.Simple.UserHooks + ( UserHooks (..) + ) +import Distribution.Simple.Utils + ( rawSystemExit + ) +import System.Directory + ( getCurrentDirectory + ) + +import qualified Distribution.PackageDescription as Pkg + +main :: IO () +main = + defaultMainWithHooks + simpleUserHooks + { confHook = rustConfHook + , buildHook = rustBuildHook + } + +rustConfHook + :: (Pkg.GenericPackageDescription, Pkg.HookedBuildInfo) + -> ConfigFlags + -> IO LocalBuildInfo +rustConfHook (description, buildInfo) flags = do + localBuildInfo <- confHook simpleUserHooks (description, buildInfo) flags + let packageDescription = localPkgDescr localBuildInfo + let library = fromJust $ Pkg.library packageDescription + let libraryBuildInfo = Pkg.libBuildInfo library + dir <- getCurrentDirectory + return localBuildInfo + { localPkgDescr = packageDescription + { Pkg.library = Just library + { Pkg.libBuildInfo = libraryBuildInfo + { Pkg.extraLibDirs = (dir ++ "/target/release") : Pkg.extraLibDirs libraryBuildInfo + } + } + } + } + +rustBuildHook + :: Pkg.PackageDescription + -> LocalBuildInfo + -> UserHooks + -> BuildFlags + -> IO () +rustBuildHook description localBuildInfo hooks flags = do + putStrLn "[🦀] Compiling Rust dependencies..." + putStrLn "[🦀] cargo build --release" + rawSystemExit (fromFlag $ buildVerbosity flags) "cargo" ["build", "--release"] + buildHook simpleUserHooks description localBuildInfo hooks flags diff --git a/cddl/cbits/libcddl.a b/cddl/cbits/libcddl.a deleted file mode 100644 index 9ec3f4d2f81..00000000000 Binary files a/cddl/cbits/libcddl.a and /dev/null differ diff --git a/cddl/cddl.cabal b/cddl/cddl.cabal index 03018e43bea..0e3a05ee3b1 100644 --- a/cddl/cddl.cabal +++ b/cddl/cddl.cabal @@ -10,8 +10,14 @@ author: KtorZ maintainer: matthias.benkort@cardanofoundation.org license: Apache-2.0 license-files: LICENSE -build-type: Simple -extra-source-files: cbits/libcddl.h +build-type: Custom +extra-source-files: Setup.hs + cbits/libcddl.h + +custom-setup + setup-depends: , base + , directory + , Cabal common project-config default-language: Haskell2010 @@ -46,7 +52,6 @@ test-suite unit Paths_cddl build-depends: , base , base16-bytestring - , bytestring , cddl , hspec , text