AppleWin icon indicating copy to clipboard operation
AppleWin copied to clipboard

AppleWin to be included into libretro downloadable cores

Open zoltanvb opened this issue 9 months ago • 8 comments

Hello,

thank you for your work on this. Would you be interested in having the libretro core included to the RetroArch downloadable cores (or precompiled packages, depending on platform)? It has been mentioned a few times on Discord, and now also here: https://github.com/libretro/RetroArch/issues/17670

The advantage of this is that users would be able to immediately get the AppleWin core, but this can also mean a bit of extra exposure, increased user requests, and the need to keep the enabled platforms compilable.

Technically, it has a few components:

  • core should have an .info file submitted to libretro-super
  • core should be able to compile on libretro buildbot infrastructure, which, for the most platforms, is Docker based cross-compilation, I can make a try with some of the main ones
  • a .gitlab-ci.yml needs to be added to the repository that controls the compilation on the libretro buildbot
  • repository needs to be cloned to libretro servers (this part must be set up by libretro admins)
  • optimally, also some documentation on docs.libretro.com

Let me know what you think.

zoltanvb avatar Mar 10 '25 07:03 zoltanvb

Yes, I think it is definitely a very good idea.

This library currently compiles on Linux - mingw64 - FreeBSD - macos. The core has only ever been tested in the first 2.

I need to understand what I can / cannot do in the build script and how to replicate the build environment myself.

And what is the best location to discuss all of this, here? elsewhere?

audetto avatar Mar 10 '25 13:03 audetto

The Linux (x64) build environment can be tried as: sudo docker run -it --rm -v "AppleWin:/build" git.libretro.com:5050/libretro-infrastructure/libretro-build-amd64-ubuntu:xenial-gcc9 bash I have made some initial attempts, libboost-dev, libyaml-dev and libminizip-dev had to be installed, then build ran into problems due to xxd not being available.

zoltanvb avatar Mar 11 '25 19:03 zoltanvb

xenial? I have seen more recent distributions.

Anyway, xxd was provided by vim. Unfortunately static linking of libminizip.a (and yaml) is not working on xenial.

The best cmake command line at the moment is

cmake .. -DBUILD_LIBRETRO=ON -G Ninja

The list of required packages is in https://github.com/audetto/AppleWin/blob/master/source/linux/raspbian.list.txt

but a few did not exist in xenial so it needs to be reduced to

cmake
g++
ninja-build
pkg-config
libyaml-dev
libminizip-dev
libboost-program-options-dev
libncurses-dev
libevdev-dev
libsdl2-image-dev
libsdl2-dev
vim

audetto avatar Mar 14 '25 18:03 audetto

The build image is indeed ancient, partly on purpose, to keep binary compatibility. But it could probably be increased to bionic (by using git.libretro.com:5050/libretro-infrastructure/libretro-build-amd64-ubuntu:latest), as it was done with melonds-ds, which also installs some extra libraries: https://github.com/JesseTG/melonds-ds/blob/5d2ece5b6d7041aa9d0a7921eee42969f8bdf8a7/.gitlab-ci.yml#L68

zoltanvb avatar Mar 15 '25 15:03 zoltanvb

I tried to use

git.libretro.com:5050/libretro-infrastructure/libretro-build-amd64-ubuntu:latest

it claims to be VERSION="18.04.6 LTS (Bionic Beaver)", but it has a version of cmake older than

git.libretro.com:5050/libretro-infrastructure/libretro-build-amd64-ubuntu:xenial-gcc9

which claims to be VERSION="16.04.7 LTS (Xenial Xerus)"

My repo needs 3.13.

audetto avatar Mar 16 '25 16:03 audetto

Anyway, after copying the extra ppa from melonds-ds, I got it to compile.

Unfortunately yaml.a and minizip.a are still unusable.

Does it matter? The core compiles ok. Am I allowed to link some .so?

audetto avatar Mar 16 '25 16:03 audetto

I believe it is usually not preferred, as it limits the portability, but it is not enforced. Here is a crude scan of dynamic libraries in current Linux x86_64 cores: core_dynamic_libs.txt

zoltanvb avatar Mar 17 '25 06:03 zoltanvb

I really do not understand why Ubuntu builds static libraries without -fPIC: fast, but unusable!

Anyway, I have never wanted to include the source code of libraries I can get for free, and without effort.

We can postpone this issue and see what else is required.

audetto avatar Mar 17 '25 20:03 audetto

I've done a lot of cleanup both in libretro integration and in the build system.

This branch https://github.com/audetto/AppleWin/tree/xenial-build generates a very clean core.

