Skip to content

Commit a476cb1

Browse files
committed
torzu: init at unstable 12.15.24
1 parent 9c4c97a commit a476cb1

File tree

4 files changed

+340
-0
lines changed

4 files changed

+340
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
diff --git a/src/core/debugger/debugger.cpp b/src/core/debugger/debugger.cpp
2+
index e86aae8460..a4dca23770 100644
3+
--- a/src/core/debugger/debugger.cpp
4+
+++ b/src/core/debugger/debugger.cpp
5+
@@ -5,7 +5,13 @@
6+
#include <mutex>
7+
#include <thread>
8+
9+
-#include <boost/asio.hpp>
10+
+// Use basic asio functionality only
11+
+#define BOOST_ASIO_STANDALONE
12+
+#include <boost/asio/basic_io_object.hpp>
13+
+#include <boost/asio/ip/tcp.hpp>
14+
+#include <boost/asio/write.hpp>
15+
+#include <boost/asio/read.hpp>
16+
+
17+
#include <boost/process/async_pipe.hpp>
18+
19+
#include "common/logging/log.h"
20+
@@ -21,17 +27,22 @@
21+
22+
template <typename Readable, typename Buffer, typename Callback>
23+
static void AsyncReceiveInto(Readable& r, Buffer& buffer, Callback&& c) {
24+
- static_assert(std::is_trivial_v<Buffer>);
25+
- auto boost_buffer{boost::asio::buffer(&buffer, sizeof(Buffer))};
26+
- r.async_read_some(
27+
- boost_buffer, [&, c](const boost::system::error_code& error, size_t bytes_read) {
28+
- if (!error.failed()) {
29+
- const u8* buffer_start = reinterpret_cast<const u8*>(&buffer);
30+
- std::span<const u8> received_data{buffer_start, buffer_start + bytes_read};
31+
- c(received_data);
32+
- AsyncReceiveInto(r, buffer, c);
33+
- }
34+
- });
35+
+ try {
36+
+ static_assert(std::is_trivial_v<Buffer>);
37+
+ auto boost_buffer{boost::asio::buffer(&buffer, sizeof(Buffer))};
38+
+ r.async_read_some(
39+
+ boost_buffer,
40+
+ [&, c](const boost::system::error_code& error, size_t bytes_read) {
41+
+ if (!error) {
42+
+ const u8* buffer_start = reinterpret_cast<const u8*>(&buffer);
43+
+ std::span<const u8> received_data{buffer_start, buffer_start + bytes_read};
44+
+ c(received_data);
45+
+ AsyncReceiveInto(r, buffer, c);
46+
+ }
47+
+ });
48+
+ } catch (const std::exception& e) {
49+
+ LOG_ERROR(Debug_GDBStub, "AsyncReceiveInto error: {}", e.what());
50+
+ }
51+
}
52+
53+
template <typename Callback>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
diff --git a/src/input_common/drivers/udp_client.cpp b/src/input_common/drivers/udp_client.cpp
2+
index 60821b31a6..8f9c047218 100644
3+
--- a/src/input_common/drivers/udp_client.cpp
4+
+++ b/src/input_common/drivers/udp_client.cpp
5+
@@ -2,7 +2,15 @@
6+
// SPDX-License-Identifier: GPL-2.0-or-later
7+
8+
#include <random>
9+
-#include <boost/asio.hpp>
10+
+// Include only needed asio components
11+
+#include <boost/asio/io_context.hpp>
12+
+#include <boost/asio/ip/udp.hpp>
13+
+#include <boost/asio/basic_waitable_timer.hpp>
14+
+#include <boost/asio/write.hpp>
15+
+#include <boost/asio/buffer.hpp>
16+
+#include <boost/asio/basic_socket.hpp>
17+
+#include <boost/asio/ip/address.hpp>
18+
+#include <boost/asio/ip/address_v4.hpp>
19+
#include <fmt/format.h>
20+
21+
#include "common/logging/log.h"
22+
@@ -113,7 +121,7 @@ private:
23+
}
24+
25+
SocketCallback callback;
26+
- boost::asio::io_service io_service;
27+
+ boost::asio::io_context io_service;
28+
boost::asio::basic_waitable_timer<clock> timer;
29+
udp::socket socket;
30+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/src/input_common/helpers/udp_protocol.h b/src/input_common/helpers/udp_protocol.h
2+
index db08fc62c5..ea223ea937 100644
3+
--- a/src/input_common/helpers/udp_protocol.h
4+
+++ b/src/input_common/helpers/udp_protocol.h
5+
@@ -69,7 +69,7 @@ Message<T> CreateMessage(const u32 magic, const T data, const u32 sender_id) {
6+
};
7+
Message<T> message{header, data};
8+
crc.process_bytes(&message, sizeof(Message<T>));
9+
- message.header.crc = crc.checksum();
10+
+ message.header.crc = static_cast<u32_le>(crc.checksum());
11+
return message;
12+
}
13+

