Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use xgo in build.sh for easier cross compilation #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions cffi_dist/Dockerfile.alpine.compile

This file was deleted.

13 changes: 0 additions & 13 deletions cffi_dist/Dockerfile.ubuntu.compile

This file was deleted.

43 changes: 13 additions & 30 deletions cffi_dist/build.sh
Original file line number Diff line number Diff line change
@@ -1,35 +1,18 @@
#!/bin/sh
#!/bin/bash
# Requires xgo: https://github.com/techknowlogick/xgo

# This build.sh file was created on a OSX host system. If you are running on windows / unix you need to adjust the commands accordingly.

echo 'Build OSX'
GOOS=darwin CGO_ENABLED=1 GOARCH=arm64 go build -buildmode=c-shared -o ./dist/tls-client-darwin-arm64-$1.dylib
GOOS=darwin CGO_ENABLED=1 GOARCH=amd64 go build -buildmode=c-shared -o ./dist/tls-client-darwin-amd64-$1.dylib

echo 'Build Linux ARM64'
# CC is needed when you cross compile from OSX to Linux
GOOS=linux CGO_ENABLED=1 GOARCH=arm64 CC="aarch64-unknown-linux-gnu-gcc" go build -buildmode=c-shared -o ./dist/tls-client-linux-arm64-$1.so
set -e

mkdir dist

# CC is needed when you cross compile from OSX to Linux
echo 'Build Linux Alpine'
# For some reason my OSX gcc cross compiler does not work. Therefore i use a alpine docker image
# GOOS=linux CGO_ENABLED=1 GOARCH=amd64 CC="x86_64-linux-musl-gcc" go build -buildmode=c-shared -o ./dist/tls-client-linux-amd64.so
# Make sure to first build the image based on the Dockerfile.alpine.compile in this directory.
docker run -v $PWD/../:/tls-client tls-client-alpine-go-1.18 bash -c "cd /tls-client/cffi_dist && GOOS=linux CGO_ENABLED=1 GOARCH=amd64 go build -buildmode=c-shared -o /tls-client/cffi_dist/dist/tls-client-linux-alpine-amd64-$1.so"

# CC is needed when you cross compile from OSX to Linux
echo 'Build Linux Ubuntu'
# For some reason my OSX gcc cross compiler does not work. Therefore i use a ubuntu docker image
# GOOS=linux CGO_ENABLED=1 GOARCH=amd64 CC="x86_64-linux-musl-gcc" go build -buildmode=c-shared -o ./dist/tls-client-linux-amd64.so
# Make sure to first build the image based on the Dockerfile.ubuntu.compile in this directory.
docker run -v $PWD/../:/tls-client tls-client-ubuntu-go-1.18 bash -c "cd /tls-client/cffi_dist && GOOS=linux CGO_ENABLED=1 GOARCH=amd64 go build -buildmode=c-shared -o /tls-client/cffi_dist/dist/tls-client-linux-ubuntu-amd64-$1.so"

echo 'Build OSX'
xgo -buildmode=c-shared -out dist/tls-client --targets=darwin/arm64 .
xgo -buildmode=c-shared -out dist/tls-client --targets=darwin/amd64 .

# CC is needed when you cross compile from OSX to Windows
echo 'Build Windows 32 Bit'
GOOS=windows CGO_ENABLED=1 GOARCH=386 CC="i686-w64-mingw32-gcc" go build -buildmode=c-shared -o ./dist/tls-client-windows-32-$1.dll
echo 'Build Linux'
xgo -buildmode=c-shared -out dist/tls-client --targets=linux/arm64 .
xgo -buildmode=c-shared -out dist/tls-client --targets=linux/amd64 .

# CC is needed when you cross compile from OSX to Windows
echo 'Build Windows 64 Bit'
GOOS=windows CGO_ENABLED=1 GOARCH=amd64 CC="x86_64-w64-mingw32-gcc" go build -buildmode=c-shared -o ./dist/tls-client-windows-64-$1.dll
echo 'Build Windows'
xgo -buildmode=c-shared -out dist/tls-client --targets=windows/386 .
xgo -buildmode=c-shared -out dist/tls-client --targets=windows/amd64 .
2 changes: 1 addition & 1 deletion cffi_dist/example_python/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json

# load the tls-client shared package for your OS you are currently running your python script (i'm running on mac)
library = ctypes.cdll.LoadLibrary('./../dist/tls-client-darwin-amd64-1.3.12.dylib')
library = ctypes.cdll.LoadLibrary(f'./../dist/tls-client-darwin-10.12-amd64.dylib')

# extract the exposed request function from the shared package
request = library.request
Expand Down