foxygit / fake-08-xbox360 Log in
commit 29d7996aabaf7268037fd95688be6cd227e93f98
Author:     Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Sun Sep 24 18:15:05 2023 -0600
Commit:     Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Sun Sep 24 18:24:35 2023 -0600

    Add switch libretro build

    manually cherry picked from other branch without attempt at vita core
    mixed in.
---
 .github/workflows/build.yml               | 28 +++++++++++++++++++++++++++-
 .github/workflows/buildSwitch-libretro.sh | 16 ++++++++++++++++
 .github/workflows/buildSwitch.sh          |  1 -
 platform/libretro/Makefile                | 18 ++++++++++++++++--
 4 files changed, 59 insertions(+), 4 deletions(-)

diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 390f731..9cbeb99 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -256,4 +256,30 @@ jobs:
           name: GCW0-libretro
           path: |
             platform/libretro/fake08_libretro_gcw0.so
-            platform/libretro/fake08_libretro.info
\ No newline at end of file
+            platform/libretro/fake08_libretro.info
+
+  switch-libretro:
+    name: switch-libretro
+    runs-on: ubuntu-latest
+
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v3
+        with:
+          submodules : recursive
+
+      - name: CheckoutLibretro
+        uses: actions/checkout@v3
+        with:
+          repository: libretro/RetroArch
+          path: retroarch
+
+      - name: Build
+        run: |
+          docker run -e ENABLE_COMPATIBILITY_REPORTING -v $GITHUB_WORKSPACE:/build_dir devkitpro/devkita64 /bin/bash -ex /build_dir/.github/workflows/buildSwitch-libretro.sh
+      - uses: actions/upload-artifact@v3
+        with:
+          name: switch-libretro
+          path: |
+            platform/libretro/fake08_libretro.info
+            retroarch/fake08_libretro_libnx.nro
diff --git a/.github/workflows/buildSwitch-libretro.sh b/.github/workflows/buildSwitch-libretro.sh
new file mode 100644
index 0000000..8af012c
--- /dev/null
+++ b/.github/workflows/buildSwitch-libretro.sh
@@ -0,0 +1,16 @@
+#source /etc/profile.d/devkit-env.sh
+
+cd /build_dir
+
+#Build core
+cd platform/libretro
+make echo platform=libnx
+make platform=libnx
+
+cp fake08_libretro_libnx.a ../../retroarch/libretro_libnx.a
+
+cd ../../retroarch
+
+make -f Makefile.libnx
+
+cp retroarch_switch.nro fake08_libretro_libnx.nro
diff --git a/.github/workflows/buildSwitch.sh b/.github/workflows/buildSwitch.sh
index 7cac627..66bd49b 100644
--- a/.github/workflows/buildSwitch.sh
+++ b/.github/workflows/buildSwitch.sh
@@ -5,4 +5,3 @@ cd /build_dir
 #Build nro
 make switch

-#todo: copy artifacts for uploading
diff --git a/platform/libretro/Makefile b/platform/libretro/Makefile
index e2e1d49..be0f1b4 100644
--- a/platform/libretro/Makefile
+++ b/platform/libretro/Makefile
@@ -133,6 +133,16 @@ else ifeq ($(platform), gcw0)
    CXXFLAGS += -fno-common -ftree-vectorize -funswitch-loops
    fpic := -fPIC
    SHARED := -shared -Wl,-version-script=link.T
+else ifeq ($(platform), libnx)
+   TARGET := $(TARGET_NAME)_libretro_$(platform).a
+   include $(DEVKITPRO)/libnx/switch_rules
+   STATIC_LINKING = 1
+   DEFINES := -D__SWITCH__ -DSWITCH=1
+   CFLAGS	:=	 $(DEFINES) -g -O3 \
+                 -fPIE -I$(LIBNX)/include/ -ffunction-sections -fdata-sections -ftls-model=local-exec -Wl,--allow-multiple-definition -specs=$(LIBNX)/switch.specs
+   CFLAGS += $(INCDIRS)
+   CFLAGS	+=	-DHAVE_LIBNX -march=armv8-a -mtune=cortex-a57 -mtp=soft
+   CXXFLAGS := $(ASFLAGS) $(CFLAGS)
 else
    CC = gcc
    TARGET := $(TARGET_NAME)_libretro.dll
@@ -158,8 +168,8 @@ CC = $(CXX)

 OBJECTS := $(SOURCES_C:.c=.o) $(SOURCES_CXX:.cpp=.o)

-CFLAGS   += $(fpic) -Wall -D__LIBRETRO__ -ffunction-sections -std=gnu++17 -fno-rtti $(INCFLAGS)
-CXXFLAGS += $(fpic) -Wall -D__LIBRETRO__ -ffunction-sections -std=gnu++17 -fno-rtti $(INCFLAGS)
+CFLAGS   += $(fpic) -Wall -D__LIBRETRO__ -DMINIZ_NO_TIME -ffunction-sections -std=gnu++17 -fno-rtti $(INCFLAGS)
+CXXFLAGS += $(fpic) -Wall -D__LIBRETRO__ -DMINIZ_NO_TIME -ffunction-sections -std=gnu++17 -fno-rtti $(INCFLAGS)

 all: $(TARGET)

@@ -175,6 +185,10 @@ endif
 	@$(if $(Q), $(shell echo echo CC $<),)
 	$(Q)$(CXX) $(CFLAGS) $(fpic) -c -o $@ $<

+%.o: %.cpp
+	@$(if $(Q), $(shell echo echo CXX $<),)
+	$(Q)$(CXX) $(CFLAGS) $(fpic) -c -o $@ $<
+
 clean:
 	rm -f $(OBJECTS) $(TARGET)