pkgs/by-name/to/torzu/package.nix

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
{
2+
lib,
3+
stdenv,
4+
SDL2,
5+
autoconf,
6+
boost,
7+
catch2_3,
8+
cmake,
9+
fetchFromGitHub,
10+
cpp-jwt,
11+
cubeb,
12+
discord-rpc,
13+
enet,
14+
fetchgit,
15+
fetchurl,
16+
ffmpeg-headless,
17+
fmt,
18+
glslang,
19+
libopus,
20+
libusb1,
21+
libva,
22+
lz4,
23+
python3,
24+
unzip,
25+
nix-update-script,
26+
nlohmann_json,
27+
nv-codec-headers-12,
28+
pkg-config,
29+
qt6,
30+
vulkan-headers,
31+
vulkan-loader,
32+
yasm,
33+
simpleini,
34+
zlib,
35+
vulkan-memory-allocator,
36+
zstd,
37+
}:
38+
39+
let
40+
inherit (qt6)
41+
qtbase
42+
qtmultimedia
43+
qtwayland
44+
wrapQtAppsHook
45+
qttools
46+
qtwebengine
47+
;
48+
49+
compat-list = stdenv.mkDerivation {
50+
pname = "yuzu-compatibility-list";
51+
version = "unstable-2024-02-26";
52+
53+
src = fetchFromGitHub {
54+
owner = "flathub";
55+
repo = "org.yuzu_emu.yuzu";
56+
rev = "9c2032a3c7e64772a8112b77ed8b660242172068";
57+
hash = "sha256-ITh/W4vfC9w9t+TJnPeTZwWifnhTNKX54JSSdpgaoBk=";
58+
};
59+
60+
buildCommand = ''
61+
cp $src/compatibility_list.json $out
62+
'';
63+
};
64+
65+
nx_tzdb = stdenv.mkDerivation rec {
66+
pname = "nx_tzdb";
67+
version = "221202";
68+
69+
src = fetchurl {
70+
url = "https://github.com/lat9nq/tzdb_to_nx/releases/download/${version}/${version}.zip";
71+
hash = "sha256-mRzW+iIwrU1zsxHmf+0RArU8BShAoEMvCz+McXFFK3c=";
72+
};
73+
74+
nativeBuildInputs = [ unzip ];
75+
76+
buildCommand = ''
77+
unzip $src -d $out
78+
'';
79+
80+
};
81+
82+
in
83+
84+
stdenv.mkDerivation (finalAttrs: {
85+
pname = "torzu";
86+
version = "unstable-2024-12-15";
87+
88+
src = fetchgit {
89+
url = "https://notabug.org/litucks/torzu";
90+
rev = "02cfee3f184e6fdcc3b483ef399fb5d2bb1e8ec7";
91+
hash = "sha256-hAWMFzTNJGFcrXov5LKMdW9YWhsu7wueATmiuS7EVkI=";
92+
fetchSubmodules = true;
93+
};
94+
95+
patches = [
96+
# Remove coroutines from debugger to fix boost::asio compatibility issues
97+
./fix-debugger.patch
98+
# Add explicit cast for CRC checksum value
99+
./fix-udp-protocol.patch
100+
# Use specific boost::asio includes and update to modern io_context
101+
./fix-udp-client.patch
102+
];
103+
104+
nativeBuildInputs = [
105+
cmake
106+
glslang
107+
pkg-config
108+
python3
109+
qttools
110+
wrapQtAppsHook
111+
];
112+
113+
buildInputs = [
114+
# vulkan-headers must come first, so the older propagated versions
115+
# don't get picked up by accident
116+
vulkan-headers
117+
118+
boost
119+
catch2_3
120+
cpp-jwt
121+
cubeb
122+
discord-rpc
123+
# intentionally omitted: dynarmic - prefer vendored version for compatibility
124+
enet
125+
126+
# ffmpeg deps (also includes vendored)
127+
# we do not use internal ffmpeg because cuda errors
128+
autoconf
129+
yasm
130+
libva # for accelerated video decode on non-nvidia
131+
nv-codec-headers-12 # for accelerated video decode on nvidia
132+
ffmpeg-headless
133+
# end ffmpeg deps
134+
135+
fmt
136+
# intentionally omitted: gamemode - loaded dynamically at runtime
137+
# intentionally omitted: httplib - upstream requires an older version than what we have
138+
libopus
139+
libusb1
140+
# intentionally omitted: LLVM - heavy, only used for stack traces in the debugger
141+
lz4
142+
nlohmann_json
143+
qtbase
144+
qtmultimedia
145+
qtwayland
146+
qtwebengine
147+
# intentionally omitted: renderdoc - heavy, developer only
148+
SDL2
149+
# intentionally omitted: stb - header only libraries, vendor uses git snapshot
150+
vulkan-memory-allocator
151+
# intentionally omitted: xbyak - prefer vendored version for compatibility
152+
zlib
153+
zstd
154+
];
155+
156+
# This changes `ir/opt` to `ir/var/empty` in `externals/dynarmic/src/dynarmic/CMakeLists.txt`
157+
# making the build fail, as that path does not exist
158+
dontFixCmake = true;
159+
160+
cmakeFlags = [
161+
# actually has a noticeable performance impact
162+
(lib.cmakeBool "YUZU_ENABLE_LTO" true)
163+
(lib.cmakeBool "YUZU_TESTS" false)
164+
165+
(lib.cmakeBool "ENABLE_QT6" true)
166+
(lib.cmakeBool "ENABLE_QT_TRANSLATION" true)
167+
168+
# use system libraries
169+
# NB: "external" here means "from the externals/ directory in the source",
170+
# so "off" means "use system"
171+
(lib.cmakeBool "YUZU_USE_EXTERNAL_SDL2" false)
172+
(lib.cmakeBool "YUZU_USE_EXTERNAL_VULKAN_HEADERS" true)
173+
"-DVulkan_INCLUDE_DIRS=${vulkan-headers}/include"
174+
175+
# # don't use system ffmpeg, suyu uses internal APIs
176+
# (lib.cmakeBool "YUZU_USE_BUNDLED_FFMPEG" true)
177+
178+
# don't check for missing submodules
179+
(lib.cmakeBool "YUZU_CHECK_SUBMODULES" false)
180+
181+
# enable some optional features
182+
(lib.cmakeBool "YUZU_USE_QT_WEB_ENGINE" true)
183+
(lib.cmakeBool "YUZU_USE_QT_MULTIMEDIA" true)
184+
(lib.cmakeBool "USE_DISCORD_PRESENCE" true)
185+
186+
# We dont want to bother upstream with potentially outdated compat reports
187+
(lib.cmakeBool "YUZU_ENABLE_COMPATIBILITY_REPORTING" false)
188+
(lib.cmakeBool "ENABLE_COMPATIBILITY_LIST_DOWNLOAD" false) # We provide this deterministically
189+
];
190+
191+
env = {
192+
# Does some handrolled SIMD
193+
NIX_CFLAGS_COMPILE = lib.optionalString stdenv.hostPlatform.isx86_64 "-msse4.1";
194+
};
195+
196+
qtWrapperArgs = [
197+
# Fixes vulkan detection.
198+
# FIXME: patchelf --add-rpath corrupts the binary for some reason, investigate
199+
"--prefix LD_LIBRARY_PATH : ${vulkan-loader}/lib"
200+
];
201+
202+
# Setting this through cmakeFlags does not work.
203+
# https://github.com/NixOS/nixpkgs/issues/114044
204+
preConfigure = lib.concatStringsSep "\n" [
205+
''
206+
cmakeFlagsArray+=(
207+
"-DTITLE_BAR_FORMAT_IDLE=${finalAttrs.pname} | ${finalAttrs.version} (nixpkgs) {}"
208+
"-DTITLE_BAR_FORMAT_RUNNING=${finalAttrs.pname} | ${finalAttrs.version} (nixpkgs) | {}"
209+
)
210+
''
211+
# provide pre-downloaded tz data
212+
''
213+
mkdir -p build/externals/nx_tzdb
214+
ln -s ${nx_tzdb} build/externals/nx_tzdb/nx_tzdb
215+
''
216+
];
217+
218+
postConfigure = ''
219+
ln -sf ${compat-list} ./dist/compatibility_list/compatibility_list.json
220+
'';
221+
222+
postInstall = "
223+
install -Dm444 $src/dist/72-yuzu-input.rules $out/lib/udev/rules.d/72-yuzu-input.rules
224+
";
225+
226+
meta = {
227+
description = "Fork of yuzu, an open-source Nintendo Switch emulator";
228+
homepage = "https://notabug.org/litucks/torzu";
229+
mainProgram = "yuzu";
230+
platforms = lib.platforms.linux;
231+
badPlatforms = [
232+
# Several conversion errors, probably caused by the update to GCC 14
233+
"aarch64-linux"
234+
];
235+
maintainers = with lib.maintainers; [ liberodark ];
236+
license = with lib.licenses; [
237+
gpl3Plus
238+
# Icons
239+
asl20
240+
mit
241+
cc0
242+
];
243+
};
244+
})

0 commit comments

Comments
 (0)