Skip to content

WIP: port: Add x64 FreeBSD#3927

Draft
xinitrcn1 wants to merge 7 commits intoshadps4-emu:mainfrom
xinitrcn1:main
Draft

WIP: port: Add x64 FreeBSD#3927
xinitrcn1 wants to merge 7 commits intoshadps4-emu:mainfrom
xinitrcn1:main

Conversation

@xinitrcn1
Copy link
Contributor

adds freebsd support

@xinitrcn1 xinitrcn1 marked this pull request as draft January 15, 2026 12:31
@georgemoralis
Copy link
Collaborator

issue with clang format , and where is the CI action?:D

@xinitrcn1
Copy link
Contributor Author

issue with clang format , and where is the CI action?:D

ci for freebsd is a can of worms i dont think we should open, and with we i mean I

@georgemoralis
Copy link
Collaborator

co-pilot gave me this :

` freebsd-sdl:
runs-on: ubuntu-24.04
needs: get-info
container:
image: freebsd/freebsd:14.1-RELEASE
steps:
- uses: actions/checkout@v5
with:
submodules: recursive

- name: Install dependencies
  run: |
    pkg update -f
    pkg install -y git cmake ninja ccache llvm16 mold libx11 libxext wayland libdecor-0 libxkbcommon glfw mesa-libs alsa-lib pulseaudio openal-soft libudev-devd libxcursor libxi libxss libxtst libGLX pkgconf

- name: Cache CMake Configuration
  uses: actions/cache@v4
  env:
      cache-name: ${{ runner.os }}-freebsd-sdl-cache-cmake-configuration
  with:
      path: |
        ${{github.workspace}}/build
      key: ${{ env.cache-name }}-${{ hashFiles('**/CMakeLists.txt', 'cmake/**') }}
      restore-keys: |
        ${{ env.cache-name }}-

- name: Configure CMake
  run: |
    cmake --fresh -B ${{github.workspace}}/build \
      -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
      -DCMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE=ON \
      -DCMAKE_C_COMPILER=/usr/local/bin/clang16 \
      -DCMAKE_CXX_COMPILER=/usr/local/bin/clang++16 \
      -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=/usr/local/bin/mold" \
      -DCMAKE_SHARED_LINKER_FLAGS="-fuse-ld=/usr/local/bin/mold" \
      -DCMAKE_C_COMPILER_LAUNCHER=/usr/local/bin/ccache \
      -DCMAKE_CXX_COMPILER_LAUNCHER=/usr/local/bin/ccache

- name: Build
  run: |
    # Get number of CPUs
    NPROC=$(sysctl -n hw.ncpu)
    cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --parallel $NPROC

- name: Package FreeBSD artifact
  run: |
    cd ${{github.workspace}}/build
    strip shadps4 || true
    tar czf shadps4-freebsd-${{ needs.get-info.outputs.shorthash }}.tar.gz shadps4

- uses: actions/upload-artifact@v4
  with:
    name: shadps4-freebsd-sdl-${{ needs.get-info.outputs.date }}-${{ needs.get-info.outputs.shorthash }}
    path: ${{github.workspace}}/build/shadps4-freebsd-${{ needs.get-info.outputs.shorthash }}.tar.gz

`
maybe you can adjust it

@xinitrcn1
Copy link
Contributor Author

xinitrcn1 commented Jan 15, 2026

co-pilot gave me this :

