diff --git a/documents/building-linux.md b/documents/building-linux.md index 979f65969..9acbfd624 100644 --- a/documents/building-linux.md +++ b/documents/building-linux.md @@ -48,12 +48,6 @@ sudo zypper install clang git cmake libasound2 libpulse-devel \ vulkan-devel vulkan-validationlayers libpng-devel ``` -#### NixOS - -```bash -nix-shell shell.nix -``` - #### Nix Flake Development Shell ```bash nix develop @@ -63,13 +57,13 @@ ln -s ./build/compile_commands.json . #### Nix Flake Build ```bash -nix build .?submodules=1#linux.debug +nix build .?submodules=1#debug ``` ```bash -nix build .?submodules=1#linux.release +nix build .?submodules=1#release ``` ```bash -nix build .?submodules=1#linux.releaseWithDebugInfo +nix build .?submodules=1#releaseWithDebugInfo ``` #### Other Linux distributions diff --git a/flake.lock b/flake.lock index 246cfd4e7..f52cab975 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1774386573, - "narHash": "sha256-4hAV26quOxdC6iyG7kYaZcM3VOskcPUrdCQd/nx8obc=", + "lastModified": 1779560665, + "narHash": "sha256-tpyBcxPpcQb8ukyNF7DoCwfSY3VPsxHoYwj00Cayv5o=", "owner": "nixos", "repo": "nixpkgs", - "rev": "46db2e09e1d3f113a13c0d7b81e2f221c63b8ce9", + "rev": "64c08a7ca051951c8eae34e3e3cb1e202fe36786", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index cfc1587bf..19d3b9ba9 100644 --- a/flake.nix +++ b/flake.nix @@ -16,127 +16,259 @@ { formatter.x86_64-linux = pkgsLinux.nixpkgs-fmt; - devShells.x86_64-linux.default = pkgsLinux.mkShell.override { stdenv = pkgsLinux.clangStdenv; } { - packages = with pkgsLinux; [ - clang-tools - cmake - pkg-config - vulkan-tools - - renderdoc - gef - strace - perf - - openal - zlib.dev - libedit.dev - vulkan-headers - vulkan-utility-libraries - ffmpeg.dev - fmt.dev - glslang.dev - wayland.dev - stb - libpng.dev - libuuid - - sdl3.dev - alsa-lib - hidapi - ibus.dev - jack2.dev - libdecor.dev - libthai.dev - fribidi.dev - libxcb.dev - libGL.dev - libpulseaudio.dev - libusb1.dev - libx11.dev - libxcursor.dev - libxext - libxfixes.dev - libxi.dev - libxinerama.dev - libxkbcommon - libxrandr.dev - libxrender.dev - libxtst - pipewire.dev - libxscrnsaver - sndio - ]; - shellHook = '' - echo "Entering shadPS4 development shell!" - ''; - - CMAKE_C_COMPILER = "clang"; - CMAKE_CXX_COMPILER = "clang++"; - CMAKE_EXPORT_COMPILE_COMMANDS = "ON"; - }; - - linux = + devShells.x86_64-linux.default = let - nativeInputs = with pkgsLinux; [ - cmake - ninja - pkg-config - magic-enum - fmt - eudev - ]; - buildInputs = with pkgsLinux; [ - boost - cli11 - openal - nlohmann_json - vulkan-loader - vulkan-headers - vulkan-memory-allocator - toml11 - zlib - zydis - pugixml - ffmpeg - libpulseaudio - pipewire - vulkan-loader - wayland - wayland-scanner - libX11 - libxrandr - libxext - libxcursor - libxi - libxscrnsaver - libxtst - libxcb - libdecor - libxkbcommon - libGL - libuuid - miniz - libressl - ]; + shell = + { mkShell + , clangStdenv + , clang-tools + , cmake + , pkg-config + , vulkan-tools + , renderdoc + , gef + , strace + , perf + , openal + , zlib + , libedit + , vulkan-headers + , vulkan-utility-libraries + , ffmpeg + , fmt + , glslang + , wayland + , stb + , libpng + , libuuid + , sdl3 + , alsa-lib + , hidapi + , ibus + , jack2 + , libdecor + , libthai + , fribidi + , libxcb + , libGL + , libpulseaudio + , libusb1 + , libx11 + , libxcursor + , libxext + , libxfixes + , libxi + , libxinerama + , libxkbcommon + , libxrandr + , libxrender + , libxtst + , pipewire + , libxscrnsaver + , sndio + , cli11 + , nlohmann_json + , spdlog + , + }: - build = { debugSymbols ? true, buildFlags }: pkgsLinux.clangStdenv.mkDerivation { - pname = "shadps4"; - version = "15.1"; - system = "x86_64-linux"; - src = ./.; + mkShell.override { stdenv = clangStdenv; } { + packages = [ + clang-tools + cmake + pkg-config + vulkan-tools - dontStrip = if debugSymbols then true else false; + renderdoc + gef + strace + perf - nativeBuildInputs = nativeInputs; - buildInputs = buildInputs; - cmakeFlags = buildFlags; - }; + openal + zlib.dev + libedit.dev + vulkan-headers + vulkan-utility-libraries + ffmpeg.dev + fmt.dev + glslang.dev + wayland.dev + stb + libpng.dev + libuuid + cli11 + nlohmann_json + spdlog.dev + + sdl3.dev + alsa-lib + hidapi + ibus.dev + jack2.dev + libdecor.dev + libthai.dev + fribidi.dev + libxcb.dev + libGL.dev + libpulseaudio.dev + libusb1.dev + libx11.dev + libxcursor.dev + libxext + libxfixes.dev + libxi.dev + libxinerama.dev + libxkbcommon + libxrandr.dev + libxrender.dev + libxtst + pipewire.dev + libxscrnsaver + sndio + ]; + + shellHook = '' + echo "Entering shadPS4 development shell!" + ''; + + CMAKE_C_COMPILER = "clang"; + CMAKE_CXX_COMPILER = "clang++"; + CMAKE_EXPORT_COMPILE_COMMANDS = "ON"; + }; + + in + pkgsLinux.callPackage shell { }; + + packages.x86_64-linux = + let + build = + { clangStdenv + , cmake + , ninja + , pkg-config + , magic-enum + , fmt + , eudev + , boost + , cli11 + , openal + , nlohmann_json + , vulkan-loader + , vulkan-headers + , vulkan-memory-allocator + , toml11 + , zlib + , zydis + , pugixml + , ffmpeg + , libpulseaudio + , pipewire + , wayland + , wayland-scanner + , libX11 + , libxrandr + , libxext + , libxcursor + , libxi + , libxscrnsaver + , libxtst + , libxcb + , libdecor + , libxkbcommon + , libGL + , libuuid + , miniz + , libressl + , src + , system + , cmakeFlags + , dontStrip ? true + , + }: + + clangStdenv.mkDerivation (finalAttrs: { + inherit src system cmakeFlags dontStrip; + + pname = "shadps4"; + version = "0.15.1"; + + nativeBuildInputs = [ + cmake + ninja + pkg-config + magic-enum + fmt + eudev + ]; + buildInputs = [ + boost + cli11 + openal + nlohmann_json + vulkan-loader + vulkan-headers + vulkan-memory-allocator + toml11 + zlib + zydis + pugixml + ffmpeg + libpulseaudio + pipewire + wayland + wayland-scanner + libX11 + libxrandr + libxext + libxcursor + libxi + libxscrnsaver + libxtst + libxcb + libdecor + libxkbcommon + libGL + libuuid + miniz + libressl + ]; + + # Cannot get the Branch name from the sandbox. + # Getting the commit hash can still be acquired through self. + patchPhase = '' + substituteInPlace src/common/scm_rev.cpp.in \ + --replace-fail "@GIT_BRANCH@" "${self.shortRev or "Dirty"}" + + substituteInPlace src/common/scm_rev.cpp.in \ + --replace-fail "@GIT_DESC@" "" + ''; + }); + + debugBuild = pkgsLinux.callPackage build + { + src = "${self}"; + system = "x86_64-linux"; + cmakeFlags = [ "-DCMAKE_BUILD_TYPE=Debug" ]; + }; + releaseBuild = pkgsLinux.callPackage build + { + src = "${self}"; + system = "x86_64-linux"; + dontStrip = false; + cmakeFlags = [ "-DCMAKE_BUILD_TYPE=Release" ]; + }; + releaseWithDebugInfoBuild = pkgsLinux.callPackage build + { + src = "${self}"; + system = "x86_64-linux"; + cmakeFlags = [ "-DCMAKE_BUILD_TYPE=RelWithDebInfo" ]; + }; in { - debug = build { buildFlags = [ "-DCMAKE_BUILD_TYPE=Debug" ]; }; - release = build { debugSymbols = false; buildFlags = [ "-DCMAKE_BUILD_TYPE=Release" ]; }; - releaseWithDebugInfo = build { buildFlags = [ "-DCMAKE_BUILD_TYPE=RelWithDebInfo" ]; }; + debug = debugBuild; + release = releaseBuild; + releaseWithDebugInfo = releaseWithDebugInfoBuild; + default = releaseWithDebugInfoBuild; }; }; } diff --git a/shell.nix b/shell.nix deleted file mode 100644 index 611095268..000000000 --- a/shell.nix +++ /dev/null @@ -1,64 +0,0 @@ -# SPDX-FileCopyrightText: 2024 shadPS4 Emulator Project -# SPDX-License-Identifier: GPL-2.0-or-later - -with import (fetchTarball "https://github.com/nixos/nixpkgs/archive/cfd19cdc54680956dc1816ac577abba6b58b901c.tar.gz") { }; - -pkgs.mkShell { - name = "shadps4-build-env"; - - nativeBuildInputs = with pkgs; [ - llvmPackages_18.clang - cmake - pkg-config - git - util-linux - ]; - - buildInputs = with pkgs; [ - alsa-lib - libpulseaudio - openal - zlib - libedit - udev - libevdev - SDL2 - jack2 - sndio - - vulkan-headers - vulkan-utility-libraries - vulkan-tools - - ffmpeg - fmt - glslang - libxkbcommon - wayland - xorg.libxcb - xorg.xcbutil - xorg.xcbutilkeysyms - xorg.xcbutilwm - sdl3 - stb - wayland-protocols - libpng - ]; - - shellHook = '' - echo "Entering shadPS4 dev shell" - export CMAKE_PREFIX_PATH="${pkgs.vulkan-headers}:$CMAKE_PREFIX_PATH" - - # OpenGL - export LD_LIBRARY_PATH="${ - pkgs.lib.makeLibraryPath [ - pkgs.libglvnd - pkgs.vulkan-tools - ] - }:$LD_LIBRARY_PATH" - - export LDFLAGS="-L${pkgs.llvmPackages_18.libcxx}/lib -lc++" - export LC_ALL="C.UTF-8" - export XAUTHORITY=${builtins.getEnv "XAUTHORITY"} - ''; -}