diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index a371f2f15..8126afc20 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -37,25 +37,26 @@ jobs: echo 'deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main' | sudo tee -a /etc/apt/sources.list sudo apt update sudo apt-get install -y clang-format-17 iwyu + sudo snap install --edge --classic just sudo ln -s /usr/bin/clang-format-17 /usr/local/bin/clang-format - sudo apt-get install -y make python3-pip + sudo apt-get install -y python3-pip sudo python3 -m pip install pyjson5 + - name: Check formatted code differences + run: | + just lint-format + git diff --exit-code || ( + clang-format --version + echo 'Please run `just lint` and commit the changes.' + exit 1 + ) + - name: Check imports run: | git add -A - make lint_imports + just lint-imports git diff --exit-code || ( include-what-you-use --version - echo 'Please run `make lint` and commit the changes.' - exit 1 - ) - - - name: Check formatted code differences - run: | - make lint_format - git diff --exit-code || ( - clang-format --version - echo 'Please run `make lint` and commit the changes.' + echo 'Please run `just lint` and commit the changes.' exit 1 ) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9c3faa24c..22a31e78c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -136,11 +136,13 @@ jobs: run: | echo "$GITHUB_CONTEXT" sudo apt-get update - sudo apt-get install -y make moby-engine moby-cli + sudo apt-get install -y moby-engine moby-cli + sudo snap install --edge --classic just - name: Build the game run: | - make clean release + just clean + just build-win release mkdir out/ cp build/win/*.exe out/ cp -r bin/* out/ @@ -171,7 +173,8 @@ jobs: - name: Install dependencies run: | sudo apt-get update - sudo apt-get install -y make p7zip-full + sudo apt-get install -y p7zip-full + sudo snap install --edge --classic just - name: Package the game run: | @@ -199,11 +202,13 @@ jobs: run: | echo "$GITHUB_CONTEXT" sudo apt-get update - sudo apt-get install -y make moby-engine moby-cli + sudo apt-get install -y moby-engine moby-cli + sudo snap install --edge --classic just - name: Build the game run: | - make clean release-linux + just clean + just build-linux release mkdir out/ cp build/linux/TR1X out/ cp -r bin/* out/ @@ -228,7 +233,8 @@ jobs: - name: Install dependencies run: | sudo apt-get update - sudo apt-get install -y make p7zip-full + sudo apt-get install -y p7zip-full + sudo snap install --edge --classic just - name: Package the game run: | diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a7d6c65ba..07e8ed23e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,8 +20,9 @@ Subsequent builds: - **With Docker**: - Make sure to install Docker and make, then run `make debug`. - The binaries should appear in the `build/` directory. + Make sure to install Docker and [just](https://github.com/casey/just), then + run `just`. The binaries should appear in the `build/` directory. + To see list of possible build targets, run `just -l`. - **Without Docker**: @@ -98,7 +99,7 @@ Other things: This project uses `clang-format` to take care of automatic code formatting, and `include-what-you-use` to remove unused `#include`s. To ensure your code -conforms to the standard, please run `make lint` after each commit. If for some +conforms to the standard, please run `just lint` after each commit. If for some reason you can't run it, don't worry, our CI pipeline will show what needs to be changed in case of mistakes. diff --git a/Makefile b/Makefile deleted file mode 100644 index 338fb21a5..000000000 --- a/Makefile +++ /dev/null @@ -1,78 +0,0 @@ -CWD = $(shell pwd) -HOST_USER_UID = $(shell id -u) -HOST_USER_GID = $(shell id -g) - -define build - $(eval TARGET := $(1)) - mkdir -p build - docker run --rm \ - --user $(HOST_USER_UID):$(HOST_USER_GID) \ - -e TARGET="$(TARGET)" \ - -v $(CWD):/app/ \ - rrdash/tr1x:latest -endef - -define build-linux - $(eval TARGET := $(1)) - mkdir -p build - docker run --rm \ - --user $(HOST_USER_UID):$(HOST_USER_GID) \ - -e TARGET="$(TARGET)" \ - -v $(CWD):/app/ \ - rrdash/tr1x-linux:latest -endef - -debug: - $(call build,debug) - -debugopt: - $(call build,debugoptimized) - -release: - $(call build,release) - -build-docker-image: - docker build --progress plain . -f docker/game-win/Dockerfile -t rrdash/tr1x - -build-docker-image-linux: - docker build --progress plain . -f docker/game-linux/Dockerfile -t rrdash/tr1x-linux - -debug-linux: - $(call build-linux,debug) - -debugopt-linux: - $(call build-linux,debugoptimized) - -release-linux: - $(call build-linux,release) - -clean: - -find build/ -type f -delete - -find tools/ -type f \( -ipath '*/out/*' -or -ipath '*/bin/*' -or -ipath '*/obj/*' \) -delete - -find . -mindepth 1 -empty -type d -delete - -lint_imports: - tools/sort_imports - -lint_format: - bash -c 'shopt -s globstar; clang-format -i **/*.c **/*.h' - -lint: lint_format lint_imports - -installer: - docker build . -f docker/installer/Dockerfile -t rrdash/tr1x_installer - docker run --rm \ - --user $(HOST_USER_UID):$(HOST_USER_GID) \ - --network host \ - -v $(CWD):/app/ \ - rrdash/tr1x_installer - -config: - docker build . -f docker/config/Dockerfile -t rrdash/tr1x_config - docker run --rm \ - --user $(HOST_USER_UID):$(HOST_USER_GID) \ - --network host \ - -v $(CWD):/app/ \ - rrdash/tr1x_config - -.PHONY: debug debugopt release clean lint_imports lint_format lint installer config diff --git a/justfile b/justfile new file mode 100644 index 000000000..a99a1780c --- /dev/null +++ b/justfile @@ -0,0 +1,55 @@ +CWD := `pwd` +HOST_USER_UID := `id -u` +HOST_USER_GID := `id -g` + +default: (build-win "debug") + +_docker_build dockerfile tag force="0": + #!/usr/bin/env sh + docker images | grep {{tag}} >/dev/null + if [ $? -eq 0 ] && [ "{{force}}" = "0" ]; then + echo "Docker image {{dockerfile}} is already built" + else + echo "Building Docker image: {{dockerfile}} → {{tag}}" + docker build \ + --progress plain \ + . \ + -f {{dockerfile}} \ + -t {{tag}} + fi + +_docker_run *args: + @echo "Running docker image: {{args}}" + docker run \ + --rm \ + --user \ + {{HOST_USER_UID}}:{{HOST_USER_GID}} \ + --network host \ + -v {{CWD}}:/app/ \ + {{args}} + + +image-win force="1": (_docker_build "docker/game-win/Dockerfile" "rrdash/tr1x" force) +image-linux force="1": (_docker_build "docker/game-linux/Dockerfile" "rrdash/tr1x-linux" force) +image-config force="1": (_docker_build "docker/config/Dockerfile" "rrdash/tr1x-config" force) +image-installer force="1": (_docker_build "docker/installer/Dockerfile" "rrdash/tr1x-installer" force) + +build-win target='debug': (image-win "0") (_docker_run "-e" "TARGET="+target "rrdash/tr1x") +build-linux target='debug': (image-linux "0") (_docker_run "-e" "TARGET="+target "rrdash/tr1x-linux") +build-config: (image-config "0") (_docker_run "rrdash/tr1x-config") +build-installer: (image-installer "0") (_docker_run "rrdash/tr1x-installer") + +clean: + -find build/ -type f -delete + -find tools/ -type f \( -ipath '*/out/*' -or -ipath '*/bin/*' -or -ipath '*/obj/*' \) -delete + -find . -mindepth 1 -empty -type d -delete + +lint-imports: + tools/sort_imports + +lint-format: + #!/usr/bin/env bash + shopt -s globstar + clang-format -i **/*.{c,h} + +lint: (lint-imports) (lint-format)