From cbaf523b0e5377407353c6b2bf677754e11d1afe Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Wed, 3 Jun 2020 08:22:05 +0200 Subject: [PATCH] Address feedback --- Makefile | 3 ++- _assets/ci/Jenkinsfile.linux | 5 +++++ cmd/library/README.md | 13 +++++++++++++ cmd/library/const.go | 4 +++- 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 cmd/library/README.md diff --git a/Makefile b/Makefile index fdff57a3b..dad0db818 100644 --- a/Makefile +++ b/Makefile @@ -111,8 +111,9 @@ statusgo-ios: ##@cross-compile Build status-go for iOS @echo "iOS framework cross compilation done in build/bin/Statusgo.framework" statusgo-library: ##@cross-compile Build status-go as static library for current platform + ## cmd/library/README.md explains the magic incantation behind this mkdir -p $(GOBIN)/statusgo-lib - go run cmd/library/* > $(GOBIN)/statusgo-lib/main.go + go run cmd/library/*.go > $(GOBIN)/statusgo-lib/main.go @echo "Building static library..." go build -buildmode=c-archive -o $(GOBIN)/libstatus.a $(BUILD_FLAGS) $(GOBIN)/statusgo-lib @echo "Static library built:" diff --git a/_assets/ci/Jenkinsfile.linux b/_assets/ci/Jenkinsfile.linux index e3b9595fa..87ccd24f1 100644 --- a/_assets/ci/Jenkinsfile.linux +++ b/_assets/ci/Jenkinsfile.linux @@ -52,6 +52,11 @@ pipeline { sh 'make setup-build' } } } + /* Sanity-check C bindings */ + stage('Sanity check bindings') { steps { dir(env.STATUS_PATH) { + sh 'make statusgo-library' + } } } + stage('Compress') { steps { dir(env.STATUS_PATH) { sh "zip -q -r ${dest}/${artifact} . -x *.git" } } } diff --git a/cmd/library/README.md b/cmd/library/README.md new file mode 100644 index 000000000..9fa632b5d --- /dev/null +++ b/cmd/library/README.md @@ -0,0 +1,13 @@ +### Library bindings + +This unholy namespace generates C bindings for `mobile/`. +It does so by parsing the go files, identify any public function in the namespace +that is not a test file, and generate an equivalent function with the correct +C signature, which will then just call the version in `mobile/`. + +This method is ad-hoc and not bullet-proof, the main limitation is that only some +types are supported for now, `C.int`, `*C.char` and `unsafer.Pointer`. +Functions that do not use these types will be ignored. + +The problem this sledgehammer solves is to have to keep in sync the two namespaces, +which is fiddly and prone to error as they are modified by either teams. diff --git a/cmd/library/const.go b/cmd/library/const.go index 66e32dfbf..ba80ea778 100644 --- a/cmd/library/const.go +++ b/cmd/library/const.go @@ -1,6 +1,8 @@ package main -const prelude = `package main +const prelude = `// Code generated by cmd/library to keep in sync with mobile. DO NOT EDIT. +package main + // #include import "C" import "unsafe"