mirror of
https://github.com/logos-storage/constantine.git
synced 2026-01-08 16:13:14 +00:00
Bindings "filesystem" (#225)
* bindings structure * missed some renaming * add back the headers * path fixes * need to sleep at night * windows path mystery is unfathomable
This commit is contained in:
parent
1cb6c3d9e1
commit
4dc2610557
7
bindings/README.md
Normal file
7
bindings/README.md
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# Bindings generator
|
||||||
|
|
||||||
|
This folder holds the bindings generators for Constantine.
|
||||||
|
|
||||||
|
To create a new build, download install the [Nim programming language](https://nim-lang.org/install.html), navigate to Constantine's root folder and call `nimble bindings`.
|
||||||
|
|
||||||
|
Headers will be placed in "include" folder and static and dynamic libraries in "lib"
|
||||||
@ -468,12 +468,12 @@ proc genDynamicBindings(bindingsName, prefixNimMain: string) =
|
|||||||
# In the future, Constantine might use:
|
# In the future, Constantine might use:
|
||||||
# - heap-allocated sequences and objects manually managed or managed by destructors for multithreading.
|
# - heap-allocated sequences and objects manually managed or managed by destructors for multithreading.
|
||||||
# - heap-allocated strings for hex-string or decimal strings
|
# - heap-allocated strings for hex-string or decimal strings
|
||||||
echo "Compiling dynamic library: bindings/generated/" & libName
|
echo "Compiling dynamic library: lib/" & libName
|
||||||
exec "nim c -f " & flags & " --noMain -d:danger --app:lib --gc:arc " &
|
exec "nim c -f " & flags & " --noMain -d:danger --app:lib --gc:arc " &
|
||||||
" --panics:on " & # Defects are not catchable
|
" --panics:on " & # Defects are not catchable
|
||||||
" --verbosity:0 --hints:off --warnings:off " &
|
" --verbosity:0 --hints:off --warnings:off " &
|
||||||
" --nimMainPrefix:" & prefixNimMain &
|
" --nimMainPrefix:" & prefixNimMain &
|
||||||
" --out:" & libName & " --outdir:bindings/generated " &
|
" --out:" & libName & " --outdir:lib " &
|
||||||
" --nimcache:nimcache/bindings/" & bindingsName &
|
" --nimcache:nimcache/bindings/" & bindingsName &
|
||||||
" bindings/" & bindingsName & ".nim"
|
" bindings/" & bindingsName & ".nim"
|
||||||
|
|
||||||
@ -483,9 +483,9 @@ proc genDynamicBindings(bindingsName, prefixNimMain: string) =
|
|||||||
elif defined(macosx):
|
elif defined(macosx):
|
||||||
compile "lib" & bindingsName & ".dylib.arm", "--cpu:arm64 -l:'-target arm64-apple-macos11' -t:'-target arm64-apple-macos11'"
|
compile "lib" & bindingsName & ".dylib.arm", "--cpu:arm64 -l:'-target arm64-apple-macos11' -t:'-target arm64-apple-macos11'"
|
||||||
compile "lib" & bindingsName & ".dylib.x64", "--cpu:amd64 -l:'-target x86_64-apple-macos10.12' -t:'-target x86_64-apple-macos10.12'"
|
compile "lib" & bindingsName & ".dylib.x64", "--cpu:amd64 -l:'-target x86_64-apple-macos10.12' -t:'-target x86_64-apple-macos10.12'"
|
||||||
exec "lipo bindings/generated/lib" & bindingsName & ".dylib.arm " &
|
exec "lipo lib/lib" & bindingsName & ".dylib.arm " &
|
||||||
" bindings/generated/lib" & bindingsName & ".dylib.x64 " &
|
" lib/lib" & bindingsName & ".dylib.x64 " &
|
||||||
" -output bindings/generated/lib" & bindingsName & ".dylib -create"
|
" -output lib/lib" & bindingsName & ".dylib -create"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
compile "lib" & bindingsName & ".so"
|
compile "lib" & bindingsName & ".so"
|
||||||
@ -499,12 +499,12 @@ proc genStaticBindings(bindingsName, prefixNimMain: string) =
|
|||||||
# In the future, Constantine might use:
|
# In the future, Constantine might use:
|
||||||
# - heap-allocated sequences and objects manually managed or managed by destructors for multithreading.
|
# - heap-allocated sequences and objects manually managed or managed by destructors for multithreading.
|
||||||
# - heap-allocated strings for hex-string or decimal strings
|
# - heap-allocated strings for hex-string or decimal strings
|
||||||
echo "Compiling static library: bindings/generated/" & libName
|
echo "Compiling static library: lib/" & libName
|
||||||
exec "nim c -f " & flags & " --noMain -d:danger --app:staticLib --gc:arc " &
|
exec "nim c -f " & flags & " --noMain -d:danger --app:staticLib --gc:arc " &
|
||||||
" --panics:on " & # Defects are not catchable
|
" --panics:on " & # Defects are not catchable
|
||||||
" --verbosity:0 --hints:off --warnings:off " &
|
" --verbosity:0 --hints:off --warnings:off " &
|
||||||
" --nimMainPrefix:" & prefixNimMain &
|
" --nimMainPrefix:" & prefixNimMain &
|
||||||
" --out:" & libName & " --outdir:bindings/generated " &
|
" --out:" & libName & " --outdir:lib " &
|
||||||
" --nimcache:nimcache/bindings/" & bindingsName &
|
" --nimcache:nimcache/bindings/" & bindingsName &
|
||||||
" bindings/" & bindingsName & ".nim"
|
" bindings/" & bindingsName & ".nim"
|
||||||
|
|
||||||
@ -514,21 +514,21 @@ proc genStaticBindings(bindingsName, prefixNimMain: string) =
|
|||||||
elif defined(macosx):
|
elif defined(macosx):
|
||||||
compile "lib" & bindingsName & ".a.arm", "--cpu:arm64 -l:'-target arm64-apple-macos11' -t:'-target arm64-apple-macos11'"
|
compile "lib" & bindingsName & ".a.arm", "--cpu:arm64 -l:'-target arm64-apple-macos11' -t:'-target arm64-apple-macos11'"
|
||||||
compile "lib" & bindingsName & ".a.x64", "--cpu:amd64 -l:'-target x86_64-apple-macos10.12' -t:'-target x86_64-apple-macos10.12'"
|
compile "lib" & bindingsName & ".a.x64", "--cpu:amd64 -l:'-target x86_64-apple-macos10.12' -t:'-target x86_64-apple-macos10.12'"
|
||||||
exec "lipo bindings/generated/lib" & bindingsName & ".a.arm " &
|
exec "lipo lib/lib" & bindingsName & ".a.arm " &
|
||||||
" bindings/generated/lib" & bindingsName & ".a.x64 " &
|
" lib/lib" & bindingsName & ".a.x64 " &
|
||||||
" -output bindings/generated/lib" & bindingsName & ".a -create"
|
" -output lib/lib" & bindingsName & ".a -create"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
compile "lib" & bindingsName & ".a"
|
compile "lib" & bindingsName & ".a"
|
||||||
|
|
||||||
proc genHeaders(bindingsName: string) =
|
proc genHeaders(bindingsName: string) =
|
||||||
echo "Generating header: bindings/generated/" & bindingsName & ".h"
|
echo "Generating header: include/" & bindingsName & ".h"
|
||||||
exec "nim c -d:release -d:CttGenerateHeaders " &
|
exec "nim c -d:release -d:CttGenerateHeaders " &
|
||||||
" --verbosity:0 --hints:off --warnings:off " &
|
" --verbosity:0 --hints:off --warnings:off " &
|
||||||
" --out:" & bindingsName & "_gen_header.exe --outdir:bindings/generated " &
|
" --out:" & bindingsName & "_gen_header.exe --outdir:build " &
|
||||||
" --nimcache:nimcache/bindings/" & bindingsName & "_header" &
|
" --nimcache:nimcache/bindings/" & bindingsName & "_header" &
|
||||||
" bindings/" & bindingsName & ".nim"
|
" bindings/" & bindingsName & ".nim"
|
||||||
exec "bindings/generated/" & bindingsName & "_gen_header.exe bindings/generated"
|
exec "build/" & bindingsName & "_gen_header.exe include"
|
||||||
|
|
||||||
proc genParallelCmdRunner() =
|
proc genParallelCmdRunner() =
|
||||||
exec "nim c --verbosity:0 --hints:off --warnings:off -d:release --out:build/pararun --nimcache:nimcache/pararun helpers/pararun.nim"
|
exec "nim c --verbosity:0 --hints:off --warnings:off -d:release --out:build/pararun --nimcache:nimcache/pararun helpers/pararun.nim"
|
||||||
@ -549,23 +549,23 @@ task test_bindings, "Test C bindings":
|
|||||||
exec "mkdir -p build/testsuite"
|
exec "mkdir -p build/testsuite"
|
||||||
echo "--> Testing dynamically linked library"
|
echo "--> Testing dynamically linked library"
|
||||||
when not defined(windows):
|
when not defined(windows):
|
||||||
exec "gcc -Ibindings/generated -Lbindings/generated -o build/testsuite/t_libctt_bls12_381_dl tests/bindings/t_libctt_bls12_381.c -lgmp -lconstantine_bls12_381"
|
exec "gcc -Iinclude -Llib -o build/testsuite/t_libctt_bls12_381_dl examples_c/t_libctt_bls12_381.c -lgmp -lconstantine_bls12_381"
|
||||||
exec "LD_LIBRARY_PATH=bindings/generated ./build/testsuite/t_libctt_bls12_381_dl"
|
exec "LD_LIBRARY_PATH=lib ./build/testsuite/t_libctt_bls12_381_dl"
|
||||||
else:
|
else:
|
||||||
# Put DLL near the exe as LD_LIBRARY_PATH doesn't work even in an POSIX compatible shell
|
# Put DLL near the exe as LD_LIBRARY_PATH doesn't work even in an POSIX compatible shell
|
||||||
exec "gcc -Ibindings/generated -Lbindings/generated -o build/testsuite/t_libctt_bls12_381_dl.exe tests/bindings/t_libctt_bls12_381.c -lgmp -lconstantine_bls12_381"
|
exec "gcc -Iinclude -Llib -o build/testsuite/t_libctt_bls12_381_dl.exe examples_c/t_libctt_bls12_381.c -lgmp -lconstantine_bls12_381"
|
||||||
exec "./build/testsuite/t_libctt_bls12_381_dl.exe"
|
exec "./build/testsuite/t_libctt_bls12_381_dl.exe"
|
||||||
|
|
||||||
echo "--> Testing statically linked library"
|
echo "--> Testing statically linked library"
|
||||||
when not defined(windows):
|
when not defined(windows):
|
||||||
# Beware MacOS annoying linker with regards to static libraries
|
# Beware MacOS annoying linker with regards to static libraries
|
||||||
# The following standard way cannot be used on MacOS
|
# The following standard way cannot be used on MacOS
|
||||||
# exec "gcc -Ibindings/generated -Lbindings/generated -o build/t_libctt_bls12_381_sl.exe tests/bindings/t_libctt_bls12_381.c -lgmp -Wl,-Bstatic -lconstantine_bls12_381 -Wl,-Bdynamic"
|
# exec "gcc -Iinclude -Llib -o build/t_libctt_bls12_381_sl.exe examples_c/t_libctt_bls12_381.c -lgmp -Wl,-Bstatic -lconstantine_bls12_381 -Wl,-Bdynamic"
|
||||||
|
|
||||||
exec "gcc -Ibindings/generated -o build/testsuite/t_libctt_bls12_381_sl tests/bindings/t_libctt_bls12_381.c bindings/generated/libconstantine_bls12_381.a -lgmp"
|
exec "gcc -Iinclude -o build/testsuite/t_libctt_bls12_381_sl examples_c/t_libctt_bls12_381.c lib/libconstantine_bls12_381.a -lgmp"
|
||||||
exec "./build/testsuite/t_libctt_bls12_381_sl"
|
exec "./build/testsuite/t_libctt_bls12_381_sl"
|
||||||
else:
|
else:
|
||||||
exec "gcc -Ibindings/generated -o build/testsuite/t_libctt_bls12_381_sl.exe tests/bindings/t_libctt_bls12_381.c bindings/generated/constantine_bls12_381.lib -lgmp"
|
exec "gcc -Iinclude -o build/testsuite/t_libctt_bls12_381_sl.exe examples_c/t_libctt_bls12_381.c lib/constantine_bls12_381.lib -lgmp"
|
||||||
exec "./build/testsuite/t_libctt_bls12_381_sl.exe"
|
exec "./build/testsuite/t_libctt_bls12_381_sl.exe"
|
||||||
|
|
||||||
task test, "Run all tests":
|
task test, "Run all tests":
|
||||||
|
|||||||
5
examples_c/README.md
Normal file
5
examples_c/README.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# C bindings examples
|
||||||
|
|
||||||
|
This folder holds tests (prefixed with `t_`) and examples for the C bindings.
|
||||||
|
|
||||||
|
Headers are located in `include/` and the static and dynamic libraries in `lib/`
|
||||||
@ -6,6 +6,9 @@
|
|||||||
// * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0).
|
// * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0).
|
||||||
// at your option. This file may not be copied, modified, or distributed except according to those terms.
|
// at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
|
// This is a test to ensure Constantine's modular arithmetic is consistent with GMP.
|
||||||
|
// While not intended as a tutorial, it showcases serialization, deserialization and computation.
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <gmp.h>
|
#include <gmp.h>
|
||||||
#include <constantine_bls12_381.h>
|
#include <constantine_bls12_381.h>
|
||||||
5
include/README.md
Normal file
5
include/README.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# Headers
|
||||||
|
|
||||||
|
This folder holds the generated C headers for Constantine.
|
||||||
|
|
||||||
|
To create a new build, download install the [Nim programming language](https://nim-lang.org/install.html), navigate to Constantine's root folder and call `nimble bindings`.
|
||||||
5
lib/README.md
Normal file
5
lib/README.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# Libraries
|
||||||
|
|
||||||
|
This folder holds the generated dynamic libraries (.so on Linux, .dylib on MacOS, .dll on Windows) and static libraries (.a on Linux and Mac, .dll on Windows).
|
||||||
|
|
||||||
|
To create a new build, download install the [Nim programming language](https://nim-lang.org/install.html), navigate to Constantine's root folder and call `nimble bindings`.
|
||||||
Loading…
x
Reference in New Issue
Block a user