hybridgroup / gocv

Go package for computer vision using OpenCV 4 and beyond. Includes support for DNN, CUDA, OpenCV Contrib, and OpenVINO.
https://gocv.io
Other
6.74k stars 868 forks source link

all: correctly working static builds #1226

Closed deadprogram closed 2 months ago

deadprogram commented 2 months ago

This PR modifies the static build capability for GoCV to correctly work to build fully statically linked binaries for Linux.

To build the static binary:

docker build -f Dockerfile-static -t gocv-static .

Once it is built:

$ docker run gocv-static
gocv version: 0.38.0
opencv lib version: 4.10.0
$ docker run --rm -it --entrypoint bash gocv-static
root@5b28670af0d5:/# ls -l /run/gocv_version 
-rwxr-xr-x 1 root root 69112352 Sep 18 08:02 /run/gocv_version
deadprogram commented 2 months ago

I have added another container called gocv-static-builder intended to help build user projects.

Build it like this:

docker build -f Dockerfile-static-builder -t gocv-static-builder .

Use it like this:

$ docker run --rm -e "BINARYNAME=mjpeg-streamer" -e "SRCPATH=./cmd/mjpeg-streamer" -v $(pwd):/src -v $(pwd)/build:/build -a stdout -a stderr gocv-static-builder
$ ls -l ./build/mjpeg-streamer
-rwxr-xr-x 1 root root 74471944 sep 18 12:06 ./build/mjpeg-streamer

Now you can run the static binary like this:

$ ./build/mjpeg-streamer 0 localhost:8080
deadprogram commented 2 months ago

Did some further work and now the docker image is multiarch for both arm64 and amd64.

$ docker run --platform=linux/arm64 gocv-static
gocv version: 0.38.0
opencv lib version: 4.10.0

$ docker run --platform=linux/amd64 gocv-static
gocv version: 0.38.0
opencv lib version: 4.10.0