veandco / go-sdl2

SDL2 binding for Go
https://godoc.org/github.com/veandco/go-sdl2
BSD 3-Clause "New" or "Revised" License
2.17k stars 219 forks source link

Is it possible to compile to .app on macOS? Also, is there a way to hide terminal when building #574

Open Mariownyou opened 11 months ago

Mariownyou commented 11 months ago

Go version: latest Go-SDL2 version: SDL2 version: OS: macOS Architecture: Apple Silicon

veeableful commented 11 months ago

Hi @Mariownyou, Go doesn't build an .app file but you can create it yourself.

You can try building the program statically so all dependencies is contained using:

CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 go build -tags static -ldflags "-s -w" -o app

After that you can create the following directory structore for the app bundle. Here the name is GoSDL2.app as example.

GoSDL2.app
└── Contents
    ├── Info.plist
    ├── MacOS
    │   └── app
    └── Resources
        ├── app.icns
        └── example.bmp

The content of Info.plist is the following:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>CFBundleExecutable</key>
  <string>app</string>
  <key>CFBundleIconFile</key>
  <string>app</string>
</dict>
</plist>

Then you can copy the executable app to GoSDL2.app/Content/MacOS/ and if you have any resource like image files, you can put them under GoSDL2.app/Content/Resources/.

As for hiding terminal when building, could you elaborate more on that? Is that a problem somehow?

Mariownyou commented 11 months ago

Thank you for providing information regarding creating .app bundle.

About terminal issue, I would like to hide terminal when builing app image

veeableful commented 11 months ago

HI @Mariownyou, do you mean that you want to hide terminal when running the app instead of building the app? I think you could create the app bundle like above and run it. In that case it won't show the Terminal

Mariownyou commented 11 months ago

Thanks, I will try this :)