Skip to content

Use modified setup for building vendored libsecp256k1 #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "secp256k1"]
path = secp256k1
url = https://github.com/bitcoin-core/secp256k1.git
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ addons:
apt:
packages:
- libgmp-dev
- libsecp256k1-dev
- libtool

before_install:
# Download and unpack the stack executable
Expand Down
67 changes: 65 additions & 2 deletions Setup.hs
Original file line number Diff line number Diff line change
@@ -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
24 changes: 18 additions & 6 deletions libsecp256k1.cabal
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,7 +16,7 @@ maintainer: [email protected]
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
Expand All @@ -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
Expand All @@ -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
Expand Down
21 changes: 18 additions & 3 deletions package.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -36,3 +46,8 @@ tests:
- hspec
- libsecp256k1
- HUnit

custom-setup:
dependencies:
- base >= 4.8 && < 5
- Cabal >= 1.10
1 change: 1 addition & 0 deletions secp256k1
Submodule secp256k1 added at 21ffe4