From 3d8164c06d869478f434082a561ef33e19bb0585 Mon Sep 17 00:00:00 2001 From: Linus Gasser Date: Mon, 10 May 2021 20:25:49 +0200 Subject: [PATCH 1/8] Build ios --- .gitignore | 1 + Makefile | 19 +++++++++++++++++++ clangwrap.sh | 14 ++++++++++++++ switch-ffi.sh | 6 +++--- 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 clangwrap.sh diff --git a/.gitignore b/.gitignore index dbb20d7..53069a5 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ cwtch.aar libCwtch.h libCwtch.so libCwtch.dll +ios/ diff --git a/Makefile b/Makefile index 179e701..a275090 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +IOS_OUT := ./ios + .PHONY: all linux android windows clean DEFAULT_GOAL: linux @@ -24,3 +26,20 @@ libCwtch.dll: lib.go clean: rm -f cwtch.aar cwtch_go.apk libCwtch.h libCwtch.so cwtch-sources.jar libCwtch.dll + +ios-arm64: + CGO_ENABLED=1 \ + GOOS=darwin \ + GOARCH=arm64 \ + CGO_CFLAGS="-fembed-bitcode" \ + go build -buildmode=c-archive -tags ios -o $(IOS_OUT)/arm64.a . + +ios-x86_64: + CGO_ENABLED=1 \ + GOOS=darwin \ + GOARCH=amd64 \ + go build -buildmode=c-archive -tags ios -o $(IOS_OUT)/x86_64.a . + +ios: ios-arm64 ios-x86_64 + lipo $(IOS_OUT)/x86_64.a $(IOS_OUT)/arm64.a -create -output $(IOS_OUT)/cwtch.a + cp $(IOS_OUT)/arm64.h $(IOS_OUT)/cwtch.h diff --git a/clangwrap.sh b/clangwrap.sh new file mode 100644 index 0000000..763187e --- /dev/null +++ b/clangwrap.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +# go/clangwrap.sh + +SDK_PATH=`xcrun --sdk $SDK --show-sdk-path` +CLANG=`xcrun --sdk $SDK --find clang` + +if [ "$GOARCH" == "amd64" ]; then + CARCH="x86_64" +elif [ "$GOARCH" == "arm64" ]; then + CARCH="arm64" +fi + +exec $CLANG -arch $CARCH -isysroot $SDK_PATH -mios-version-min=10.0 "$@" diff --git a/switch-ffi.sh b/switch-ffi.sh index 7985e9f..a75c3b3 100755 --- a/switch-ffi.sh +++ b/switch-ffi.sh @@ -1,5 +1,5 @@ #!/bin/sh -sed -i "s/^package cwtch/\/\/package cwtch/" lib.go -sed -i "s/^\/\/package main/package main/" lib.go -sed -i "s/^\/\/func main()/func main()/" lib.go \ No newline at end of file +perl -pi -e "s/^package cwtch/\/\/package cwtch/" lib.go +perl -pi -e "s/^\/\/package main/package main/" lib.go +perl -pi -e "s/^\/\/func main()/func main()/" lib.go From c395153ad887d8d9309de3c460a1920ad820c784 Mon Sep 17 00:00:00 2001 From: Linus Gasser Date: Fri, 14 May 2021 08:59:00 +0200 Subject: [PATCH 2/8] Activating clangwrap.sh and putting the SDK manually --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index a275090..e6fb01d 100644 --- a/Makefile +++ b/Makefile @@ -31,13 +31,17 @@ ios-arm64: CGO_ENABLED=1 \ GOOS=darwin \ GOARCH=arm64 \ + SDK=iphoneos \ CGO_CFLAGS="-fembed-bitcode" \ + CC=$(PWD)/clangwrap.sh \ go build -buildmode=c-archive -tags ios -o $(IOS_OUT)/arm64.a . ios-x86_64: CGO_ENABLED=1 \ GOOS=darwin \ GOARCH=amd64 \ + SDK=iphonesimulator \ + CC=$(PWD)/clangwrap.sh \ go build -buildmode=c-archive -tags ios -o $(IOS_OUT)/x86_64.a . ios: ios-arm64 ios-x86_64 From c57942c69344c8ddca3b8a9861c1f98e55426403 Mon Sep 17 00:00:00 2001 From: Linus Gasser Date: Fri, 14 May 2021 09:03:20 +0200 Subject: [PATCH 3/8] using perl-pie instead of sed-i, so that macos can compile, too --- switch-gomobile.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/switch-gomobile.sh b/switch-gomobile.sh index be90765..e7e0d0f 100755 --- a/switch-gomobile.sh +++ b/switch-gomobile.sh @@ -1,5 +1,5 @@ #!/bin/sh -sed -i "s/^\/\/package cwtch/package cwtch/" lib.go -sed -i "s/^package main/\/\/package main/" lib.go -sed -i "s/^func main()/\/\/func main()/" lib.go +perl -pi -e "s/^\/\/package cwtch/package cwtch/" lib.go +perl -pi -e "s/^package main/\/\/package main/" lib.go +perl -pi -e "s/^func main()/\/\/func main()/" lib.go From 64528d731fcde1c0537121fa1df97bad7ba7bd9b Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Fri, 6 Aug 2021 14:38:26 -0700 Subject: [PATCH 4/8] experimental ios comments and notes --- Makefile | 4 +++- README.md | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e6fb01d..131e1e3 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ IOS_OUT := ./ios -.PHONY: all linux android windows clean +.PHONY: all linux android windows clean ios DEFAULT_GOAL: linux @@ -27,6 +27,8 @@ libCwtch.dll: lib.go clean: rm -f cwtch.aar cwtch_go.apk libCwtch.h libCwtch.so cwtch-sources.jar libCwtch.dll +# iOS - for testing purposes only for now, not officially supported + ios-arm64: CGO_ENABLED=1 \ GOOS=darwin \ diff --git a/README.md b/README.md index 8fb7bc7..f2f4c80 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,13 @@ C-bindings for the Go Cwtch Library. -# Build Instructions... +# Build Instructions make linux make android + make windows + +## Experimental iOS support + make ios # Using @@ -16,3 +20,7 @@ C-bindings for the Go Cwtch Library. ## Android - copy `cwtch.aar` into `flutter_app/android/cwtch` + +## Windows + +- copy libCwtch.dll into the directory of the `.exe` using it From b524f9e8ad8665aae9016cc2efe9e25f355a908b Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Fri, 6 Aug 2021 14:48:53 -0700 Subject: [PATCH 5/8] new buildifles host --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 3fc2b93..5bedeb4 100644 --- a/.drone.yml +++ b/.drone.yml @@ -82,7 +82,7 @@ steps: - find . -type f -exec sha256sum {} \; > ./../sha256s.txt - mv ./../sha256s.txt . - cd .. - - scp -r -o StrictHostKeyChecking=no -i ~/id_rsa $DIR buildfiles@openprivacy.ca:/home/buildfiles/buildfiles/ + - scp -r -o StrictHostKeyChecking=no -i ~/id_rsa $DIR buildfiles@build.openprivacy.ca:/home/buildfiles/buildfiles/ - name: gitea-release image: plugins/gitea-release From 127ad82b21e58d06e7e7cac32e3291cc1b1cf4b8 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Fri, 6 Aug 2021 14:57:09 -0700 Subject: [PATCH 6/8] fix perl regexp in new switch-* functions --- switch-ffi.sh | 2 +- switch-gomobile.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/switch-ffi.sh b/switch-ffi.sh index a75c3b3..fa1ca27 100755 --- a/switch-ffi.sh +++ b/switch-ffi.sh @@ -2,4 +2,4 @@ perl -pi -e "s/^package cwtch/\/\/package cwtch/" lib.go perl -pi -e "s/^\/\/package main/package main/" lib.go -perl -pi -e "s/^\/\/func main()/func main()/" lib.go +perl -pi -e "s/^\/\/func main\(\)/func main\(\)/" lib.go diff --git a/switch-gomobile.sh b/switch-gomobile.sh index e7e0d0f..afb97d5 100755 --- a/switch-gomobile.sh +++ b/switch-gomobile.sh @@ -2,4 +2,4 @@ perl -pi -e "s/^\/\/package cwtch/package cwtch/" lib.go perl -pi -e "s/^package main/\/\/package main/" lib.go -perl -pi -e "s/^func main()/\/\/func main()/" lib.go +perl -pi -e "s/^func main\(\)/\/\/func main\(\)/" lib.go From 7d02f841749ace1814e7add973f49860df341fe4 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Mon, 9 Aug 2021 19:34:44 -0400 Subject: [PATCH 7/8] switch swtich-*.sh back to sed now with -i.bak and rm lib.go.bak for compatibility with macos --- switch-ffi.sh | 9 +++++---- switch-gomobile.sh | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/switch-ffi.sh b/switch-ffi.sh index fa1ca27..221fe92 100755 --- a/switch-ffi.sh +++ b/switch-ffi.sh @@ -1,5 +1,6 @@ #!/bin/sh - -perl -pi -e "s/^package cwtch/\/\/package cwtch/" lib.go -perl -pi -e "s/^\/\/package main/package main/" lib.go -perl -pi -e "s/^\/\/func main\(\)/func main\(\)/" lib.go +# using '-i.bak' and 'rm .bak' for gnu sed (linux) and bsd sed (macosx) compat +sed -i.bak "s/^package cwtch/\/\/package cwtch/" lib.go +sed -i.bak "s/^\/\/package main/package main/" lib.go +sed -i.bak "s/^\/\/func main()/func main()/" lib.go +rm lib.go.bak diff --git a/switch-gomobile.sh b/switch-gomobile.sh index afb97d5..f89c584 100755 --- a/switch-gomobile.sh +++ b/switch-gomobile.sh @@ -1,5 +1,6 @@ #!/bin/sh - -perl -pi -e "s/^\/\/package cwtch/package cwtch/" lib.go -perl -pi -e "s/^package main/\/\/package main/" lib.go -perl -pi -e "s/^func main\(\)/\/\/func main\(\)/" lib.go +# using '-i.bak' and 'rm .bak' for gnu sed (linux) and bsd sed (macosx) compat +sed -i.bak "s/^\/\/package cwtch/package cwtch/" lib.go +sed -i.bak "s/^package main/\/\/package main/" lib.go +sed -i.bak "s/^func main()/\/\/func main()/" lib.go +rm lib.go.bak From 23b9888ad7268462553f8112365dd25a95371818 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Mon, 9 Aug 2021 19:55:55 -0400 Subject: [PATCH 8/8] add macos target to makefile --- Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 131e1e3..57972fe 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,15 @@ IOS_OUT := ./ios -.PHONY: all linux android windows clean ios +.PHONY: all linux android windows macos clean ios DEFAULT_GOAL: linux -all: linux android +all: linux android windows linux: libCwtch.so +macos: libCwtch.so + android: cwtch.aar windows: libCwtch.dll