gen2brain / beeep

Go cross-platform library for sending desktop notifications, alerts and beeps
BSD 2-Clause "Simplified" License
1.43k stars 89 forks source link

building for windows from osx #19

Closed ghost closed 5 years ago

ghost commented 5 years ago

I cant get a Windows build :)

I have a setup for cross platform builds running from OSX and Linux. But I cant build for Windows from OSX.

Would appreciate advice here !

Step to repo:


make build-win-fromosx

Makefile you can run from anywhere:


LIB=github.com/gen2brain/beeep
LIB_FSPATH=$(GOPATH)/src/$(LIB)

NAME=n

print:
    @echo Lib  -
    @echo LIB :$(LIB)
    @echo LIB_FSPATH  : $(LIB_FSPATH)
    #cd $(LIB_FSPATH) && ls -al 
    @echo

dep:
    go get $(LIB)

open-code:
    code $(LIB_FSPATH)

open-bash:
    bash $(LIB_FSPATH)

build-list:
    cd $(LIB_FSPATH) && ls -al

build-clean:
    cd $(LIB_FSPATH) && rm -rf $(NAME) go$(NAME) $(NAME).exe go$(NAME).exe *.tar.gz

build-win-fromosx:
    brew install mingw-w64

    go get gopkg.in/toast.v1

    #windows with cgo. It needs CGO
    #apt-get install gcc-multilib 
    #apt-get install gcc-mingw-w64
    cd $(LIB_FSPATH) && CC=i686-w64-mingw32-gcc-win32 CGO_ENABLED=1 GOOS=windows GOARCH=386 go build -o $(NAME).exe && tar zcfv "$(NAME)-windows-386.tar.gz" $(NAME).exe
    cd $(LIB_FSPATH) && rm -rf $(NAME).exe
    cd $(LIB_FSPATH) && CC=x86_64-w64-mingw32-gcc CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -o $(NAME).exe && tar zcfv "$(NAME)-windows-amd64.tar.gz" $(NAME).exe
    cd $(LIB_FSPATH) && rm -rf $(NAME).exe

build-win-fromlinux:
    #windows with cgo
    #apt-get install gcc-multilib 
    #apt-get install gcc-mingw-w64
    cd $(LIB_FSPATH) && CC=i686-w64-mingw32-gcc-win32 CGO_ENABLED=1 GOOS=windows GOARCH=386 go build -o $(NAME).exe && tar zcfv "$(NAME)-windows-386.tar.gz" $(NAME).exe
    cd $(LIB_FSPATH) && rm -rf $(NAME).exe
    cd $(LIB_FSPATH) && CC=x86_64-w64-mingw32-gcc CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -o $(NAME).exe && tar zcfv "$(NAME)-windows-amd64.tar.gz" $(NAME).exe
    cd $(LIB_FSPATH) && rm -rf $(NAME).exe

build-linux:
    #linux 
    go get github.com/godbus/dbus

    cd $(LIB_FSPATH) && CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -o $(NAME) -ldflags "-s -w" && tar zcfv "$(NAME)-linux-386.tar.gz" $(NAME)
    cd $(LIB_FSPATH) && rm -rf $(NAME)
    cd $(LIB_FSPATH) && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(NAME) -ldflags "-s -w" && tar zcfv "$(NAME)-linux-amd64.tar.gz" $(NAME)
    cd $(LIB_FSPATH) && rm -rf $(NAME)

build-darwin:
    #darwin
    cd $(LIB_FSPATH) && CGO_ENABLED=0 GOOS=darwin GOARCH=386 go build -o $(NAME) -ldflags "-s -w" && tar zcfv "$(NAME)-darwin-386.tar.gz" $(NAME)
    cd $(LIB_FSPATH) && rm -rf $(NAME)
    cd $(LIB_FSPATH) && CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o $(NAME) -ldflags "-s -w" && tar zcfv "$(NAME)-darwin-amd64.tar.gz" $(NAME)
    cd $(LIB_FSPATH) && rm -rf $(NAME)
gen2brain commented 5 years ago

Why do you want to build with CGO_ENABLED just on Windows? You need mingw toolchain if you are cross compiling something that use CGo, for native Go you don't need that.

ghost commented 5 years ago

I thought the toast lib needs cgo :)

It doesn't ?

On Fri, 28 Sep 2018, 14:29 Milan Nikolic, notifications@github.com wrote:

Why do you want to build with CGO_ENABLED just on Windows? You need mingw toolchain if you are cross compiling something that use CGo, for native Go you don't need that.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/gen2brain/beeep/issues/19#issuecomment-425420059, or mute the thread https://github.com/notifications/unsubscribe-auth/ATuCwowNL6QcM_POhN3SyqWpztSchi7mks5ufhYigaJpZM4W-Tfd .

gen2brain commented 5 years ago

Nope, it builds template file and executes it with powershell. No cgo.

gen2brain commented 5 years ago

Actually for Windows in most cases you don't need to use cgo, e.g. https://github.com/gen2brain/dlgs/blob/master/dlgs_windows.go , better than Linux. For win32 API everything can be done with syscall, I guess only for new apis you will need cgo.

ghost commented 5 years ago

Pat king of you to help me learn.

Will close ..