root@eacfc3eebca2:~/AppleWin# ll build/source/frontends/libretro                     
total 8212
drwxr-xr-x 3 root root    4096 Mar 23 10:04 ./
drwxr-xr-x 4 root root    4096 Mar 23 10:03 ../
drwxr-xr-x 3 root root    4096 Mar 23 10:03 CMakeFiles/
-rw-r--r-- 1 root root     350 Mar 23 10:03 applewin_libretro.info
-rwxr-xr-x 1 root root 8385608 Mar 23 10:04 applewin_libretro.so*
-rw-r--r-- 1 root root    1259 Mar 23 10:03 cmake_install.cmake

root@eacfc3eebca2:~/AppleWin# ldd build/source/frontends/libretro/applewin_libretro.so
	linux-vdso.so.1 =>  (0x00007fff88396000)
	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007dcdb3c47000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007dcdb393e000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007dcdb3574000)
	/lib64/ld-linux-x86-64.so.2 (0x00007dcdb47c3000)

What is the next step?

audetto avatar Mar 23 '25 10:03 audetto

Wow, great! Thank you for the efforts, I reproduced the build with minimal effort.

Next step could be reproducing 64-bit Windows builds, it is done using cross-compiling with another Docker image: git.libretro.com:5050/libretro-infrastructure/libretro-build-mxe-win-cross-cores:gcc11. Also, I plan to take a look at producing an Android build (it was requested here: https://forums.libretro.com/t/apple-ii-core-for-android/47480 ), it may need a few extra files but hopefully nothing that interferes with existing code.

zoltanvb avatar Mar 26 '25 06:03 zoltanvb

How do I use it?

docker run -it --rm -v git.libretro.com:5050/libretro-infrastructure/libretro-build-mxe-win-cross-cores:gcc11 bash

tells me

docker: Error response from daemon: invalid mode: gcc11.

audetto avatar Mar 27 '25 09:03 audetto

now this works

docker run -it --rm -v "AppleWin:/build" git.libretro.com:5050/libretro-infrastructure/libretro-build-mxe-win-cross-cores:gcc11 bash

but I have no idea what to do with it.

is there any help on all of these target environments?

audetto avatar Mar 29 '25 19:03 audetto

Hi, sorry for the long feedback times. This container is using Bionic, but the cmake version is still too old, I was able to make first steps with:

apt-get install apt-transport-https ca-certificates gnupg software-properties-common wget
wget -qO - https://apt.kitware.com/keys/kitware-archive-latest.asc | apt-key add -
apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main'
apt-get update
apt-get install cmake
apt install libboost-dev
ln -s /usr/bin/ninja /usr/local/bin/ninja

For some reason, ninja is present, but in a different location, hence the linkage.

zoltanvb avatar Mar 30 '25 07:03 zoltanvb

Oops, no, this will try a Linux binary... Cmake should be invoked like: x86_64-w64-mingw32.static-cmake

zoltanvb avatar Mar 30 '25 07:03 zoltanvb

Fine. If you explain me what the goal is, I can try to help.

I understand there is a x-compiler cmake, but how do I install cross compiler packages?

audetto avatar Mar 31 '25 11:03 audetto

I suspect the only missing package is boost, but I have not found how to install it.

audetto avatar Apr 01 '25 19:04 audetto

This seems to bring a few:

    echo "deb http://pkg.mxe.cc/repos/apt bionic main" > /etc/apt/sources.list.d/mxeapt.list
    apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C6BF758A33A3A276
    apt-get update

Maybe the needed one is mxe-x86-64-w64-mingw32.static-boost .

zoltanvb avatar Apr 01 '25 20:04 zoltanvb

The mxe packages currently available in the image are cc cmake bzip2 curl gcc glib gmp gnutls libpng nettle pixman pkgconf dlfcn-win32 libsndfile sdl_net sdl2 zlib libxml2 freetype fribidi ninja nasm

Source

Using xenial-build branch

docker run -it --rm -v "/path/to/AppleWin:/build" git.libretro.com:5050/libretro-infrastructure/libretro-build-mxe-win-cross-cores:gcc11 bash
cd /build
/usr/lib/mxe/usr/bin/x86_64-w64-mingw32.static-cmake -DBUILD_LIBRETRO=ON -B build -G Ninja

I get this result

Log
== Using MXE wrapper: /usr/lib/mxe/usr/bin/x86_64-w64-mingw32.static-cmake
     - cmake version 3.23.1
     - warnings for unused CMAKE_POLICY_DEFAULT variables can be ignored
== Using MXE toolchain: /usr/lib/mxe/usr/x86_64-w64-mingw32.static/share/cmake/mxe-conf.cmake
== Using MXE runresult: /usr/lib/mxe/usr/share/cmake/modules/TryRunResults.cmake
== Adding "-DCMAKE_BUILD_TYPE=Release"
loading initial cache file /usr/lib/mxe/usr/share/cmake/modules/TryRunResults.cmake
CMAKE_BUILD_TYPE:                Release
CMAKE_CXX_FLAGS:                 
CMAKE_CXX_FLAGS_RELEASE:         -O3 -DNDEBUG
CMAKE_CXX_FLAGS_DEBUG:           -g
CMAKE_CXX_FLAGS_RELWITHDEBINFO:  -O2 -g -DNDEBUG
CMake Warning at source/CMakeLists.txt:14 (message):
  'libslirp' not found: will try 'libpcap' instead


-- Checking for one of the modules 'libpcap'
CMake Error at /usr/lib/mxe/usr/x86_64-pc-linux-gnu/share/cmake-3.23/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find Boost (missing: Boost_INCLUDE_DIR)
Call Stack (most recent call first):
  /usr/lib/mxe/usr/x86_64-pc-linux-gnu/share/cmake-3.23/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  /usr/lib/mxe/usr/x86_64-pc-linux-gnu/share/cmake-3.23/Modules/FindBoost.cmake:2375 (find_package_handle_standard_args)
  source/CMakeLists.txt:34 (find_package)


-- Configuring incomplete, errors occurred!
See also "/build/build/CMakeFiles/CMakeOutput.log".

Using apt install mxe-x86-64-pc-linux-gnu-boost after adding apt repository. CMake still can't find it.

To be continued ;)

