From 96a0f0e83ceee3ce52b89a5bd4e35f99700ea2f2 Mon Sep 17 00:00:00 2001 From: Sean Hickey Date: Wed, 28 Sep 2022 15:53:42 -0700 Subject: [PATCH] Add documentation and static build script for windows. --- .gitignore | 5 ++++- README.md | 4 +++- config/config.go | 16 ++++++++++++++++ docs/README.md | 14 ++++++++++++++ docs/setup/go-sdl-setup-windows.md | 8 ++++---- docs/setup/go-sdl-setup.md | 14 +++++++++++++- go.sum | 2 -- scripts/build-windows-static.sh | 19 +++++++++++++++++++ 8 files changed, 73 insertions(+), 9 deletions(-) create mode 100644 docs/README.md create mode 100644 scripts/build-windows-static.sh diff --git a/.gitignore b/.gitignore index 4cf9bb3..ff867fc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ # Emacs temp files *~ +# VSCode +.vscode + # SDL libraries SDL*.dll SDL*.so @@ -9,4 +12,4 @@ SDL*.a # Build output *.exe output.log -project-ely +/project-ely* diff --git a/README.md b/README.md index faaccdc..15910aa 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,9 @@ This project is written in Go using SDL2. ## Compiling -You can use the Makefile: +See the [Setup Docs][1] for installing all the necessary dependencies. It's fairly bare-bones, only requiring SDL. + +Then you can use the Makefile: ```sh make release ``` diff --git a/config/config.go b/config/config.go index 9bf133f..834b0b3 100644 --- a/config/config.go +++ b/config/config.go @@ -1,11 +1,27 @@ package config import ( + "os" + "gitea.wisellama.rocks/Wisellama/gosimpleconf" ) +var defaultConfig gosimpleconf.ConfigMap = gosimpleconf.ConfigMap{ + "game.title": "Project Ely", + "log.writeToFile": "false", +} + func Configure(filename string) (gosimpleconf.ConfigMap, error) { var err error + + _, err = os.Stat(filename) + if os.IsNotExist(err) { + // Config file does not exist, return a default configMap + return defaultConfig, nil + } else if err != nil { + return nil, err + } + configMap, err := gosimpleconf.Load(filename) if err != nil { return nil, err diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..374f59c --- /dev/null +++ b/docs/README.md @@ -0,0 +1,14 @@ +# Docs + +Extra documentation to help with the project. + +To get started, see the [Setup][1] directory first. It will help you install the depends and get the development environment set up. + +Then there are some other notes and things in this directory that might be helpful. + +## Scripts + +There are some scripts in the [Scripts][2] directory that may be useful. One of them specifically builds a statically-linked Windows binary for easy distribution. + +[1]: setup +[2]: scripts diff --git a/docs/setup/go-sdl-setup-windows.md b/docs/setup/go-sdl-setup-windows.md index c55389c..b1b7414 100644 --- a/docs/setup/go-sdl-setup-windows.md +++ b/docs/setup/go-sdl-setup-windows.md @@ -62,12 +62,12 @@ Go to start menu, search for "env", and select "edit the system environment vari Set the following env variables (change the username directory to match your username as needed). First we need to set GCC as our default C compiler: -``` +```conf CC = gcc -`` +``` Then we need to enable CGO (allowing the Go compiler to use a C compiler too): -``` +```conf CGO_ENABLED = 1 ``` @@ -78,7 +78,7 @@ C_INCLUDE_PATH = C:\Users\Username\GCC\x86_64-12.1.0-release-win32-seh-rt_v10-re Then we need to set our "library" path. This is all of the directories that contain compiled library files (on Windows these are `*.dll` files) that can be imported into our code. This only needs to add all of the SDL2 directories. ``` -LIBRARY_PATH = C:\Users\Username\SDL2\SDL2-2.24.0\x86_64-w64-mingw32\bin;C:\Users\Username\SDL2\SDL2_ttf-2.20.1\x86_64-w64-mingw32\bin;C:\Users\Username\SDL2\SDL2_mixer-2.6.2\x86_64-w64-mingw32\bin;C:\Users\Username\SDL2\SDL2_image-2.6.2\x86_64-w64-mingw32\bin; +LIBRARY_PATH = C:\Users\Username\SDL2\SDL2-2.24.0\x86_64-w64-mingw32\lib;C:\Users\Username\SDL2\SDL2_ttf-2.20.1\x86_64-w64-mingw32\lib;C:\Users\Username\SDL2\SDL2_mixer-2.6.2\x86_64-w64-mingw32\lib;C:\Users\Username\SDL2\SDL2_image-2.6.2\x86_64-w64-mingw32\lib; ``` And depending on how you installed GCC, you may need to also add its `bin` directory to your path so that you will be able to call the `gcc` compiler. There are probably other entries already in your `PATH` variable, so just add this as an additional entry: diff --git a/docs/setup/go-sdl-setup.md b/docs/setup/go-sdl-setup.md index 3a644f1..cd3cb95 100644 --- a/docs/setup/go-sdl-setup.md +++ b/docs/setup/go-sdl-setup.md @@ -12,6 +12,8 @@ You will need the following dependencies: That's all, you may even have most of them installed already. +I also use [golangci-lint][6] as a Go linter. This is used by the Makefile before running `go build`. You can either install this from your package manager or with `go install`. To work-around this, you can just run `go build` directly without the makefile or edit the linter section of the makefile to do nothing. + ### Debian As the most common example, on Debian or Ubuntu, the following `apt` command should install all the dependencies: @@ -55,8 +57,18 @@ As a reference for the BSD crowd, the dependencies in pkgsrc are: I apologize for not adding more systems, but at some point this list gets annoyingly long to repeat the same thing. Your distribution should almost certainly have these dependencies, and they will be named something similar to the above examples. +## Build + +You can use the Makefile to run +```sh +make release +``` + +or you can use `go build` directly. + [1]: http://pkgsrc.org/ [2]: https://go.dev/ [3]: https://unix.stackexchange.com/q/8049 [4]: https://unix.stackexchange.com/q/107689 -[5]: https://brew.sh/ \ No newline at end of file +[5]: https://brew.sh/ +[6]: https://golangci-lint.run/usage/install/ diff --git a/go.sum b/go.sum index 1a054ca..ab424cd 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,3 @@ -gitea.wisellama.rocks/Wisellama/gosimpleconf v0.0.3 h1:g4hcc7TjodjMNrSEQ3UO96HXvltHc2EOiudS+Wfle60= -gitea.wisellama.rocks/Wisellama/gosimpleconf v0.0.3/go.mod h1:kY9gQL8laVTe+tW0ue5bYb6QThw78d7mx6AHwQ5CIzc= gitea.wisellama.rocks/Wisellama/gosimpleconf v0.0.4 h1:xFjG/dGPUoh1L7/PG9xQRr0GQZwlh1EGI9RnG8Ja8R8= gitea.wisellama.rocks/Wisellama/gosimpleconf v0.0.4/go.mod h1:kY9gQL8laVTe+tW0ue5bYb6QThw78d7mx6AHwQ5CIzc= github.com/veandco/go-sdl2 v0.4.25 h1:J5ac3KKOccp/0xGJA1PaNYKPUcZm19IxhDGs8lJofPI= diff --git a/scripts/build-windows-static.sh b/scripts/build-windows-static.sh new file mode 100644 index 0000000..05ea7a4 --- /dev/null +++ b/scripts/build-windows-static.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env sh + +# This is intended to run in Git Bash on Windows. +# This builds a statically-linked release version of the binary ready to be deployed. + +OUTPUT=project-ely + +build(){ + OS=$1 + ARCH=$2 + + CGO_ENABLED=1 \ + CC=gcc \ + GOOS=$OS \ + GOARCH=$ARCH \ + go build -x -v -trimpath -tags static -ldflags="-s -w -H windowsgui" -o "${OUTPUT}-${OS}-${ARCH}.exe" +} + +build windows amd64