Skip to content

Commit 18b5372

Browse files
committed
duckstation-unofficial: init at 0.1-9384
This is a soft-revert of duckstation's removal in NixOS#430501 (revision: f5cb574) and placing it under the `duckstation-unofficial` attribute which supports both linux and darwin platforms, most of the previously submitted code and patches still apply and this commit squashes everything together into one package file and thus is a combination of work done by different authors, listed below to the best of my ability: Co-developed-by: Marcin Serwin <[email protected]> Co-developed-by: Anderson Torres <[email protected]> Co-developed-by: OPNA2608 <[email protected]> Co-developed-by: qubitnano <[email protected]> Co-developed-by: PedroHLC ☭ <[email protected]> Co-developed-by: Artturin <[email protected]> Co-developed-by: Guillaume Bouchard <[email protected]>
1 parent f962ff8 commit 18b5372

File tree

5 files changed

+481
-0
lines changed

5 files changed

+481
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
diff --git a/dep/CMakeLists.txt b/dep/CMakeLists.txt
2+
index 633267c66..8f9c65c39 100644
3+
--- a/dep/CMakeLists.txt
4+
+++ b/dep/CMakeLists.txt
5+
@@ -25,9 +25,9 @@ add_subdirectory(rcheevos EXCLUDE_FROM_ALL)
6+
disable_compiler_warnings_for_target(rcheevos)
7+
add_subdirectory(rapidyaml EXCLUDE_FROM_ALL)
8+
disable_compiler_warnings_for_target(rapidyaml)
9+
-add_subdirectory(cubeb EXCLUDE_FROM_ALL)
10+
-disable_compiler_warnings_for_target(cubeb)
11+
-disable_compiler_warnings_for_target(speex)
12+
+find_package(cubeb REQUIRED GLOBAL)
13+
+add_library(cubeb ALIAS cubeb::cubeb)
14+
+# disable_compiler_warnings_for_target(speex)
15+
16+
if(ENABLE_OPENGL)
17+
add_subdirectory(glad EXCLUDE_FROM_ALL)
18+
diff --git a/src/util/cubeb_audio_stream.cpp b/src/util/cubeb_audio_stream.cpp
19+
index e01cbfe78..294c6e59d 100644
20+
--- a/src/util/cubeb_audio_stream.cpp
21+
+++ b/src/util/cubeb_audio_stream.cpp
22+
@@ -261,9 +261,9 @@ std::vector<std::pair<std::string, std::string>> AudioStream::GetCubebDriverName
23+
std::vector<std::pair<std::string, std::string>> names;
24+
names.emplace_back(std::string(), TRANSLATE_STR("AudioStream", "Default"));
25+
26+
- const char** cubeb_names = cubeb_get_backend_names();
27+
- for (u32 i = 0; cubeb_names[i] != nullptr; i++)
28+
- names.emplace_back(cubeb_names[i], cubeb_names[i]);
29+
+ cubeb_backend_names cubeb_names = cubeb_get_backend_names();
30+
+ for (u32 i = 0; i < cubeb_names.count; i++)
31+
+ names.emplace_back(cubeb_names.names[i], cubeb_names.names[i]);
32+
return names;
33+
}
34+
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
From 19e094e5c7aaaf375a13424044521701e85c8313 Mon Sep 17 00:00:00 2001
2+
From: OPNA2608 <[email protected]>
3+
Date: Thu, 9 Jan 2025 17:46:25 +0100
4+
Subject: [PATCH] Fix usage of NEON intrinsics
5+
6+
---
7+
src/common/gsvector_neon.h | 12 ++++++------
8+
1 file changed, 6 insertions(+), 6 deletions(-)
9+
10+
diff --git a/src/common/gsvector_neon.h b/src/common/gsvector_neon.h
11+
index e4991af5e..61b8dc09b 100644
12+
--- a/src/common/gsvector_neon.h
13+
+++ b/src/common/gsvector_neon.h
14+
@@ -867,7 +867,7 @@ public:
15+
16+
ALWAYS_INLINE int mask() const
17+
{
18+
- const uint32x2_t masks = vshr_n_u32(vreinterpret_u32_s32(v2s), 31);
19+
+ const uint32x2_t masks = vshr_n_u32(vreinterpret_u32_f32(v2s), 31);
20+
return (vget_lane_u32(masks, 0) | (vget_lane_u32(masks, 1) << 1));
21+
}
22+
23+
@@ -2882,7 +2882,7 @@ public:
24+
ALWAYS_INLINE GSVector4 gt64(const GSVector4& v) const
25+
{
26+
#ifdef CPU_ARCH_ARM64
27+
- return GSVector4(vreinterpretq_f32_f64(vcgtq_f64(vreinterpretq_f64_f32(v4s), vreinterpretq_f64_f32(v.v4s))));
28+
+ return GSVector4(vreinterpretq_f32_u64(vcgtq_f64(vreinterpretq_f64_f32(v4s), vreinterpretq_f64_f32(v.v4s))));
29+
#else
30+
GSVector4 ret;
31+
ret.U64[0] = (F64[0] > v.F64[0]) ? 0xFFFFFFFFFFFFFFFFULL : 0;
32+
@@ -2894,7 +2894,7 @@ public:
33+
ALWAYS_INLINE GSVector4 eq64(const GSVector4& v) const
34+
{
35+
#ifdef CPU_ARCH_ARM64
36+
- return GSVector4(vreinterpretq_f32_f64(vceqq_f64(vreinterpretq_f64_f32(v4s), vreinterpretq_f64_f32(v.v4s))));
37+
+ return GSVector4(vreinterpretq_f32_u64(vceqq_f64(vreinterpretq_f64_f32(v4s), vreinterpretq_f64_f32(v.v4s))));
38+
#else
39+
GSVector4 ret;
40+
ret.U64[0] = (F64[0] == v.F64[0]) ? 0xFFFFFFFFFFFFFFFFULL : 0;
41+
@@ -2906,7 +2906,7 @@ public:
42+
ALWAYS_INLINE GSVector4 lt64(const GSVector4& v) const
43+
{
44+
#ifdef CPU_ARCH_ARM64
45+
- return GSVector4(vreinterpretq_f32_f64(vcgtq_f64(vreinterpretq_f64_f32(v4s), vreinterpretq_f64_f32(v.v4s))));
46+
+ return GSVector4(vreinterpretq_f32_u64(vcgtq_f64(vreinterpretq_f64_f32(v4s), vreinterpretq_f64_f32(v.v4s))));
47+
#else
48+
GSVector4 ret;
49+
ret.U64[0] = (F64[0] < v.F64[0]) ? 0xFFFFFFFFFFFFFFFFULL : 0;
50+
@@ -2918,7 +2918,7 @@ public:
51+
ALWAYS_INLINE GSVector4 ge64(const GSVector4& v) const
52+
{
53+
#ifdef CPU_ARCH_ARM64
54+
- return GSVector4(vreinterpretq_f32_f64(vcgeq_f64(vreinterpretq_f64_f32(v4s), vreinterpretq_f64_f32(v.v4s))));
55+
+ return GSVector4(vreinterpretq_f32_u64(vcgeq_f64(vreinterpretq_f64_f32(v4s), vreinterpretq_f64_f32(v.v4s))));
56+
#else
57+
GSVector4 ret;
58+
ret.U64[0] = (F64[0] >= v.F64[0]) ? 0xFFFFFFFFFFFFFFFFULL : 0;
59+
@@ -2930,7 +2930,7 @@ public:
60+
ALWAYS_INLINE GSVector4 le64(const GSVector4& v) const
61+
{
62+
#ifdef CPU_ARCH_ARM64
63+
- return GSVector4(vreinterpretq_f32_f64(vcleq_f64(vreinterpretq_f64_f32(v4s), vreinterpretq_f64_f32(v.v4s))));
64+
+ return GSVector4(vreinterpretq_f32_u64(vcleq_f64(vreinterpretq_f64_f32(v4s), vreinterpretq_f64_f32(v.v4s))));
65+
#else
66+
GSVector4 ret;
67+
ret.U64[0] = (F64[0] <= v.F64[0]) ? 0xFFFFFFFFFFFFFFFFULL : 0;
68+
--
69+
2.47.0
70+
Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
{
2+
lib,
3+
llvmPackages,
4+
stdenvNoCC,
5+
fetchFromGitHub,
6+
cmake,
7+
pkg-config,
8+
ninja,
9+
extra-cmake-modules,
10+
wayland-scanner,
11+
makeBinaryWrapper,
12+
qt6,
13+
sdl3,
14+
zstd,
15+
libwebp,
16+
zlib,
17+
libpng,
18+
libjpeg,
19+
freetype,
20+
plutosvg,
21+
cpuinfo,
22+
discord-rpc,
23+
soundtouch,
24+
cubeb,
25+
libzip,
26+
curl,
27+
libX11,
28+
wayland,
29+
shaderc,
30+
spirv-cross,
31+
udev,
32+
libbacktrace,
33+
ffmpeg-headless,
34+
fetchurl,
35+
unzip,
36+
}:
37+
38+
let
39+
passthru = {
40+
updateScript = ./update.sh;
41+
};
42+
43+
meta = {
44+
description = "Fast PlayStation 1 emulator for x86-64/AArch32/AArch64/RV64";
45+
longDescription = ''
46+
# DISCLAIMER
47+
This is an **unofficial** package, do not report any issues to
48+
duckstation developers. Instead, please report them to
49+
<https://github.com/NixOS/nixpkgs> or use the officially
50+
supported platform build at <https://duckstation.org> or other
51+
upstream-approved distribution mechanism not listed here. We
52+
(nixpkgs) do not endorse or condone any action taken on your own
53+
accord in regards to this package.
54+
'';
55+
homepage = "https://duckstation.org/";
56+
license = lib.licenses.cc-by-nc-nd-40;
57+
maintainers = with lib.maintainers; [ normalcea ];
58+
};
59+
60+
pkgSources = lib.importJSON ./sources.json;
61+
62+
linuxDrv = llvmPackages.stdenv.mkDerivation (finalAttrs: {
63+
pname = "duckstation-unofficial";
64+
version = pkgSources.duckstation.version;
65+
66+
src = fetchFromGitHub {
67+
owner = "stenzek";
68+
repo = "duckstation";
69+
tag = "v${finalAttrs.version}";
70+
hash = pkgSources.duckstation.hash_linux;
71+
};
72+
73+
patches = [
74+
# un-vendor cubeb
75+
./0001-remove-cubeb-vendor.patch
76+
# Fix NEON intrinsics usage
77+
./0002-fix-NEON-intrinsics.patch
78+
];
79+
80+
vendorDiscordRPC = discord-rpc.overrideAttrs (oldAttrs: {
81+
pname = "discord-rpc-duckstation";
82+
version = "3.4.0-unstable-${pkgSources.discord_rpc.date}";
83+
src = fetchFromGitHub {
84+
owner = "stenzek";
85+
repo = "discord-rpc";
86+
rev = pkgSources.discord_rpc.rev;
87+
hash = pkgSources.discord_rpc.hash;
88+
};
89+
patches = oldAttrs.patches or [ ];
90+
});
91+
92+
vendorSoundtouch = soundtouch.overrideAttrs (oldAttrs: {
93+
pname = "soundtouch-duckstation";
94+
version = "2.3.3-unstable-${pkgSources.soundtouch.date}";
95+
96+
src = fetchFromGitHub {
97+
owner = "stenzek";
98+
repo = "soundtouch";
99+
rev = pkgSources.soundtouch.rev;
100+
hash = pkgSources.soundtouch.hash;
101+
};
102+
103+
nativeBuildInputs = [ cmake ];
104+
105+
preConfigure = null;
106+
});
107+
108+
vendorShaderc = shaderc.overrideAttrs (oldAttrs: {
109+
pname = "shaderc-duckstation";
110+
version = "2025.2-unstable-${pkgSources.shaderc.date}";
111+
src = fetchFromGitHub {
112+
owner = "stenzek";
113+
repo = "shaderc";
114+
rev = pkgSources.shaderc.rev;
115+
hash = pkgSources.shaderc.hash;
116+
};
117+
118+
patches = (oldAttrs.patches or [ ]);
119+
cmakeFlags = (oldAttrs.cmakeFlags or [ ]) ++ [
120+
(lib.cmakeBool "SHADERC_SKIP_EXAMPLES" true)
121+
(lib.cmakeBool "SHADERC_SKIP_TESTS" true)
122+
];
123+
outputs = [
124+
"out"
125+
"lib"
126+
"dev"
127+
];
128+
postFixup = null;
129+
});
130+
131+
vendorSpirvCross = spirv-cross.overrideAttrs (oldAttrs: {
132+
pname = "spirv-cross-duckstation";
133+
patches = (oldAttrs.patches or [ ]);
134+
cmakeFlags = (oldAttrs.cmakeFlags or [ ]) ++ [
135+
(lib.cmakeBool "SPIRV_CROSS_CLI" false)
136+
(lib.cmakeBool "SPIRV_CROSS_ENABLE_CPP" false)
137+
(lib.cmakeBool "SPIRV_CROSS_ENABLE_C_API" true)
138+
(lib.cmakeBool "SPIRV_CROSS_ENABLE_GLSL" true)
139+
(lib.cmakeBool "SPIRV_CROSS_ENABLE_HLSL" false)
140+
(lib.cmakeBool "SPIRV_CROSS_ENABLE_MSL" false)
141+
(lib.cmakeBool "SPIRV_CROSS_ENABLE_REFLECT" false)
142+
(lib.cmakeBool "SPIRV_CROSS_ENABLE_TESTS" false)
143+
(lib.cmakeBool "SPIRV_CROSS_ENABLE_UTIL" true)
144+
(lib.cmakeBool "SPIRV_CROSS_SHARED" true)
145+
(lib.cmakeBool "SPIRV_CROSS_STATIC" false)
146+
];
147+
});
148+
149+
nativeBuildInputs = [
150+
cmake
151+
pkg-config
152+
ninja
153+
extra-cmake-modules
154+
wayland-scanner
155+
makeBinaryWrapper
156+
qt6.wrapQtAppsHook
157+
qt6.qttools
158+
];
159+
160+
buildInputs = [
161+
sdl3
162+
zstd
163+
libwebp
164+
zlib
165+
libpng
166+
libjpeg
167+
freetype
168+
plutosvg
169+
cubeb
170+
cpuinfo
171+
libzip
172+
curl
173+
libX11
174+
wayland
175+
qt6.qtbase
176+
udev
177+
libbacktrace
178+
ffmpeg-headless
179+
]
180+
++ [
181+
finalAttrs.vendorDiscordRPC
182+
finalAttrs.vendorShaderc
183+
finalAttrs.vendorSoundtouch
184+
finalAttrs.vendorSpirvCross
185+
];
186+
187+
cmakeFlags = [
188+
(lib.cmakeBool "ALLOW_INSTALL" true)
189+
(lib.cmakeFeature "CMAKE_INSTALL_PREFIX" "${placeholder "out"}/lib/duckstation")
190+
];
191+
192+
qtWrapperArgs = [
193+
"--prefix LD_LIBRARY_PATH : ${(lib.makeLibraryPath [ ffmpeg-headless ])}"
194+
];
195+
196+
postInstall = ''
197+
makeWrapper $out/lib/duckstation/duckstation-qt $out/bin/duckstation-qt
198+
199+
mkdir -p $out/share/applications/
200+
ln -s $out/lib/duckstation/resources/org.duckstation.DuckStation.desktop \
201+
$out/share/applications/
202+
203+
mkdir -p $out/share/icons/hicolor/scalable/apps/
204+
ln -s $out/lib/duckstation/resources/org.duckstation.DuckStation.png \
205+
$out/share/icons/hicolor/scalable/apps/
206+
207+
pushd ..
208+
install -Dm644 LICENSE -t $out/share/doc/duckstation
209+
install -Dm644 README.* -t $out/share/doc/duckstation
210+
install -Dm644 CONTRIBUTORS.md -t $out/share/doc/duckstation
211+
popd
212+
'';
213+
214+
inherit passthru;
215+
216+
meta = {
217+
inherit (meta)
218+
description
219+
longDescription
220+
homepage
221+
license
222+
maintainers
223+
;
224+
mainProgram = "duckstation-qt";
225+
platforms = lib.platforms.linux;
226+
};
227+
});
228+
229+
darwinDrv = stdenvNoCC.mkDerivation (finalAttrs: {
230+
pname = "duckstation";
231+
version = pkgSources.duckstation.version;
232+
233+
src = fetchurl {
234+
url = "https://github.com/stenzek/duckstation/releases/download/v${finalAttrs.version}/duckstation-mac-release.zip";
235+
hash = pkgSources.duckstation.hash_darwin;
236+
};
237+
238+
nativeBuildInputs = [ unzip ];
239+
240+
dontPatch = true;
241+
dontConfigure = true;
242+
dontBuild = true;
243+
244+
sourceRoot = ".";
245+
246+
installPhase = ''
247+
runHook preInstall
248+
249+
mkdir -p $out/Applications
250+
cp -r DuckStation.app $out/Applications/DuckStation.app
251+
252+
runHook postInstall
253+
'';
254+
255+
inherit passthru;
256+
257+
meta = {
258+
inherit (meta)
259+
description
260+
longDescription
261+
homepage
262+
license
263+
maintainers
264+
;
265+
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
266+
platforms = lib.platforms.darwin;
267+
};
268+
});
269+
in
270+
if stdenvNoCC.hostPlatform.isLinux then
271+
linuxDrv
272+
else if stdenvNoCC.hostPlatform.isDarwin then
273+
darwinDrv
274+
else
275+
throw "No supported build."

0 commit comments

Comments
 (0)