Add cImport for multiple headers

This commit is contained in:
Ganesh Viswanathan 2020-04-22 22:11:30 -05:00
commit c1f46680f7
3 changed files with 99 additions and 37 deletions

42
tests/rsa.nim Normal file
View file

@ -0,0 +1,42 @@
import os
import strutils
import nimterop/[build, cimport]
setDefines(@["cryptoStd"])
getHeader("openssl/crypto.h")
const
basePath = cryptoPath.parentDir
FLAGS {.strdefine.} = ""
cPlugin:
import strutils
proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} =
sym.name = sym.name.strip(chars = {'_'}).replace("__", "_")
if sym.name in [
"AES_ENCRYPT", "AES_DECRYPT",
"BIO_CTRL_PENDING", "BIO_CTRL_WPENDING",
"BN_F_BNRAND", "BN_F_BNRAND_RANGE",
"CRYPTO_THREADID",
"EVP_CIPHER",
"OPENSSL_VERSION",
"PKCS7_ENCRYPT", "PKCS7_STREAM",
"SSL_TXT_ADH", "SSL_TXT_AECDH", "SSL_TXT_kECDHE"
]:
sym.name = "C_" & sym.name
cOverride:
proc OPENSSL_die*(assertion: cstring; file: cstring; line: cint) {.importc.}
cImport(@[
basePath / "rsa.h",
basePath / "err.h",
], recurse = true, flags = "-f:ast2 -s " & FLAGS)
{.passL: cryptoLPath.}
OpensslInit()
echo $OPENSSL_VERSION_TEXT