gouchi avatar Apr 09 '25 21:04 gouchi

With

apt install mxe-x86-64-w64-mingw32.static-boost

then cmake works, but gcc is too old.

root@78fbd2e5cd1f:/build/AppleWin/build# /usr/lib/mxe/usr/bin/x86_64-w64-mingw32.static-gcc --version
x86_64-w64-mingw32.static-gcc (GCC) 5.5.0

how do I get a newer version?

audetto avatar Apr 18 '25 19:04 audetto

The problem is that as soon as I install mxe-x86-64-w64-mingw32.static-boost this installs the old gcc 5 as well.

This is because the gcc mxe package is not installed, even if the executable /usr/lib/mxe/usr/bin/x86_64-w64-mingw32.static-gcc already exists.

It looks to me that the base image is not consistent and apt is not aware of things already installed and so it tries to reinstall them.

I can't avoid the feeling that we are reinventing the wheel. How are all other cores using all of this?

Just to make clear, if I use a real mingw64 on Windows, it all works out of the box and such a build is run on every commit via the github workflow.

audetto avatar Apr 19 '25 09:04 audetto

The answer is here:

https://git.libretro.com/libretro-infrastructure/libretro-build-mxe-win-cross-cores/-/blob/fb98d96078250a582ada5d30ee67e503c4358250/Dockerfile.gcc11#L128

packages must not be installed via apt but built in the mxe checkout under /usr/lib/mxe

anyway, this project only needs boost header files not libraries.

ideally, it should be added to the base image.

do this

cd /usr/lib/mxe
make boost

the it works, or at least there are some compiler errors which I will look into.

audetto avatar Apr 19 '25 09:04 audetto

OK, pushed a new commit, full instructions are

  1. make boost in /usr/lib/mxe (takes 10-15 minutes)
  2. apt install xxd
  3. cmake... etc.

audetto avatar Apr 19 '25 10:04 audetto

I am now able to cross-compile from Ubuntu inside VSCode using a mxe cmake kit.

Add this file to your .vscode folder

[
  {
    "name": "MXE",
    "toolchainFile": "/path/to/mxe/usr/x86_64-w64-mingw32.static/share/cmake/mxe-conf.cmake"
  }
]

It shows a warning, but works.

Then, you can just switch compiler in the VSCode status bar.

audetto avatar Apr 20 '25 18:04 audetto

Is still still active? What do we need to do exactly?

audetto avatar May 24 '25 17:05 audetto

We have a little documentation about adding a Libretro core to the Libretro CI/CD.

So first, the core info file should be submitted to Libretro super repository then we should create gitlab-ci.yml.

@zoltanvb if you have the opportunity to make some compilation test.

Thank you.

gouchi avatar May 24 '25 20:05 gouchi

Adding the core info is easy, but for gitlab-ci.yml I will need help.

For now, all changes have been merged to master.

audetto avatar May 26 '25 18:05 audetto

