nim-bearssl/regenerate.sh
Jacek Sieka c4aec8b664
split decls into separate modules in bearssl/abi (#27)
* split `decls.nim` into smaller modules - allows using parts of the ABI
without compiling all of `bearssl`
* deprecate functions with `Br` prefix - there are duplicate exports
both with and without `Br` for the same function and we use both in
consumers like `chronos` and `libp2p`
* fix several cases of incorrectly mapped types
* use `var` for certain arguments that can't be `nil`
* add script to regenerate ABI with `c2nim`
* consistently use `uint` for length (`int` was sometimes used)

The Split likely needs more cleanup work - this is a first cut to get
the idea in place.

In the new layout, `bearssl/abi/` contains "raw" nim mappings while
hand-written helpers are in `bearssl/`.
2022-06-14 19:33:00 +02:00

41 lines
1.3 KiB
Bash

#!/bin/sh
mkdir -p gen
cp bearssl/csources/inc/*.h gen
# c2nim gets confused by #ifdef inside struct's
unifdef -m -UBR_DOXYGEN_IGNORE gen/*.h
# TODO: several things broken in c2nim 0.9.18
# https://github.com/nim-lang/c2nim/issues/239
# https://github.com/nim-lang/c2nim/issues/240
# https://github.com/nim-lang/c2nim/issues/241
# https://github.com/nim-lang/c2nim/issues/242
[[ $(c2nim -v) == "0.9.18" ]] || echo "Different c2nim used, check the code"
c2nim --header --importc --nep1 --prefix:br_ --prefix:BR_ --skipinclude --cdecl --skipcomments gen/*.h
rm gen/*.h
# Fix cosmetic and ease-of-use issues
sed -i \
-e "s/int16T/int16/g" \
-e "s/int32T/int32/g" \
-e "s/int64T/int64/g" \
-e "s/cuchar/byte/g" \
-e "s/cdecl/importcFunc/g" \
-e "s/csize_t/uint/g" \
gen/*.nim
# The functions taking a "Context" don't allow `nil` being passed to them - use
# `var` instead - ditto for "output" parameters like length
sed -i \
-e 's/ctx: ptr \(.*\)Context/ctx: var \1Context/g' \
-e 's/ctx: ptr \(.*\)Keys/ctx: var \1Keys/g' \
-e 's/hc: ptr \(.*\)Context/hc: var \1Context/g' \
-e 's/sc: ptr \(.*\)Context/sc: var \1Context/g' \
-e 's/cc: ptr \(.*\)Context/cc: var \1Context/g' \
-e 's/kc: ptr \(.*\)Context/kc: var \1Context/g' \
-e 's/xwc: ptr \(.*\)Context/xwc: var \1Context/g' \
-e 's/len: ptr uint/len: var uint/g' \
gen/*.nim