` freebsd-sdl: runs-on: ubuntu-24.04 needs: get-info container: image: freebsd/freebsd:14.1-RELEASE steps: - uses: actions/checkout@v5 with: submodules: recursive

- name: Install dependencies
  run: |
    pkg update -f
    pkg install -y git cmake ninja ccache llvm16 mold libx11 libxext wayland libdecor-0 libxkbcommon glfw mesa-libs alsa-lib pulseaudio openal-soft libudev-devd libxcursor libxi libxss libxtst libGLX pkgconf

- name: Cache CMake Configuration
  uses: actions/cache@v4
  env:
      cache-name: ${{ runner.os }}-freebsd-sdl-cache-cmake-configuration
  with:
      path: |
        ${{github.workspace}}/build
      key: ${{ env.cache-name }}-${{ hashFiles('**/CMakeLists.txt', 'cmake/**') }}
      restore-keys: |
        ${{ env.cache-name }}-

- name: Configure CMake
  run: |
    cmake --fresh -B ${{github.workspace}}/build \
      -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
      -DCMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE=ON \
      -DCMAKE_C_COMPILER=/usr/local/bin/clang16 \
      -DCMAKE_CXX_COMPILER=/usr/local/bin/clang++16 \
      -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=/usr/local/bin/mold" \
      -DCMAKE_SHARED_LINKER_FLAGS="-fuse-ld=/usr/local/bin/mold" \
      -DCMAKE_C_COMPILER_LAUNCHER=/usr/local/bin/ccache \
      -DCMAKE_CXX_COMPILER_LAUNCHER=/usr/local/bin/ccache

- name: Build
  run: |
    # Get number of CPUs
    NPROC=$(sysctl -n hw.ncpu)
    cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --parallel $NPROC

- name: Package FreeBSD artifact
  run: |
    cd ${{github.workspace}}/build
    strip shadps4 || true
    tar czf shadps4-freebsd-${{ needs.get-info.outputs.shorthash }}.tar.gz shadps4

- uses: actions/upload-artifact@v4
  with:
    name: shadps4-freebsd-sdl-${{ needs.get-info.outputs.date }}-${{ needs.get-info.outputs.shorthash }}
    path: ${{github.workspace}}/build/shadps4-freebsd-${{ needs.get-info.outputs.shorthash }}.tar.gz

` maybe you can adjust it

copilot, is, respectfully, stupid
trust me, freebsd is a pita to maintain in the ci
one day it will break, and you will not know why
i will not know why

remember freebsd is ran on a vm with libvirt within a github runner
freebsd runner sometimes fails because it felt that the weather was "not cozy"; take that as you will

i think there are like 2-3 shadPS4 users who use freebsd, either way maintaining freebsd support isn't that hard, just dont use linux-isms (basically like it was __APPLE__ without vm)

CMakeLists.txt Outdated
find_package(Zydis 5.0.0 CONFIG)
# Outdated zydis from ports
if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
find_package(Zydis 5.0.0 CONFIG)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? If the version in FreeBSD is outdated we should be using the submodule.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zydis will get updated soon so it wont matter in a few days

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just received info that zydis wont be updated till someone sends a new patch and that patch gets merged
which basically translates into eternity, i'll make it use submodules

Oh yeah one small issue through, find_package(Zydis 5.0.0 CONFIG) was suceeding even through zydis was NOT 5.0.0, it's 4.1.1 in FBSD ports - don't know why yet


if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
target_link_libraries(shadps4 PRIVATE "/usr/lib/libusb.so")
target_link_libraries(shadps4 PRIVATE "/usr/local/lib/libuuid.so")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to do this? Rather would not hard code library paths.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default cmake doesnt play nicely with some FreeBSD configs

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it would be nice if we could at least find_library or something as an alternative instead of hardcoding paths

add_subdirectory(ext-libusb)
add_library(libusb::usb ALIAS usb-1.0)
if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
# YOU MUST USE NATIVE LIBUSB
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot use native libusb as it does not enforce our ABI requirements to match callbacks from PS4 applications.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no libusb port for freebsd - only the native libusb from fbsd itself

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well I don't think this will work since the guest callback ABI likely won't match host, if libusb doesn't work as a submodule we would probably just need to disable it for FreeBSD.

}
shm_unlink(shm_path.c_str());
#elif defined(__FreeBSD__)
backing_fd = memfd_create("BackingDmem", 0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think you should just ifdef the madvise and leave the rest as common since its the same.

}
return false;
#elif defined(__FreeBSD__)
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No equivalent here?

Copy link
Contributor Author

@xinitrcn1 xinitrcn1 Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the "normal way" to do these things is via dtrace but the easiest way to find if there is dtrace, is to literally do:

system("pgrep dtrace")

and get the result code...

i mean there is also lldb/gdb but pragmatically it would mean making a gdb server and seeing if there is a gdb instance hooked up and lots of annoying details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants