diff --git a/.gitignore b/.gitignore index becd7f9..dab42ad 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ * !*/ !*.* +build diff --git a/Readme.md b/Readme.md index c51a20e..cc0ebc7 100644 --- a/Readme.md +++ b/Readme.md @@ -2,5 +2,4 @@ ngtcp2 for Nim ============== Wrapper around the [ngtcp2](https://github.com/ngtcp2/ngtcp2) C library for -[Nim](https://nim-lang.org/). Requires [CMake](https://cmake.org/) to be -installed. +[Nim](https://nim-lang.org/). diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..4e31628 --- /dev/null +++ b/build.sh @@ -0,0 +1,24 @@ +#!/bin/bash +root=$(dirname "$0") + +# install nimterop, if not already installed +if ! [ -x "$(command -v toast)" ]; then + nimble install -y nimterop@0.6.11 +fi + +# run cmake on ngtcp2 sources +cmake -S "${root}/sources" -B "${root}/build" + +# socket definitions +cat "${root}/sockets.nim" > "${root}/ngtcp2.nim" + +# dividing line +echo >> "${root}/ngtcp2.nim" + +# generate nim wrapper with nimterop +toast \ + --pnim \ + --preprocess \ + --includeDirs="${root}/sources/lib/includes" \ + --includeDirs="${root}/build/lib/includes" \ + "${root}/sources/lib/includes/ngtcp2/ngtcp2.h" >> "${root}/ngtcp2.nim" diff --git a/ngtcp2.nimble b/ngtcp2.nimble index c16a85f..4731ef3 100644 --- a/ngtcp2.nimble +++ b/ngtcp2.nimble @@ -5,9 +5,3 @@ description = "Nim wrapper around the ngtcp2 library" license = "MIT" requires "nim >= 1.2.6" -requires "nimterop >= 0.6.11 & < 0.7.0" - -import os - -after install: - exec "nim c -r " & currentSourcePath.parentDir/"ngtcp2"/"make.nim" diff --git a/ngtcp2/make.nim b/ngtcp2/make.nim deleted file mode 100644 index cce1830..0000000 --- a/ngtcp2/make.nim +++ /dev/null @@ -1,14 +0,0 @@ -import nimterop/build -import sources - -static: - gitPull( - "https://github.com/ngtcp2/ngtcp2", - checkout="d234d50", - outdir=ngtcp2src - ) - cmake( - ngtcp2src, - check="lib"/"includes"/"ngtcp2"/"version.h", - flags="." - ) diff --git a/ngtcp2/sources.nim b/ngtcp2/sources.nim deleted file mode 100644 index e0a4214..0000000 --- a/ngtcp2/sources.nim +++ /dev/null @@ -1,3 +0,0 @@ -import nimterop/build - -const ngtcp2src* = getProjectCacheDir("ngtcp2") diff --git a/sockets.nim b/sockets.nim new file mode 100644 index 0000000..0bbae5a --- /dev/null +++ b/sockets.nim @@ -0,0 +1,13 @@ +# Import socket definitions from system + +when defined(windows): + {.passL: "-lws2_32".} + const socketheader = "" +else: + const socketheader = "" + +type + sockaddr* + {.header: socketheader, importc: "sockaddr".} = object + sockaddr_storage* + {.header: socketheader, importc: "sockaddr_storage".} = object