diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..d65ad36 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "secp256k1"] + path = secp256k1 + url = https://github.com/bitcoin-core/secp256k1.git diff --git a/.travis.yml b/.travis.yml index 7a8dead..2a68737 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,7 @@ addons: apt: packages: - libgmp-dev - - libsecp256k1-dev + - libtool before_install: # Download and unpack the stack executable diff --git a/Setup.hs b/Setup.hs index 9a994af..246ea06 100644 --- a/Setup.hs +++ b/Setup.hs @@ -1,2 +1,65 @@ -import Distribution.Simple -main = defaultMain +import Control.Monad +import Distribution.PackageDescription +import Distribution.Simple +import Distribution.Simple.LocalBuildInfo +import Distribution.Simple.Setup +import Distribution.Simple.Utils +import Distribution.Verbosity +import System.Environment +import System.Exit + +main :: IO () +main = defaultMainWithHooks autoconfUserHooks + { preConf = autogen + , postConf = configure + , preBuild = make + , preClean = clean + } + +runInRepo :: Verbosity + -> FilePath + -> [String] + -> Maybe [(String, String)] + -> IO ExitCode +runInRepo v prog args envM = rawSystemIOWithEnv v + prog args (Just "secp256k1") envM Nothing Nothing Nothing + +autogen :: Args -> ConfigFlags -> IO HookedBuildInfo +autogen _ flags = do + maybeExit $ runInRepo v "sh" [ "-c", "libtoolize"] Nothing + maybeExit $ runInRepo v "sh" ["./autogen.sh"] Nothing + return emptyHookedBuildInfo + where + v = fromFlag $ configVerbosity flags + +configure :: Args -> ConfigFlags -> PackageDescription -> LocalBuildInfo -> IO () +configure args flags pd lbi = do + (ccProg, ccFlags) <- configureCCompiler v programConfig + env <- getEnvironment + let env' = appendToEnvironment ("CFLAGS", unwords ccFlags) env + args' = args ++ ["--with-gcc=" ++ ccProg] + maybeExit $ runInRepo v "sh" args' (Just env') + where + args = "./configure" : "--enable-module-recovery" : "--enable-module-schnorrsig" : configureArgs False flags + v = fromFlag $ configVerbosity flags + appendToEnvironment (key, val) [] = [(key, val)] + appendToEnvironment (key, val) (kv@(k, v) : rest) + | key == k = (key, v ++ " " ++ val) : rest + | otherwise = kv : appendToEnvironment (key, val) rest + programConfig = withPrograms lbi + +make :: Args -> BuildFlags -> IO HookedBuildInfo +make _ flags = do + runInRepo v "make" ["clean"] Nothing + runInRepo v "make" [] Nothing + runInRepo v "make" ["install"] Nothing + return emptyHookedBuildInfo + where + v = fromFlag $ buildVerbosity flags + +clean :: Args -> CleanFlags -> IO HookedBuildInfo +clean _ flags = do + runInRepo v "make" ["clean"] Nothing + return emptyHookedBuildInfo + where + v = fromFlag $ cleanVerbosity flags diff --git a/libsecp256k1.cabal b/libsecp256k1.cabal index c064342..72deb25 100644 --- a/libsecp256k1.cabal +++ b/libsecp256k1.cabal @@ -1,11 +1,11 @@ -cabal-version: 1.12 +cabal-version: 1.24 --- This file has been generated from package.yaml by hpack version 0.34.4. +-- This file has been generated from package.yaml by hpack version 0.35.1. -- -- see: https://github.com/sol/hpack name: libsecp256k1 -version: 0.1.0 +version: 0.2.0 synopsis: Bindings for secp256k1 description: Sign and verify signatures using the secp256k1 library. category: Crypto @@ -16,7 +16,7 @@ maintainer: keagan.mcclelland@gmail.com copyright: (c) 2017 Jean-Pierre Rupp; (c) 2020 Haskoin Developers; (c) 2022 Keagan McClelland license: MIT license-file: LICENSE -build-type: Simple +build-type: Custom extra-source-files: CHANGELOG.md README.md @@ -25,6 +25,11 @@ source-repository head type: git location: https://github.com/ProofOfKeags/libsecp256k1-haskell.git +custom-setup + setup-depends: + Cabal >=1.10 + , base >=4.8 && <5 + library exposed-modules: Crypto.Secp256k1 @@ -35,8 +40,15 @@ library Paths_libsecp256k1 hs-source-dirs: src - pkgconfig-depends: - libsecp256k1 + cc-options: -DHAVE_CONFIG_H -Wno-error=deprecated-declarations + include-dirs: + secp256k1 + secp256k1/include + c-sources: + secp256k1/src/secp256k1.c + secp256k1/contrib/lax_der_parsing.c + secp256k1/src/precomputed_ecmult.c + secp256k1/src/precomputed_ecmult_gen.c build-depends: base >=4.9 && <5 , bytestring >=0.10.8 && <0.12 diff --git a/package.yaml b/package.yaml index 2be2a10..478e8af 100644 --- a/package.yaml +++ b/package.yaml @@ -1,5 +1,5 @@ name: libsecp256k1 -version: 0.1.0 +version: 0.2.0 synopsis: Bindings for secp256k1 description: Sign and verify signatures using the secp256k1 library. category: Crypto @@ -10,6 +10,7 @@ license: MIT license-file: LICENSE github: ProofOfKeags/libsecp256k1-haskell.git homepage: http://github.com/ProofOfKeags/secp256k1-haskell#readme +build-type: Custom extra-source-files: - CHANGELOG.md - README.md @@ -22,8 +23,17 @@ dependencies: - transformers >= 0.4.0.0 && <1.0 library: source-dirs: src - pkg-config-dependencies: - - libsecp256k1 + cc-options: + - -DHAVE_CONFIG_H + - -Wno-error=deprecated-declarations + c-sources: + - secp256k1/src/secp256k1.c + - secp256k1/contrib/lax_der_parsing.c + - secp256k1/src/precomputed_ecmult.c + - secp256k1/src/precomputed_ecmult_gen.c + include-dirs: + - secp256k1 + - secp256k1/include tests: spec: main: Main.hs @@ -36,3 +46,8 @@ tests: - hspec - libsecp256k1 - HUnit + +custom-setup: + dependencies: + - base >= 4.8 && < 5 + - Cabal >= 1.10 \ No newline at end of file diff --git a/secp256k1 b/secp256k1 new file mode 160000 index 0000000..21ffe4b --- /dev/null +++ b/secp256k1 @@ -0,0 +1 @@ +Subproject commit 21ffe4b22a9683cf24ae0763359e401d1284cc7a