Files
nym/sdk/ffi/cpp/build.sh
T
mx ae6c80f0cd FFI share lib + initial uniffi-bindgen-go implementation (#4394)
* fixed rebase conflict with cargo.lock

* shared cleanup

* moved returncode to shared

* first pass at Go binding structure

* minor cleanup

* working on custom type udl

* trying to get LDFLAG script working

* commit before changing alias -> proper types

* converted CCallbacks from aliases to Struct

* cleanup comments

* temp

* push to share

* cleanup

* trait Lift not implemented for *const i8 issue

* test of refactor:
* move c-specific var casting out of shared/ into cpp/
* error returning in go/ over ffi boundary with uniffi

*  _internal functions ffi wrapper agnostic
* moved lang-specific type conversions to cpp / go bindings and out of
  shared
* got send_message working in c/c++ & go
* split out c/c++-specific types to mod

* cont. with making _internal fns lang agnostic
* working on final fn for C and shared (listening for incoming messages)

* fixed return err on listen_for_incoming

* got full example run running again after shared/ refactor

* removed unused struct

* code comments

* got first runthrough of go example code

* script cleanup

* clean up readme instructions

* clippy

* removed unused imports

* rustfmt

* Update sdk/ffi/go/README.md with link to example file

Co-authored-by: Mark Sinclair <14054343+mmsinclair@users.noreply.github.com>

* updated readme with extra build and usage info

* renamed binding outer directory for nicer path
* moved example file from ffi/main.go -> ./example.go

* updated README with new example file name

---------

Co-authored-by: mfahampshire <mfahampshire@pm.me>
Co-authored-by: Mark Sinclair <14054343+mmsinclair@users.noreply.github.com>
2024-03-18 15:15:59 +01:00

52 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
C_CODE_NAME="main"
PROJECT_NAME="cpp"
clean_artifacts() {
printf "cleaning cargo artifacts \n"
cargo clean
if [ -e "src/${C_CODE_NAME}" ]
then
printf "cleaning compiled C++ \n"
rm src/${C_CODE_NAME}
else
printf "no compiled C++ to clean \n"
fi
}
build_artifacts_and_link() {
cargo build --release &&
cd src/ &&
printf "compiling cpp \n"
g++ -std=c++11 -o main main.cpp -ldl -lpthread -L../target/release -lnym_cpp_ffi -lboost_thread &&
export LD_LIBRARY_PATH=../target/release:$LD_LIBRARY_PATH
# check output for name of rust lib - can be helpful if you've changed e.g. the name of a file and the compilation is failing
# printf "ldd main: \n"
# ldd main
}
if [ $(pwd | awk -F/ '{print $NF}') != ${PROJECT_NAME} ]
then
printf "please run from root dir of project"
exit 1
fi
if [ $# -eq 0 ];
then
build_artifacts_and_link;
./main;
else
arg=$1
if [ "$arg" == "clean" ]; then
clean_artifacts;
build_artifacts_and_link;
./main;
else
printf "unknown optional argument - the only available optional argument is 'clean'"
exit 1
fi
fi