From 5e9d8ea9d2995770fe5e0ef0c8d178d86d440ad4 Mon Sep 17 00:00:00 2001 From: yvt Date: Thu, 29 Apr 2021 23:24:02 +0900 Subject: [PATCH 1/5] chore(nix): `shell.nix` --- shell.nix | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 shell.nix diff --git a/shell.nix b/shell.nix new file mode 100644 index 000000000..98d88257e --- /dev/null +++ b/shell.nix @@ -0,0 +1,17 @@ +with import {}; + +with pkgs.xorg; + +runCommand "dummy" rec { + nativeBuildInputs = [ cmake imagemagick unzip zip file gcc ]; + + buildInputs = [ + freetype SDL2 SDL2_image libGL zlib curl glew opusfile openal libogg pkgconfig libopus libGLU + libXext pkg-config + ]; + + NIX_CFLAGS_LINK = [ "-L${libXext}/lib" ]; + NIX_CFLAGS_COMPILE= ["-I${libogg.dev}/include" "-I${libopus.dev}/include" "-I${libGLU.dev}/include" ]; + + LD_LIBRARY_PATH = [ "${openal}/lib" ]; +} "" From e7d95e5831753feb5f0c611f0a7cc3d9e8399313 Mon Sep 17 00:00:00 2001 From: yvt Date: Thu, 29 Apr 2021 23:24:32 +0900 Subject: [PATCH 2/5] chore: fixes for NixOS --- CMakeLists.txt | 2 ++ cmake/FindGLEW2.cmake | 6 ++++++ cmake/FindOpus.cmake | 30 ++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 310930351..2c35e3264 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -247,6 +247,8 @@ else() include_directories(${CURL_INCLUDE_DIRS}) include_directories(${FREETYPE_INCLUDE_DIRS}) include_directories(${OpusFile_INCLUDE_DIR}) + include_directories(${Opus_INCLUDE_DIR}) + include_directories(${Ogg_INCLUDE_DIR}) endif() add_subdirectory(Resources) diff --git a/cmake/FindGLEW2.cmake b/cmake/FindGLEW2.cmake index 36a3abe86..1e5c370e6 100644 --- a/cmake/FindGLEW2.cmake +++ b/cmake/FindGLEW2.cmake @@ -36,6 +36,12 @@ ELSE (WIN32) /sw/lib /opt/local/lib DOC "The GLEW library") + FIND_PATH( GLU_INCLUDE_DIR GL/glu.h + /usr/include + /usr/local/include + /sw/include + /opt/local/include + DOC "The directory where GL/glu.h resides") ENDIF (WIN32) IF (GLEW_INCLUDE_DIR) diff --git a/cmake/FindOpus.cmake b/cmake/FindOpus.cmake index 879af81c8..6475de7db 100644 --- a/cmake/FindOpus.cmake +++ b/cmake/FindOpus.cmake @@ -25,6 +25,36 @@ FIND_LIBRARY(OpusFile_LIBRARY /opt ) +FIND_PATH(Opus_INCLUDE_DIR opus/opus_multistream.h + HINTS + $ENV{OPUSDIR} + PATH_SUFFIXES include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local/include/SDL2 + /usr/include/SDL2 + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt +) + +FIND_PATH(Ogg_INCLUDE_DIR ogg/ogg.h + HINTS + $ENV{OPUSDIR} + PATH_SUFFIXES include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local/include/SDL2 + /usr/include/SDL2 + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt +) + set(OpusFile_FOUND "NO") if(OpusFile_INCLUDE_DIR AND OpusFile_LIBRARY) set(OpusFile_FOUND "YES") From 6844e7100c6175e244c221fa17daf4e5e37d78f9 Mon Sep 17 00:00:00 2001 From: yvt Date: Sat, 2 Jul 2022 23:04:59 +0900 Subject: [PATCH 3/5] chore(res): support copying the development package from a local file This is useful for Nix, where network access is unavailable during a build. --- Resources/downloadpak.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Resources/downloadpak.sh b/Resources/downloadpak.sh index e180c37f5..8bb46a1f2 100755 --- a/Resources/downloadpak.sh +++ b/Resources/downloadpak.sh @@ -27,8 +27,13 @@ OUTPUT_DIR="." if [ -f "$PAK_NAME" ]; then exit 0 fi +# TODO: Check if the extracted files are present and up-to-date (#988) -wget "$PAK_URL" -O "$PAK_NAME" +if [ -n "$OPENSPADES_DEVPAK_PATH" ]; then + cp "$OPENSPADES_DEVPAK_PATH" "$PAK_NAME" +else + wget "$PAK_URL" -O "$PAK_NAME" +fi unzip -o "$PAK_NAME" -d "$OUTPUT_DIR" # relocate paks to the proper location From ada6a8e739cece3eca35655bcf08c99e31f8493a Mon Sep 17 00:00:00 2001 From: yvt Date: Sat, 2 Jul 2022 23:24:02 +0900 Subject: [PATCH 4/5] chore(nix): add Nix flake --- .gitignore | 4 ++++ README.md | 20 +++++++++++++++++ flake.lock | 41 +++++++++++++++++++++++++++++++++++ flake.nix | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ shell.nix | 25 +++++++--------------- 5 files changed, 136 insertions(+), 17 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.gitignore b/.gitignore index 095224642..d3fb3824c 100644 --- a/.gitignore +++ b/.gitignore @@ -63,6 +63,10 @@ OpenSpades.msvc/ # Linux build path openspades.mk/ +# Nix +/outputs +/result + # fltk / fluid output leftovers Sources/Gui/DetailConfigWindow.txt Sources/Gui/MainWindow.txt diff --git a/README.md b/README.md index 067b10433..6967fc9d5 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,26 @@ Alternatively, to install the game to a different directory, take the following After successful installation, optionally you can remove the source code and build outputs to save disk space (~100MB). +#### On Linux (from source, by Nix Flakes) +To build and run OpenSpades from the latest source code: + +```bash +nix shell github:yvt/openspades -c openspades +``` + +To build and run OpenSpades for development: + +```bash +git clone https://github.com/yvt/openspades.git && cd openspades +nix develop +# note: this will patch CMake files in the source tree +cmakeBuildType=RelWithDebInfo cmakeConfigurePhase +buildPhase +bin/openspades +``` + +**note**: Nix Flakes are an experimental feature of Nix and must be enabled manually. See [this wiki article](https://nixos.wiki/wiki/Flakes) for how to do that. + ### On Windows (with Visual Studio) 1. Get the required software if you haven't already: * CMake 2.8+ diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..0eb4c7cbb --- /dev/null +++ b/flake.lock @@ -0,0 +1,41 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1656065134, + "narHash": "sha256-oc6E6ByIw3oJaIyc67maaFcnjYOz1mMcOtHxbEf9NwQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "bee6a7250dd1b01844a2de7e02e4df7d8a0a206c", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1656633783, + "narHash": "sha256-nXMIGtQXBGzO57nkPxgEOx8HLRwVQ+d1WkOnE01JG4A=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "95e79164be1f7d883ed9ffda8b7d4ad3a17e6c1e", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..ebd3a081b --- /dev/null +++ b/flake.nix @@ -0,0 +1,63 @@ +{ + description = "A compatible client of Ace of Spades 0.75"; + + inputs = { + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem + (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + inherit (pkgs) stdenv; + + # Non-GPL assets - please see `PakLocation.txt` for the terms of use + # and issue #424 for the situation + devPackage = pkgs.fetchurl { + url = https://github.com/yvt/openspades-paks/releases/download/r33/OpenSpadesDevPackage-r33.zip; + sha256 = "CSfcMjoLOroO6NHWjWtUSwD+ZUdA/q1tH6rTeqx3oq0="; + }; + # Google Noto Fonts, licensed under the SIL Open Font License + notoFontPak = pkgs.fetchurl { + url = https://github.com/yvt/openspades/releases/download/v0.1.1b/NotoFonts.pak; + sha256 = "VQYMZNYqNBZ9+01YCcabqqIfck/mU/BRcFZKXpBEX00="; + }; + in rec { + packages.default = packages.openspades; + + packages.openspades = stdenv.mkDerivation rec { + pname = "openspades"; + version = "0.1.5-beta"; + + src = ./.; + + nativeBuildInputs = with pkgs; [ cmake imagemagick unzip zip file ]; + + buildInputs = with pkgs; + ([ + freetype SDL2 SDL2_image libGL zlib curl glew opusfile openal libogg + ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ + darwin.apple_sdk.frameworks.Cocoa + ]); + + cmakeFlags = [ "-DOPENSPADES_INSTALL_BINARY=bin" ]; + + inherit notoFontPak; + + # Used by `downloadpak.sh`. Instructs the script to copy the + # development package from this path instead of downloading it. + OPENSPADES_DEVPAK_PATH = devPackage; + + postPatch = '' + patchShebangs Resources + ''; + + postInstall = '' + cp $notoFontPak $out/share/games/openspades/Resources/ + ''; + + NIX_CFLAGS_LINK = "-lopenal"; + }; + }); +} \ No newline at end of file diff --git a/shell.nix b/shell.nix index 98d88257e..d5e1a215b 100644 --- a/shell.nix +++ b/shell.nix @@ -1,17 +1,8 @@ -with import {}; - -with pkgs.xorg; - -runCommand "dummy" rec { - nativeBuildInputs = [ cmake imagemagick unzip zip file gcc ]; - - buildInputs = [ - freetype SDL2 SDL2_image libGL zlib curl glew opusfile openal libogg pkgconfig libopus libGLU - libXext pkg-config - ]; - - NIX_CFLAGS_LINK = [ "-L${libXext}/lib" ]; - NIX_CFLAGS_COMPILE= ["-I${libogg.dev}/include" "-I${libopus.dev}/include" "-I${libGLU.dev}/include" ]; - - LD_LIBRARY_PATH = [ "${openal}/lib" ]; -} "" +# Flake's devShell for non-flake-enabled nix instances +let + compat = builtins.fetchGit { + url = "https://github.com/edolstra/flake-compat.git"; + rev = "b4a34015c698c7793d592d66adbab377907a2be8"; + }; +in + (import compat {src = ./.;}).shellNix.default From 1cd7214eaa2daa3e88a3e79fff2f569b5007c4e4 Mon Sep 17 00:00:00 2001 From: yvt Date: Sat, 2 Jul 2022 22:32:11 +0900 Subject: [PATCH 5/5] chore(ci): build Nix flake --- .github/workflows/ci.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b0ad3187e..d85b94435 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,3 +67,17 @@ jobs: build-type: RelWithDebInfo configure-options: -D CMAKE_BUILD_TYPE=RelWithDebInfo -D CMAKE_TOOLCHAIN_FILE=${{ runner.workspace }}/openspades/vcpkg/scripts/buildsystems/vcpkg.cmake -D VCPKG_TARGET_TRIPLET=x64-osx -D CMAKE_OSX_ARCHITECTURES=x86_64 parallel: 8 + + build-nix: + name: Build (Linux + Nix) + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install Nix + uses: cachix/install-nix-action@v17 + + - name: Build Nix flake + run: nix build +