diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..732af36 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,20 @@ +name: Test + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + go-version: [ '1.x' ] + + steps: + - uses: actions/checkout@v4 + - name: Setup Go ${{ matrix.go-version }} + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go-version }} + - name: Test + run: make test \ No newline at end of file diff --git a/.gitignore b/.gitignore index 575ad12..d163863 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1 @@ -.idea -*.so -*.o -app +build/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 3dda8c7..0000000 --- a/Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -FROM ubuntu:18.04 - -ARG GO=1.13.4 - -RUN apt update && apt upgrade -y -RUN apt install -y wget make gcc - -WORKDIR /tmp -RUN wget https://dl.google.com/go/go${GO}.linux-amd64.tar.gz -RUN tar -xvf go${GO}.linux-amd64.tar.gz -RUN mv go /usr/local - -RUN echo export GOROOT=/usr/local/go >> ~/.bashrc -RUN echo export GOPATH=\$HOME/go >> ~/.bashrc -RUN echo export PATH=\$GOPATH/bin:\$GOROOT/bin:\$PATH >> ~/.bashrc - -WORKDIR /src diff --git a/Makefile b/Makefile index ca4f0fa..418b1d2 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,25 @@ -.PHONY: all c go run env - -TESTLIBPATH="./ctestlib" +.PHONY: all c go run env clean all: c go run env: - docker build --tag cgo . - docker run --rm -ti -v $(shell pwd):/src cgo + docker run --rm -ti -v $(shell pwd):/src -w /src golang:1.24.2 c: - gcc -c -Wall -Werror -fpic -o ${TESTLIBPATH}/test.o ${TESTLIBPATH}/test.c - gcc -shared -o ${TESTLIBPATH}/libtest.so ${TESTLIBPATH}/test.o + mkdir -p build + gcc -c -Wall -Werror -fpic -o build/test.o ctestlib/test.c + gcc -shared -o build/libtest.so build/test.o + ar rcs build/libtest.a build/test.o go: - go build -o app *.go + go build -o build/app *.go run: - ./app + ./build/app + +test: c go + ./build/app > build/app.out + diff build/app.out app.expected_out + +clean: + rm -rf build/ \ No newline at end of file diff --git a/app.expected_out b/app.expected_out new file mode 100644 index 0000000..94f7f0f --- /dev/null +++ b/app.expected_out @@ -0,0 +1,26 @@ + +Numbers +3 + +Get string +string sent from C +[115 116 114 105 110 103 32 115 101 110 116 32 102 114 111 109 32 67] + +Send string + +Send byte array +bytes: +Get and pass struct +{0 2} +-2 + +Pass void pointer + +Access enum +true 0 1 + +Pass callback +odd number: 0 +odd number: 2 +odd number: 4 +{johndoe 5} diff --git a/main.go b/main.go index 058ccfc..5bcb9ad 100644 --- a/main.go +++ b/main.go @@ -2,8 +2,8 @@ package main /* #cgo CFLAGS: -I${SRCDIR}/ctestlib -#cgo LDFLAGS: -Wl,-rpath,${SRCDIR}/ctestlib -#cgo LDFLAGS: -L${SRCDIR}/ctestlib +#cgo LDFLAGS: -Wl,-rpath,${SRCDIR}/build +#cgo LDFLAGS: -L${SRCDIR}/build #cgo LDFLAGS: -ltest #include