timob / jnigi

Golang Java JNI library
BSD 2-Clause "Simplified" License
166 stars 44 forks source link

change include of windows.h to lower case #68

Closed mlaggner closed 1 year ago

mlaggner commented 1 year ago

per default Microsoft defaults its examples to #include <Windows.h>, which is fine for building in Windows (since the file system of Windows is case insensitive).

But if you want to cross build the application (e.g. via golang crossbuild - https://github.com/elastic/golang-crossbuild), the build will fail because this toolchain contains the file in lowercase windows.h

I tested crossbuilding with the lower include which works fine. Unfortunately I was not able to build on Windows yet

timob commented 1 year ago

Thanks for the detail here! Will look into this. Is this blocking something for you?

mlaggner commented 1 year ago

yes - since I have automated cross builds (using the docker images from elastic), my builds are failing because of that.

I've set up a docker command where I can test your lib.:

# docker run -it --rm --platform linux/amd64 -v $(pwd):/go/src/tekao.net/jnigi -v $(pwd)/include/:/jvm/include/ -w /go/src/tekao.net/jnigi docker.elastic.co/beats-dev/golang-crossbuild:1.19.2-main --build-cmd "CGO_ENABLED=1 CGO_CFLAGS='-I/jvm/include/win32 -I/jvm/include/win32/win32' go test" -p "windows/amd64"
>> Building using: cmd='CGO_ENABLED=1 CGO_CFLAGS='-I/jvm/include/win32 -I/jvm/include/win32/win32' go test', env=[CC=x86_64-w64-mingw32-gcc, CXX=x86_64-w64-mingw32-g++, GOARCH=amd64, GOARM=, GOOS=windows, PLATFORM_ID=windows-amd64]
# tekao.net/jnigi
./windows.go:12:21: fatal error: Windows.h: No such file or directory
 #include <Windows.h>
                     ^
compilation terminated.
FAIL    tekao.net/jnigi [build failed]
Error: failed building for windows/amd64: exit status 2
failed building for windows/amd64: exit status 2

but after changing the include to lower case:

docker run -it --rm --platform linux/amd64 -v $(pwd):/go/src/tekao.net/jnigi -v $(pwd)/include/:/jvm/include/ -w /go/src/tekao.net/jnigi docker.elastic.co/beats-dev/golang-crossbuild:1.19.2-main --build-cmd "CGO_ENABLED=1 CGO_CFLAGS='-I/jvm/include/win32 -I/jvm/include/win32/win32' go test" -p "windows/amd64"
>> Building using: cmd='CGO_ENABLED=1 CGO_CFLAGS='-I/jvm/include/win32 -I/jvm/include/win32/win32' go test', env=[CC=x86_64-w64-mingw32-gcc, CXX=x86_64-w64-mingw32-g++, GOARCH=amd64, GOARM=, GOOS=windows, PLATFORM_ID=windows-amd64]
fork/exec /tmp/go-build2578602732/b001/jnigi.test.exe: exec format error
FAIL    tekao.net/jnigi 0.006s
Error: failed building for windows/amd64: exit status 1
failed building for windows/amd64: exit status 1

it builds, but the test fails (probably, because the .exe cant be executed in the docker environment

timob commented 1 year ago

OK I see, looks good.