First all, you should select the platform where the core could be compiled as there are a lot of platforms.

I selected some .gitlab-ci.yml which are using CMake 1 2 3 4 5

Then we could try to enable it on the Libretro CI/CD to make some test compilation to fix potential compilation issue.

gouchi avatar May 31 '25 12:05 gouchi

I don't really know what they do.

Let's pick one (https://github.com/libretro/arduous/blob/main/.gitlab-ci.yml) and see what happens.

What is the next step?

audetto avatar Jun 01 '25 18:06 audetto

For now, I put "straightforward" .gitlab-ci.yml,we can extend it later on if we need some something specific build options for a platform using for example

.core-defs-XXX:
  extends: .core-defs
  variables:
    CORE_ARGS: -DLIBRETRO=ON -DCMAKE_BUILD_TYPE=Release -DXXX

Source

.gitlab-ci.yml
# DESCRIPTION: GitLab CI/CD for libRetro (NOT FOR GitLab-proper)

##############################################################################
################################# BOILERPLATE ################################
##############################################################################

# Core definitions
.core-defs:
  variables:
    GIT_SUBMODULE_STRATEGY: recursive
    CORENAME: applewin
    CORE_ARGS: -DBUILD_LIBRETRO=ON -DCMAKE_BUILD_TYPE=Release

# Inclusion templates, required for the build to work
include:
  ################################## DESKTOPS ################################
  # Windows
  - project: 'libretro-infrastructure/ci-templates'
    file: '/windows-cmake-mingw.yml'

  # MacOS
  - project: 'libretro-infrastructure/ci-templates'
    file: 'osx-cmake-x86.yml'

  # MacOS
  - project: 'libretro-infrastructure/ci-templates'
    file: 'osx-cmake-arm64.yml'

  # Linux
  - project: 'libretro-infrastructure/ci-templates'
    file: '/linux-cmake.yml'

  # DJGPP
  - project: 'libretro-infrastructure/ci-templates'
    file: '/djgpp-static-cmake.yml'

  ################################## CELLULAR ################################
  # Android
  - project: 'libretro-infrastructure/ci-templates'
    file: '/android-cmake.yml'

  # iOS
  - project: 'libretro-infrastructure/ci-templates'
    file: '/ios-cmake.yml'

  ################################## CONSOLES ################################
  # Libnx
  - project: 'libretro-infrastructure/ci-templates'
    file: '/libnx-static-cmake.yml'

  # CTR (3DS)
  - project: 'libretro-infrastructure/ci-templates'
    file: '/ctr-static-cmake.yml'

  # PSP
  - project: 'libretro-infrastructure/ci-templates'
    file: '/psp-static-cmake.yml'

  # PS2
  - project: 'libretro-infrastructure/ci-templates'
    file: '/ps2-static-cmake.yml'

  # VITA
  - project: 'libretro-infrastructure/ci-templates'
    file: '/vita-static-cmake.yml'

  # WiiU
  - project: 'libretro-infrastructure/ci-templates'
    file: '/wiiu-static-cmake.yml'

  # tvOS
  - project: 'libretro-infrastructure/ci-templates'
    file: '/tvos-cmake.yml'

  # Dingux
  - project: 'libretro-infrastructure/ci-templates'
    file: '/dingux-cmake.yml'

  # Wii
  - project: 'libretro-infrastructure/ci-templates'
    file: '/wii-static-cmake.yml'

  # Gamecube
  - project: 'libretro-infrastructure/ci-templates'
    file: '/ngc-static-cmake.yml'

  ################################## MISC ####################################
  # Emscripten
  - project: 'libretro-infrastructure/ci-templates'
    file: '/emscripten-static-cmake.yml' 

# Stages for building
stages:
  - build-prepare
  - build-shared
  - build-static

##############################################################################
#################################### STAGES ##################################
##############################################################################
#
################################### DESKTOPS #################################
# Windows 64-bit
libretro-build-windows-x64:
  extends:
    - .libretro-windows-cmake-x86_64
    - .core-defs

# Windows 32-bit
libretro-build-windows-i686:
  extends:
    - .libretro-windows-cmake-x86
    - .core-defs

# Linux 64-bit
libretro-build-linux-x64:
  extends:
    - .libretro-linux-cmake-x86_64

# Linux 32-bit
libretro-build-linux-i686:
  extends:
    - .libretro-linux-cmake-x86

# MacOS 32-bit
libretro-build-osx-x86:
  extends:
    - .libretro-osx-cmake-x86
    - .core-defs

# MacOS 64-bit
libretro-build-osx-x64:
  extends:
    - .libretro-osx-cmake-x86_64
    - .core-defs

