Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package Request: CEMU #188187

Closed
Krutonium opened this issue Aug 24, 2022 · 45 comments
Closed

Package Request: CEMU #188187

Krutonium opened this issue Aug 24, 2022 · 45 comments

Comments

@Krutonium
Copy link
Contributor

Project description
A WiiU emulator for Windows and now Linux

Metadata

@cid-chan
Copy link
Contributor

Note:
nixpkgs#cemu points to https://github.com/ce-programming/cemu which is not the project requested here.

@SuperSamus
Copy link
Contributor

I wonder how it should be named. cemu-emulator, while correct (and the title on the Google Search result), is also correct for the other. cemu-wiiu... meh.
On the AUR, nixpkgs#cemu is named ticemu, while the Wii U emulator is cemu. Renaming them around however is something that can't exactly be done lightly.

@Krutonium
Copy link
Contributor Author

Dolphin, the Wii emulator is called dolphin-emu, so perhaps cemu-emu. (Dolphin also being a file manager)

@leiserfg
Copy link
Contributor

I tried to do it, but I faced several issues and my nix/cmake skills were not advanced enough. If someone has the required skills, this is what I have till now:
https://github.com/leiserfg/leiserfg-overlay/tree/master/pkgs/cemu-wip

@winterqt
Copy link
Member

