fr-ser / grafana-sqlite-datasource

Grafana Plugin to enable SQLite as a Datasource
Apache License 2.0
124 stars 17 forks source link

TODO: Support MacOs as environment #7

Closed fr-ser closed 3 years ago

fr-ser commented 3 years ago

The plugin is currently not compiling (on GitHub actions or inside a docker container) on a macOS environment.

Workaround: Run Grafana (and the plugin) inside a Linux docker container.

This is not planned for the near future. If this feature is required for some, please let me know (through a thumbsup emoji on this message)

fr-ser commented 3 years ago

Some general cross-compilation info is here:

https://www.arp242.net/static-go.html https://dh1tw.de/2019/12/cross-compiling-golang-cgo-projects/ grafana/google-sheets-datasource#104 grafana/grafana-plugin-sdk-go#188

fr-ser commented 3 years ago

A look at Grafana's build process: https://github.com/grafana/grafana/blob/master/scripts/build/build.sh

fr-ser commented 3 years ago

Question in the Grafana community (I guess this is where Grafana development questions go...) https://community.grafana.com/t/cross-compilation-of-grafana-plugin-for-macos/42772?u=frser

fr-ser commented 3 years ago

Reference:

After adding this line to the dockerfile RUN tar -xf /tmp/osxcross.tar.xz --directory /tmp

This code (from the makefile)

build-backend-cross-darwin-amd64:
    docker build -t cross-build ./build

    docker run -v "$${PWD}":/usr/src/app -w /usr/src/app \
        -e CGO_ENABLED=1 -e GOOS=darwin -e GOARCH=amd64 \
        -e CC=/tmp/osxcross/target/bin/o64-clang \
        cross-build \
        go build -o dist/gpx_sqlite-datasource_darwin_amd64 \
        -ldflags '-w -s -extldflags "-static"' \
        -tags osusergo,netgo,sqlite_omit_load_extension \
        ./pkg

Produced this error:

/usr/local/go/pkg/tool/linux_amd64/link: running /tmp/osxcross/target/bin/o64-clang failed: exit status 1
ld: library not found for -lcrt0.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
yuriymacdev commented 3 years ago

Produced this error:

/usr/local/go/pkg/tool/linux_amd64/link: running /tmp/osxcross/target/bin/o64-clang failed: exit status 1
ld: library not found for -lcrt0.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Just remove the -extldflags "-static" part.

I've built it for Mac by editing Makefile to

...
build-backend:
ifeq ($(UNAME_OS), Linux)
    CGO_ENABLED=1 go build \
        -o dist/gpx_sqlite-datasource_linux_amd64 \
        -ldflags '-extldflags "-static"' \
        -tags osusergo,netgo,sqlite_omit_load_extension \
        ./pkg
else ifeq ($(UNAME_OS), Darwin)
    CGO_ENABLED=1 go build \
        -o dist/gpx_sqlite-datasource_darwin_amd64 \
        -tags osusergo,netgo,sqlite_omit_load_extension \
        ./pkg
else
    CGO_ENABLED=1 go build \
        -o dist/gpx_sqlite-datasource_windows_amd64.exe \
        -ldflags '-extldflags "-static"' \
        -tags osusergo,netgo,sqlite_omit_load_extension \
        ./pkg
endif

...

then using these commands:

brew install go
make build-backend

and placing gpx_sqlite-datasource_darwin_amd64 into the plugins dir manually

fr-ser commented 3 years ago

This way we would not be "linking statically" anymore. This would require certain C libraries to be present on the target (MacOS) machine. But all bug reports I find in regards to this (e.g. https://github.com/grafana/google-sheets-datasource/issues/104) are only about Linux distributions. So maybe I can just get rid of the static linking for MacOs :thinking:

I will try it out :ok_hand:

fr-ser commented 3 years ago

This version should be a working MacOS release (testing is hard for me, if anybody wants to send me a Macbook feel free :wink: ) https://github.com/fr-ser/grafana-sqlite-datasource/releases/tag/v1.1.0