# MacOS ARM64
libretro-build-osx-arm64:
  extends:
    - .libretro-osx-cmake-arm64
    - .core-defs

# DJGPP
libretro-build-djgpp-i586:
  extends:
    - .libretro-djgpp-static-cmake-retroarch-master
    - .core-defs

################################### CELLULAR #################################
# Android ARMv7a
android-armeabi-v7a:
  extends:
    - .libretro-android-cmake-armeabi-v7a
    - .core-defs

# Android ARMv8a
android-arm64-v8a:
  extends:
    - .libretro-android-cmake-arm64-v8a
    - .core-defs

# Android 64-bit x86
android-x86_64:
  extends:
    - .libretro-android-cmake-x86_64
    - .core-defs

# Android 32-bit x86
android-x86:
  extends:
    - .libretro-android-cmake-x86
    - .core-defs

# iOS arm64
libretro-build-ios-arm64:
  extends:
    - .libretro-ios-cmake-arm64
    - .core-defs

# iOS armv7
libretro-build-ios9:
  extends:
    - .libretro-ios-cmake-ios9
    - .core-defs

################################### CONSOLES #################################
# Libnx
libretro-build-libnx-aarch64:
  extends:
    - .libretro-libnx-static-cmake-retroarch-master
    - .core-defs

# CTR (3ds)
libretro-build-ctr:
  extends:
    - .libretro-ctr-static-cmake-retroarch-master
    - .core-defs

# PSP
libretro-build-psp:
  extends:
    - .libretro-psp-static-cmake-retroarch-master
    - .core-defs

# PS2
libretro-build-ps2:
  extends:
    - .libretro-ps2-static-cmake-retroarch-master
    - .core-defs

# VITA
libretro-build-vita:
  extends:
    - .libretro-vita-static-cmake-retroarch-master
    - .core-defs

# tvOS arm64
libretro-build-tvos-arm64:
  extends:
    - .libretro-tvos-cmake-arm64
    - .core-defs

# WiiU
libretro-build-wiiu:
  extends:
    - .libretro-wiiu-static-cmake-retroarch-master
    - .core-defs

# Dingux
libretro-build-dingux-mips32:
  extends:
    - .libretro-dingux-cmake-mips32
    - .core-defs

libretro-build-dingux-odbeta-mips32:
  extends:
    - .libretro-dingux-odbeta-cmake-mips32
    - .core-defs

libretro-build-rs90-odbeta-mips32:
  extends:
    - .libretro-rs90-odbeta-cmake-mips32
    - .core-defs

libretro-build-retrofw-mips32:
  extends:
    - .libretro-retrofw-odbeta-cmake-mips32
    - .core-defs

libretro-build-miyoo-arm32:
  extends:
    - .libretro-miyoo-cmake-arm32
    - .core-defs

# Wii
libretro-build-wii:
  extends:
    - .libretro-wii-static-cmake-retroarch-master
    - .core-defs

# Gamecube
libretro-build-ngc:
  extends:
    - .libretro-ngc-static-cmake-retroarch-master
    - .core-defs

################################### MISC #####################################

# Emscripten
libretro-build-emscripten:
  extends:
    - .libretro-emscripten-static-cmake-retroarch-master
    - .core-defs

gouchi avatar Jun 01 '25 19:06 gouchi

To catch up again, I reproduced the Linux 64-bit build manually, with following commands:

sudo docker run --rm -it -m5G -v "<path>/AppleWin:/build" git.libretro.com:5050/libretro-infrastructure/libretro-build-amd64-ubuntu:xenial-gcc9 bash
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 16FAAD7AF99A65E2
apt-get update -qy
apt-get -qy install $(cat source/frontends/libretro/xenial/packages.txt)
cmake -DBUILD_LIBRETRO=ON -B build -G Ninja
cd build
ninja

I definitely recommend starting with a highly reduced set of .gitlab-ci.yml, enabling only the ones that have been validated manually, starting with 64-bit Linux build.

The 3 apt install commands can go to the before_script part, as with MelonDS DS. Image can be specified as:

image: $CI_SERVER_HOST:5050/libretro-infrastructure/libretro-build-amd64-ubuntu:xenial-gcc9

And based on the common cmake template, some variables are also required:

CORENAME=applewin
CORE_ARGS="-DBUILD_LIBRETRO=ON -G Ninja"
EXTRA_PATH=source/frontends/libretro/

I tried to simulate the buildbot manually using these definitions, and it did result in a successful build. I will also try to check the Windows build eventually.

zoltanvb avatar Jun 02 '25 20:06 zoltanvb