What issues were you running into exactly, @leiserfg? (I'd attempt to build the package myself, but if you have logs on hand it would be easier.)

@leiserfg
Copy link
Contributor

It's failing while building Zarchive:

Target "zarchive" links to:

    zstd::libzstd_static

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.



-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    BUILD_TESTING
    CMAKE_EXPORT_NO_PACKAGE_REGISTRY
    CMAKE_POLICY_DEFAULT_CMP0025
    ```
seems like something around here https://github.com/Exzap/ZArchive/blob/48914a07df3c213333c580bb5e5bb3393442ca5b/cmake/Findzstd.cmake#L10-L14  but I don't know how to make it work.

@leiserfg
Copy link
Contributor

Probably there are more broken things but that is blocking me.

@leiserfg
Copy link
Contributor

@winterqt I managed to fix the issue in archive, but now I'm having to problems with wxwidgets in cmake 😢, I'm hating all the CMake black magic.

@winterqt
Copy link
Member

@leiserfg Can you push the ZArchive fixes so I can take a look at it where you left off?

@leiserfg
Copy link
Contributor

I fixed more stuff, now I'm in a point where I can't do more, has a weird compilation error.

@leiserfg
Copy link
Contributor

I had to change the compiler to Clang because the code has a clang-ism (uses a function defined by clangc)

@winterqt
Copy link
Member

Looking at the issue for Linux builds, it looks like things are very rocky right now and everyone is having issues. If you can't get it working, maybe it would be best to just wait. (I'd take a stab at it if I didn't have to try to rip out vcpkg -- maybe your patch isn't enough?)

@misuzu
Copy link
Contributor

misuzu commented Aug 30, 2022

Looks like vcpkg is not required anymore: cemu-project/Cemu#75

@leiserfg
Copy link
Contributor

leiserfg commented Sep 3, 2022

I tried after the cemu upstream changes and now I can't get it to compile because it tries to find imgui with cmake or pkg-config but none of them work. In arch they add imgui-config.cmake and that makes it work, should we do something like that?

Linking @WolfangAukang as imgui maintainer, maybe he can share some light.

@WolfangAukang
Copy link
Contributor

@leiserfg AFAIU:

  • Regarding the IMGUI_*_BINDING conditions, it might be looking for these files here and. In the imgui configuration, you would be able to find them at $out/include/imgui/backends.
  • Regarding the IMGUI_FREETYPE, it might be looking for the ones at $out/include/imgui/misc/freetype.

Not sure what else to provide.

@0x715C
Copy link

0x715C commented Sep 4, 2022

I tried overriding imgui,
(imgui.overrideAttrs(old: rec {
      cmakeSrc = fetchurl {
        url = "https://raw.githubusercontent.com/microsoft/vcpkg/master/ports/imgui/CMakeLists.txt";
        sha256 = "sha256-Ji+u1QcUnImqt1cv0sKpaPhDyikABD4wqcM5c17Qio8=";
        };
      imguiConfigSrc = fetchurl {
        url = "https://raw.githubusercontent.com/microsoft/vcpkg/master/ports/imgui/imgui-config.cmake.in";
        sha256 = "sha256-kVKPYMypPTvOBC0qwWpjFpAl7CWjRFO0mAMSbtGRU64=";
        };
      prePatch = old.installPhase + ''
        cp "${cmakeSrc}" CMakeLists.txt
        cp "${imguiConfigSrc}" imgui-config.cmake.in
      '';
      installPhase = ''
      '';
      buildInputs = [cmake];
      dontBuild = false;
      }))
It stopped whining about imgui, but now it tries to find glslang.

CMake Error at CMakeLists.txt:83 (find_package):
By not providing "Findglslang.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "glslang", but
CMake did not find one.

Could not find a package configuration file provided by "glslang" with any
of the following names:

glslangConfig.cmake
glslang-config.cmake

Add the installation prefix of "glslang" to CMAKE_PREFIX_PATH or set
"glslang_DIR" to a directory containing one of the above files. If
"glslang" provides a separate development package or SDK, be sure it has
been installed.

@leiserfg
Copy link
Contributor

leiserfg commented Sep 4, 2022

but now it tries to find glslang

Try with this one https://github.com/microsoft/vcpkg/blob/master/ports/glslang/glslang-config.cmake
So many libs without *-config.cmake or *.pc 😢

@yboettcher
Copy link
Contributor

Hey all, I managed to create a working flake for this which should work standalone: https://github.com/zaethan/CemuFlake
However, when trying to run the result, Cemu complains that it cannot write into its own directory, so one has to copy the result/bin folder somewhere else and add writing permissions. But this seems to be just how Cemu works and either needs to be changed on their side (using standard .config/.local directories) or which needs to be patched to use another (writable) directory.
For now however, copying the result somewhere else lets me start cemu and even load into a game, although I probably hit cemu-project/Cemu#217 right in the opening cutscene.

@misuzu
Copy link
Contributor

misuzu commented Sep 11, 2022

@zaethan you could try using libredirect in a wrapper as workaround.

@leiserfg
Copy link
Contributor

leiserfg commented Sep 11, 2022

@misuzu, @zaethan it checks for the "writability" of the path where the executable is running, which is done by calling boost::dll::program_location().generic_wstring();
that one gets it from /proc/self/exe

@leiserfg
Copy link
Contributor

I think the only way to make it work (till it's fixed upstream) is to make a wrapper that copies the executable and executes the copy.

@yboettcher
Copy link
Contributor

So the libredirect gave me a build that starts up without copying stuff around. The question then becomes where to redirect to. For testing I just used some temporary scratch storage I have, but that's not an option.

postFixup = ''
  wrapProgram $out/bin/Cemu_release \
    --set LD_PRELOAD "${pkgs.libredirect}/lib/libredirect.so" \
    --set NIX_REDIRECTS ${builtins.concatStringsSep ":" [ "$out/bin=/mnt/RamDisk" ]}
'';

I'll experiment a bit more with this tomorrow. But I guess I can't just put ${HOME}/... or some xdg variable there directly.

One would also have to make sure the directory exists since I dont think cemu tries to create it. For that, it should be possible to wrap cemu in a script (maybe makeWrapper? Never used that before) that just calls mkdir -p if the path does not exist, but at this point I'm just guessing.
If we put this in a script though, we could also use that script to populate NIX_REDIRECTS with $HOME/.config/cemu-emulator or something like this (xdg?).

@leiserfg
Copy link
Contributor

leiserfg commented Sep 12, 2022

@zaethan /dev/shm/ is always available, but yes if the files are supposed to be available across runs or will take a lot of space is better to use a xdg folder,
Can you test if this works?, I'm not sure if libredirect resolves ~.

postFixup = ''
 wrapProgram $out/bin/Cemu_release \
   --set LD_PRELOAD "${pkgs.libredirect}/lib/libredirect.so" \
   --set NIX_REDIRECTS ${builtins.concatStringsSep ":" [ "$out/bin=~/.config/cemu" ]} \
   --run "mkdir -p ~/.config/cemu"
'';

@yboettcher
Copy link
Contributor

yboettcher commented Sep 12, 2022

@leiserfg I think this data needs to persist. The very first thing Cemu does on startup is ask where to save stuff/look for games.
Also apparently cemu creates the directory if it does not exist, so there is no need for the --run part.
Sadly, wrapProgram puts the variables into single quotes which prevents expansion of the variables (or ~ for that matter). Apparently, ~ doesn't even get expanded in zsh when put into double quotes. Feel free to correct me on this quoting stuff though, not an expert on this.
What works however is putting the NIX_REDIRECTS variable in double quotes and using ${HOME}. For that just ran a sed command on the resulting wrapped script to replace single with double quotes on that line. I tried using some grep to get the line number programmatically, but the variable substitution didn't work how I wanted it to, so I just hardcoded line 3 for now.

wrapProgram $out/bin/Cemu_release \
  --set LD_PRELOAD "${pkgs.libredirect}/lib/libredirect.so" \
  --set NIX_REDIRECTS $out=$\{HOME}/.config/cemu

# LINE=$(cat $out/bin/Cemu_release -n | grep NIX_REDIRECTS | grep -oP "^\s+\d" | tr -d '[:space:]')

sed -i "3s/\x27/\x22/g" $out/bin/Cemu_release

This gives me a cemu which starts up, creates ${HOME}/.config/cemu and lets me configure it and load a game. But... apparently it forgets the configuration on every run. Every time I start it, I have to tell it again, where it shall save/load stuff.

@yboettcher
Copy link
Contributor

Just found this PR to make cemu use XDG directories: cemu-project/Cemu#130
If that gets merged, we wouldn't need to do anything special.

@leiserfg
Copy link
Contributor

leiserfg commented Sep 12, 2022

This also works without hardcoding the line number

--set NIX_REDIRECTS $out=
 ...
 sed -e 's|.*NIX_REDIRECTS.*|\0$HOME/.config/cemu|' -i $out/bin/Cemu_release

@0x715C
Copy link

0x715C commented Sep 12, 2022

Just found this PR to make cemu use XDG directories: cemu-project/Cemu#130 If that gets merged, we wouldn't need to do anything special.

Seems to work.
You need to edit $XDG_CONFIG_HOME/cemu/settings.xml,
In <Graphic> change <api>1</api> to <api>0</api>

Sound appears non-functional?

@leiserfg
Copy link
Contributor

@0x715C maybe because of this ?
https://github.com/mozilla/cubeb/blob/master/CMakeLists.txt#L163-L172
So adding pulse to the build inputs of it "should" fix it.

@0x715C
Copy link

0x715C commented Sep 13, 2022

@leiserfg yea, that fixed it. Also had to wrap the executable to add pulseaudio to the library path.

@yboettcher
Copy link
Contributor

It also looks like Vulkan is not functional either. I only have an OpenGL option. IIrc Cemu bundles it's own Vulkan headers as submodule and probably cannot find them during build time.

@yboettcher
Copy link
Contributor

So adding pulse to the build inputs of it "should" fix it.

@leiserfg yea, that fixed it. Also had to wrap the executable to add pulseaudio to the library path.

Yup, works for me too. One also has to remember to select cubeb as output and set the TV output to one the devices. I thought it didn't work at first.

@leiserfg
Copy link
Contributor

@zaethan maybe the vulkan issue is because it needs to have access to vulkan-loader? like:

 "--prefix LD_LIBRARY_PATH : ${vulkan-loader}/lib"

@SuperSamus
Copy link
Contributor

DuckStation's package does this too:

qtWrapperArgs = [
  "--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ libpulseaudio vulkan-loader ]}"
];

@yboettcher
Copy link
Contributor

This gives me the option to select Vulkan, but it segfaults if I do so.

yboettcher added a commit to yboettcher/CemuFlake that referenced this issue Sep 13, 2022
@yboettcher
Copy link
Contributor

Yeah, they rely on their submodule here.
So we either gotta patch this line to do something like find_package+target_link_library or so, or we gotta populate the "dependencies/Vulkan-headers" directory (copying the vulkan-headers from nixpkgs in a postPatch)

@leiserfg
Copy link
Contributor

I'm not sure that's the issue, unless the copy of vulkan-headers they have is somehow patched. If it is were cmake is not finding vulkan it will not try to load it at runtime, isn't it?

@yboettcher
Copy link
Contributor

So I tried adding the files in the dependencies/Vulkan-Headers directory and I tried applying this patch

postPatch = ''
  sed -i 's:include_directories(\"dependencies/Vulkan-Headers/include\"):find_package(Vulkan REQUIRED):g' CMakeLists.txt
'';

inspired by this pr.
Also, their submodule just points to some commit of the KhronosGroup's Vulkan-Headers, so I don't think they patched anything.
Both attempts compiled, but segfaulted as soon as I tried to select Vulkan.

@yboettcher
Copy link
Contributor

Vulkan works now (for me atleast) :)
I don't know why they are related, but I noticed some references to wxwidgets or gtk in some of the segfault traces. So I changed it to now use gtk3 and added the wrapGAppsHook.

@misuzu
Copy link
Contributor

misuzu commented Sep 24, 2022

Had to tweak your flake a bit to get it working on my system with dwm, sound works too!

diff --git a/flake.nix b/flake.nix
index 401d2ee..915e7f4 100644
--- a/flake.nix
+++ b/flake.nix
@@ -64,7 +64,7 @@

             nativeBuildInputs = with pkgs; [ cmake ];

-            buildInputs = with pkgs; [ libpulseaudio ];
+            buildInputs = with pkgs; [ libpulseaudio alsa-lib libjack2 pipewire ];

             # for now
             # googletest is a submodule which is broken with flakes
@@ -166,6 +166,7 @@
             ];

             buildInputs = with pkgs; [
+              libpulseaudio alsa-lib libjack2 pipewire
               SDL2
               pugixml
               imgui
@@ -204,12 +205,11 @@
             postInstall = ''
               mkdir -p $out/bin
               cp ../bin/Cemu_release $out/bin/
-            '';
-
-            postFixup = ''
               wrapProgram $out/bin/Cemu_release \
-                --prefix LD_LIBRARY_PATH : ${pkgs.lib.makeLibraryPath [ pkgs.libpulseaudio pkgs.vulkan-loader ]}
+                --prefix LD_LIBRARY_PATH : ${with pkgs; lib.makeLibraryPath [ libpulseaudio alsa-lib libjack2 pipewire vulkan-loader ]}
             '';
+
+              meta.mainProgram = "Cemu_release";
           };

           defaultPackage = self.packages.${system}.cemu;

@leiserfg
Copy link
Contributor

leiserfg commented Sep 24, 2022

@misuzu I don't think you need all the audio backends, alsa and pulse (both) work with a pipewire server or a pulse server, so you just need pulse or alsa, in the case of alsa you will probably need also alsa-plugins

@yboettcher
Copy link
Contributor

I guess ideally (if/when this gets integrated into nixpkgs), the audio backends would depend on what backends are enabled in the config or be configurable through options.
In the meantime, I think having maximum compatibility in the flake would be best. Or can flakes have options?

@leiserfg
Copy link
Contributor

@zaethan the other emulators already packaged use only one audio backend, in any case using alsa is enough as it will work with raw alsa, pulseaudio or pipewire.

@leiserfg
Copy link
Contributor

Guys, seems like the latest release of cemu includes the xdg path fix.

@zhaofengli
Copy link
Member

Hi all, I totally missed this issue and started my own attempt at packaging Cemu this afternoon. I even asked on Matrix and searched on Discourse, but somehow still missed this one in my search. My apologies.

I opened #198590 which seems to work well for me. None of the invasive patches are required, and apart from fmt which requires a bump all dependencies from nixpkgs seem to work flawlessly.

@SuperSamus
Copy link
Contributor

This can be closed now.

@aanderse aanderse closed this as completed Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests