From c41ce2f74ef146046e3c9ffaf5703a0cde32fad8 Mon Sep 17 00:00:00 2001 From: IvantheTricourne Date: Thu, 20 Apr 2023 20:06:07 +0000 Subject: [PATCH 1/8] Use modified setup for building vendored libsecp256k1 --- .gitmodules | 3 +++ Setup.hs | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++-- secp256k1 | 1 + 3 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 .gitmodules create mode 160000 secp256k1 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/Setup.hs b/Setup.hs index 9a994af..6a28ec0 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 "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" : "--prefix=/usr" : 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 \ No newline at end of file diff --git a/secp256k1 b/secp256k1 new file mode 160000 index 0000000..a6f4bcf --- /dev/null +++ b/secp256k1 @@ -0,0 +1 @@ +Subproject commit a6f4bcf6e1025f88597d3fd569899178570917c6 From 9da92bc53d0e30fa578d2490760825249d2dc2a5 Mon Sep 17 00:00:00 2001 From: Ilya Ostrovskiy Date: Fri, 21 Apr 2023 13:10:39 -0400 Subject: [PATCH 2/8] we're building secp256k1 now, so no need for it to be in pkg-config --- package.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/package.yaml b/package.yaml index 2be2a10..e2fa9c0 100644 --- a/package.yaml +++ b/package.yaml @@ -22,8 +22,6 @@ dependencies: - transformers >= 0.4.0.0 && <1.0 library: source-dirs: src - pkg-config-dependencies: - - libsecp256k1 tests: spec: main: Main.hs From 0dcdcc0c742bd0555dbf36d819840c236437b74c Mon Sep 17 00:00:00 2001 From: Ilya Ostrovskiy Date: Fri, 21 Apr 2023 13:11:19 -0400 Subject: [PATCH 3/8] use sh libtoolize so that PATHs get properly picked up on most systems, and enable schnorr as this lib has bindings to it --- Setup.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Setup.hs b/Setup.hs index 6a28ec0..c8cc601 100644 --- a/Setup.hs +++ b/Setup.hs @@ -26,7 +26,7 @@ runInRepo v prog args envM = rawSystemIOWithEnv v autogen :: Args -> ConfigFlags -> IO HookedBuildInfo autogen _ flags = do - maybeExit $ runInRepo v "libtoolize" [] Nothing + maybeExit $ runInRepo v "sh" ["libtoolize"] Nothing maybeExit $ runInRepo v "sh" ["./autogen.sh"] Nothing return emptyHookedBuildInfo where @@ -40,7 +40,7 @@ configure args flags pd lbi = do args' = args ++ ["--with-gcc=" ++ ccProg] maybeExit $ runInRepo v "sh" args' (Just env') where - args = "./configure" : "--enable-module-recovery" : "--prefix=/usr" : configureArgs False flags + 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) From 48e166d6be0c6df50d8e143e30a966e3265a9a7b Mon Sep 17 00:00:00 2001 From: Ilya Ostrovskiy Date: Fri, 21 Apr 2023 13:12:15 -0400 Subject: [PATCH 4/8] depend on secp256k1 0.2.0, since that what this lib seems to assume, whereas the HEAD that was submoduled is... well, master... --- secp256k1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/secp256k1 b/secp256k1 index a6f4bcf..21ffe4b 160000 --- a/secp256k1 +++ b/secp256k1 @@ -1 +1 @@ -Subproject commit a6f4bcf6e1025f88597d3fd569899178570917c6 +Subproject commit 21ffe4b22a9683cf24ae0763359e401d1284cc7a From 9b7975c841da4cdb15a085e0a15dff2372149a10 Mon Sep 17 00:00:00 2001 From: Ilya Ostrovskiy Date: Fri, 21 Apr 2023 13:17:06 -0400 Subject: [PATCH 5/8] install libtoolize in travis so we can build, and remove libsecp256k1 dep in travis since we're building our own --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 37915d56f73b38656f0aab5bb02b191b8931d140 Mon Sep 17 00:00:00 2001 From: Ilya Ostrovskiy Date: Fri, 21 Apr 2023 13:41:30 -0400 Subject: [PATCH 6/8] actually build the library using our custom setup, add no-error on deprecations since Prim marks them as well --- libsecp256k1.cabal | 22 +++++++++++++++++----- package.yaml | 17 +++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/libsecp256k1.cabal b/libsecp256k1.cabal index c064342..5e4e51b 100644 --- a/libsecp256k1.cabal +++ b/libsecp256k1.cabal @@ -1,6 +1,6 @@ -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 @@ -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 e2fa9c0..e9de957 100644 --- a/package.yaml +++ b/package.yaml @@ -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,6 +23,17 @@ dependencies: - transformers >= 0.4.0.0 && <1.0 library: source-dirs: src + 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 @@ -34,3 +46,8 @@ tests: - hspec - libsecp256k1 - HUnit + +custom-setup: + dependencies: + - base >= 4.8 && < 5 + - Cabal >= 1.10 \ No newline at end of file From 8326c01270e5acd29dee0e34809ce58629192fdc Mon Sep 17 00:00:00 2001 From: Ilya Ostrovskiy Date: Fri, 21 Apr 2023 13:50:54 -0400 Subject: [PATCH 7/8] bump version to 0.2.0, since we're depending on libsecp256k1-0.2.0 --- libsecp256k1.cabal | 2 +- package.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libsecp256k1.cabal b/libsecp256k1.cabal index 5e4e51b..72deb25 100644 --- a/libsecp256k1.cabal +++ b/libsecp256k1.cabal @@ -5,7 +5,7 @@ cabal-version: 1.24 -- 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 diff --git a/package.yaml b/package.yaml index e9de957..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 From 6a8fa72e0668bdb30a40c56b24755d7447a2848b Mon Sep 17 00:00:00 2001 From: Ilya Ostrovskiy Date: Fri, 21 Apr 2023 14:29:24 -0400 Subject: [PATCH 8/8] properly invoke libtoolize on non-macOS --- Setup.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Setup.hs b/Setup.hs index c8cc601..246ea06 100644 --- a/Setup.hs +++ b/Setup.hs @@ -26,7 +26,7 @@ runInRepo v prog args envM = rawSystemIOWithEnv v autogen :: Args -> ConfigFlags -> IO HookedBuildInfo autogen _ flags = do - maybeExit $ runInRepo v "sh" ["libtoolize"] Nothing + maybeExit $ runInRepo v "sh" [ "-c", "libtoolize"] Nothing maybeExit $ runInRepo v "sh" ["./autogen.sh"] Nothing return emptyHookedBuildInfo where @@ -62,4 +62,4 @@ clean _ flags = do runInRepo v "make" ["clean"] Nothing return emptyHookedBuildInfo where - v = fromFlag $ cleanVerbosity flags \ No newline at end of file + v = fromFlag $ cleanVerbosity flags