Skip to content

Compilation & Development

VocalFan edited this page Apr 15, 2024 · 4 revisions

Compilation & Development
A list about how to compile Obliteration, and what you will need to begin developing!

Building from source

Windows prerequisites

Linux prerequisites

  • GCC 9.4+
  • Rust on the latest stable channel
  • CMake 3.21+

macOS prerequisites

  • macOS 12+
  • Homebrew
  • Clang 13+
  • Rust on the latest stable channel
  • CMake 3.21+

Install Qt 6

You need to install Qt 6 on your system before you proceed. The minimum version is 6.5. You also need to enable SVG support when installing.

Windows-specific requirements

You need Qt Online Installer for open-source to install Qt, downloaded from https://www.qt.io. The installer will ask you to sign in with a Qt account, which you can create for free. You need to check Custom installation and do not check Qt for desktop development that is using the MinGW toolchain. Make sure you have checked the MSVC 2019 64-bit component in the Select Components page for the version you wish to install and uncheck all of the other components.

Once installation is completed you need to set the CMAKE_PREFIX_PATH environment variable to the full path of the installed version (e.g. C:\Qt\6.5.1\msvc2019_64). To set an environment variable:

  1. Open a run dialog with Win + R.
  2. Enter sysdm.cpl then click OK.
  3. Go to the Advanced tab then click on Environment Variables....
  4. Click New... to create a new environment variable. Just create for either User variables or System variables, not both.
  5. Restart your terminal or IDE to load the new PATH.

Install Qt with Homebrew (macOS only)

brew install qt@6

Configure build system

cmake --preset PRESET .

The value of PRESET will depend on your platform and the build configuration you want to use. The current available presets are:

  • windows-release
  • windows-debug
  • linux-release
  • linux-debug
  • mac-release
  • mac-debug

If all you want is to use the emulator, choose [YOUR-PLATFORM]-release for optimized outputs. But if you want to edit the code, choose *-debug.

Build

cmake --build --preset PRESET

You can use -j to enable parallel building (e.g. cmake --build --preset PRESET -j 2). Each parallel build on Linux consumes a lot of memory so don't use the number of your CPU cores otherwise your system might crash due to out of memory. On Windows and macOS it seems like it is safe to use the number of your CPU cores.

Development

Recommended Code Editor

Before proceeding, make sure the build preset you are using is *-debug. We recommend Visual Studio Code as a code editor with the following extensions:

Then open this folder with VS Code. It will ask which CMake preset to use and you need to choose the same one that you were using when building. Everything should work out of the box (e.g. code completion, debugging, etc).

macOS debugging issues

If you can't launch or debug Obliteration from VS Code, try this solution.

Get a homebrew application for testing

If you don't have a PS4 application for testing you can download PS Scene Quiz for free here.

Rules for Rust sources

  • Use unsafe code only when you know what you are doing. When you do try to wrap it in a safe function so other people who are not familiar with unsafe code can have a safe life.
  • Don't chain method calls without an intermediate variable if the result code is hard to follow. We encourage code readability as a pleasure when writing so try to make it easy to read and understand for other people.
  • Do not blindly cast an integer. Make sure the value can fit in a destination type. We don't have any plans to support non-64-bit systems so the pointer size and its related types like usize are always 64-bits.
  • Beware of deadlock and memory leak. Rust can protect us from most mistakes, except those two. Deadlock can be happen easily in Rust because Rust requires us to wrap the data we want to protect with a mutex and get a mutable reference through it. The problem with this is it become natural for you to lock the mutex to operate on the inner data, which can easily cause a deadlock if you are not aware when there are another locks being active. The only cases for memory leak you need to aware is when working with Arc. Just make sure you don't create a reference cycle that will never be dropped.

Rules for C++ sources

Just follow how Qt is written (e.g. coding style, etc.). Always prefers Qt classes over std when possible so you don't need to handle exceptions. Do not use the Qt ui file to design the UI because it will break on a high-DPI screen.

Starting point

The application consists of 2 binaries:

Frontend

This is what users will see when they launch Obliteration. Its entry point is inside src/main.cpp.

Kernel

This is where emulation takes place. Its entry point is inside src/kernel/src/main.rs.

Debugging the kernel

Create .kernel-debug in the root of the repository. The contents of this file is YAML and the kernel will deserialize it to the Args struct in src/kernel/src/main.rs when passing the --debug flag to the kernel. See Args struct for available options.

We already provide a launch configuration for VS Code so all you need to do is choose Debug - Kernel as the configuration and start debugging.

Code contribution

If you want to make some contributions but don't know what to work on you can look for TODO comment or todo! macro invocation in the source code. You can also take a look at unassigned issues.

Additional informations

PS4 Developer Wiki has a lot of useful information about the PS4 internal. We also have a PS4 reverse engineering project.