Skip to content

Commit 1fbe5ed

Browse files
authored
Merge pull request #10 from prolic/master
C shim for static context to address Windows MinGW64 runtime failure
2 parents 9db4d62 + 2fb581e commit 1fbe5ed

File tree

6 files changed

+37
-10
lines changed

6 files changed

+37
-10
lines changed

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Set update schedule for GitHub Actions
2+
3+
version: 2
4+
updates:
5+
6+
- package-ecosystem: "github-actions"
7+
directory: "/"
8+
schedule:
9+
# Check for updates to GitHub Actions every week
10+
interval: "weekly"

.github/workflows/build.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@ jobs:
4646
name: Build
4747
runs-on: ${{ matrix.os }}
4848
steps:
49-
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b
49+
- uses: actions/checkout@v4
5050
name: Checkout
5151

52-
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b
52+
- uses: actions/checkout@v4
5353
name: Checkout bitcoin-core/secp256k1
5454
with:
5555
repository: bitcoin-core/secp256k1
56-
ref: 1ad5185cd42c0636104129fcc9f6a4bf9c67cc40
56+
ref: v0.5.1
5757
path: lib/secp256k1
5858

59-
- uses: haskell-actions/setup@64aa5146ed5bd91f181552b8b5fbe50fbd2bd3fe
59+
- uses: haskell-actions/setup@v2
6060
name: Setup Haskell
6161
id: setup-haskell
6262
with:
@@ -65,7 +65,7 @@ jobs:
6565

6666
- name: Cache
6767
id: cache
68-
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9
68+
uses: actions/cache@v4.2.3
6969
with:
7070
path: |
7171
${{ steps.setup-haskell.outputs.stack-root }}

cbits/hs_secp256k1_shim.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <secp256k1.h>
2+
3+
/* Returns the adress of the library's built-in context */
4+
const secp256k1_context* hs_secp256k1_content_static(void)
5+
{
6+
return secp256k1_context_static;
7+
}

libsecp256k1.cabal

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cabal-version: 1.12
55
-- see: https://github.com/sol/hpack
66

77
name: libsecp256k1
8-
version: 0.2.1
8+
version: 0.3.1
99
synopsis: Bindings for secp256k1
1010
description: Sign and verify signatures using the secp256k1 library.
1111
category: Crypto
@@ -35,6 +35,8 @@ library
3535
Paths_libsecp256k1
3636
hs-source-dirs:
3737
src
38+
c-sources:
39+
cbits/hs_secp256k1_shim.c
3840
default-extensions:
3941
ImportQualifiedPost
4042
pkgconfig-depends:

package.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: libsecp256k1
2-
version: 0.2.1
2+
version: 0.3.1
33
synopsis: Bindings for secp256k1
44
description: Sign and verify signatures using the secp256k1 library.
55
category: Crypto
@@ -29,6 +29,10 @@ library:
2929
source-dirs: src
3030
pkg-config-dependencies:
3131
- libsecp256k1
32+
hs-source-dirs:
33+
src
34+
c-sources:
35+
cbits/hs_secp256k1_shim.c
3236
tests:
3337
spec:
3438
main: Main.hs

src/Crypto/Secp256k1/Prim.hs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,12 @@ foreign import capi safe "secp256k1.h secp256k1_context_destroy"
302302
-- type serialization/parsing functions which require a context object to maintain
303303
-- API consistency, but currently do not require expensive precomputations or dynamic
304304
-- allocations.
305-
foreign import ccall unsafe "secp256k1.h secp256k1_context_no_precomp"
306-
contextNoPrecomp :: Ctx
305+
foreign import ccall unsafe "hs_secp256k1_content_static"
306+
c_contextStatic :: IO Ctx
307+
308+
{-# NOINLINE contextStatic #-}
309+
contextStatic :: Ctx
310+
contextStatic = unsafePerformIO c_contextStatic
307311

308312

309313
-- | Copy a secp256k1 context object into caller-provided memory.
@@ -445,7 +449,7 @@ foreign import capi safe "secp256k1.h secp256k1_context_set_error_callback"
445449
-- undefined.
446450
--
447451
-- When this function has not been called (or called with fn==NULL), then the
448-
-- default handler will be used. The library provides a default handler which
452+
-- default handler will be used. The library provides a default handler which
449453
-- writes the message to stderr and calls abort. This default handler can be
450454
-- replaced at link time if the preprocessor macro
451455
-- USE_EXTERNAL_DEFAULT_CALLBACKS is defined, which is the case if the build

0 commit comments

Comments
 (0)