Skip to content

Commit

Permalink
[Nx] allow for per vfs build options, add switch workflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
ITotalJustice committed Dec 30, 2024
1 parent 888893f commit a8ac234
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 76 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/build_switch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: build_switch

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
preset: [switch]
runs-on: ${{ matrix.os }}
container: devkitpro/devkita64:latest

steps:
- uses: actions/checkout@v3

# fetch latest cmake
- uses: lukka/get-cmake@latest

- name: Configure CMake
# disable ftp-gc until dkpa64 container uses latest libnx
run: |
cmake --preset ${{ matrix.preset }} -DUSE_VFS_GC=0
- name: Build
run: cmake --build --preset ${{ matrix.preset }} --parallel 4
176 changes: 108 additions & 68 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,96 +216,130 @@ if (FTPSRV_LIB_BUILD)
)
else()
if (NINTENDO_SWITCH)
if (NOT DEFINED USE_VFS_SAVE)
set(USE_VFS_SAVE TRUE)
endif()
if (NOT DEFINED USE_VFS_STORAGE)
set(USE_VFS_STORAGE TRUE)
endif()
if (NOT DEFINED USE_VFS_GC)
set(USE_VFS_GC TRUE)
endif()
if (NOT DEFINED USE_VFS_USBHSFS)
set(USE_VFS_USBHSFS TRUE)
endif()

ftp_set_options(ftpsrv 769 128 1024*64)
fetch_minini()

set(USBHSFS_GPL ON)
FetchContent_Declare(libusbhsfs
GIT_REPOSITORY https://github.com/DarkMatterCore/libusbhsfs.git
GIT_TAG v0.2.9
set(NX_SRC
src/platform/nx/vfs_nx.c
src/platform/nx/vfs/vfs_nx_none.c
src/platform/nx/vfs/vfs_nx_root.c
src/platform/nx/vfs/vfs_nx_fs.c
src/platform/nx/reboot_to_payload/ams_bpc.c
src/platform/nx/reboot_to_payload/reboot_to_payload.c
src/platform/nx/rtc/max77620-rtc.c
src/platform/nx/custom_commands.c
src/platform/nx/utils.c
src/log/log.c
)

FetchContent_MakeAvailable(libusbhsfs)
add_library(libusbhsfs
${libusbhsfs_SOURCE_DIR}/source/usbhsfs_drive.c
${libusbhsfs_SOURCE_DIR}/source/usbhsfs_log.c
${libusbhsfs_SOURCE_DIR}/source/usbhsfs_manager.c
${libusbhsfs_SOURCE_DIR}/source/usbhsfs_mount.c
${libusbhsfs_SOURCE_DIR}/source/usbhsfs_request.c
${libusbhsfs_SOURCE_DIR}/source/usbhsfs_scsi.c
${libusbhsfs_SOURCE_DIR}/source/usbhsfs_utils.c
target_compile_definitions(ftpsrv PUBLIC
FTP_VFS_HEADER="${CMAKE_CURRENT_SOURCE_DIR}/src/platform/nx/vfs_nx.h"
FTP_SOCKET_HEADER="${CMAKE_CURRENT_SOURCE_DIR}/src/platform/unistd/socket_unistd.h"
VFS_NX_BUFFER_WRITES=1
)

target_include_directories(libusbhsfs PUBLIC ${libusbhsfs_SOURCE_DIR}/include)
if (USE_VFS_SAVE)
list(APPEND NX_SRC src/platform/nx/vfs/vfs_nx_save.c)
endif()
if (USE_VFS_STORAGE)
list(APPEND NX_SRC src/platform/nx/vfs/vfs_nx_storage.c)
endif()
if (USE_VFS_GC)
list(APPEND NX_SRC src/platform/nx/vfs/vfs_nx_gc.c)
endif()

# fatfs stuff
target_sources(libusbhsfs PRIVATE
${libusbhsfs_SOURCE_DIR}/source/fatfs/diskio.c
${libusbhsfs_SOURCE_DIR}/source/fatfs/ff_dev.c
${libusbhsfs_SOURCE_DIR}/source/fatfs/ff.c
${libusbhsfs_SOURCE_DIR}/source/fatfs/ffsystem.c
${libusbhsfs_SOURCE_DIR}/source/fatfs/ffunicode.c
add_executable(ftpexe
src/platform/nx/main.c
${NX_SRC}
)

# sxos stuff
target_sources(libusbhsfs PRIVATE
${libusbhsfs_SOURCE_DIR}/source/sxos/usbfs_dev.c
${libusbhsfs_SOURCE_DIR}/source/sxos/usbfs.c
target_compile_definitions(ftpexe PUBLIC
USE_VFS_SAVE=$<BOOL:${USE_VFS_SAVE}>
USE_VFS_STORAGE=$<BOOL:${USE_VFS_STORAGE}>
USE_VFS_GC=$<BOOL:${USE_VFS_GC}>
USE_VFS_USBHSFS=$<BOOL:${USE_VFS_USBHSFS}>
)

if (USBHSFS_GPL)
if (USE_VFS_USBHSFS)
set(USBHSFS_GPL ON)
FetchContent_Declare(libusbhsfs
GIT_REPOSITORY https://github.com/DarkMatterCore/libusbhsfs.git
GIT_TAG v0.2.9
)

FetchContent_MakeAvailable(libusbhsfs)
add_library(libusbhsfs
${libusbhsfs_SOURCE_DIR}/source/usbhsfs_drive.c
${libusbhsfs_SOURCE_DIR}/source/usbhsfs_log.c
${libusbhsfs_SOURCE_DIR}/source/usbhsfs_manager.c
${libusbhsfs_SOURCE_DIR}/source/usbhsfs_mount.c
${libusbhsfs_SOURCE_DIR}/source/usbhsfs_request.c
${libusbhsfs_SOURCE_DIR}/source/usbhsfs_scsi.c
${libusbhsfs_SOURCE_DIR}/source/usbhsfs_utils.c
)

target_include_directories(libusbhsfs PUBLIC ${libusbhsfs_SOURCE_DIR}/include)

# fatfs stuff
target_sources(libusbhsfs PRIVATE
${libusbhsfs_SOURCE_DIR}/source/lwext4/ext_dev.c
${libusbhsfs_SOURCE_DIR}/source/lwext4/ext_disk_io.c
${libusbhsfs_SOURCE_DIR}/source/lwext4/ext.c
${libusbhsfs_SOURCE_DIR}/source/fatfs/diskio.c
${libusbhsfs_SOURCE_DIR}/source/fatfs/ff_dev.c
${libusbhsfs_SOURCE_DIR}/source/fatfs/ff.c
${libusbhsfs_SOURCE_DIR}/source/fatfs/ffsystem.c
${libusbhsfs_SOURCE_DIR}/source/fatfs/ffunicode.c
)

${libusbhsfs_SOURCE_DIR}/source/ntfs-3g/ntfs_dev.c
${libusbhsfs_SOURCE_DIR}/source/ntfs-3g/ntfs_disk_io.c
${libusbhsfs_SOURCE_DIR}/source/ntfs-3g/ntfs.c
# sxos stuff
target_sources(libusbhsfs PRIVATE
${libusbhsfs_SOURCE_DIR}/source/sxos/usbfs_dev.c
${libusbhsfs_SOURCE_DIR}/source/sxos/usbfs.c
)

find_library(ntfs_3g_lib ntfs-3g REQUIRED)
find_path(ntfs_3g_inc ntfs-3g REQUIRED)
if (USBHSFS_GPL)
target_sources(libusbhsfs PRIVATE
${libusbhsfs_SOURCE_DIR}/source/lwext4/ext_dev.c
${libusbhsfs_SOURCE_DIR}/source/lwext4/ext_disk_io.c
${libusbhsfs_SOURCE_DIR}/source/lwext4/ext.c

find_library(lwext4_lib lwext4 REQUIRED)
find_path(lwext4_inc ext4.h REQUIRED)
${libusbhsfs_SOURCE_DIR}/source/ntfs-3g/ntfs_dev.c
${libusbhsfs_SOURCE_DIR}/source/ntfs-3g/ntfs_disk_io.c
${libusbhsfs_SOURCE_DIR}/source/ntfs-3g/ntfs.c
)

target_link_libraries(libusbhsfs PRIVATE ${ntfs_3g_lib} ${lwext4_lib})
target_include_directories(libusbhsfs PRIVATE ${ntfs_3g_inc} ${lwext4_inc})
target_compile_definitions(libusbhsfs PRIVATE GPL_BUILD)
endif()
find_library(ntfs_3g_lib ntfs-3g REQUIRED)
find_path(ntfs_3g_inc ntfs-3g REQUIRED)

target_compile_definitions(ftpsrv PUBLIC
FTP_VFS_HEADER="${CMAKE_CURRENT_SOURCE_DIR}/src/platform/nx/vfs_nx.h"
FTP_SOCKET_HEADER="${CMAKE_CURRENT_SOURCE_DIR}/src/platform/unistd/socket_unistd.h"
VFS_NX_BUFFER_WRITES=1
)
find_library(lwext4_lib lwext4 REQUIRED)
find_path(lwext4_inc ext4.h REQUIRED)

set(NX_SRC
src/platform/nx/vfs_nx.c
src/platform/nx/vfs/vfs_nx_none.c
src/platform/nx/vfs/vfs_nx_root.c
src/platform/nx/vfs/vfs_nx_fs.c
src/platform/nx/vfs/vfs_nx_save.c
src/platform/nx/vfs/vfs_nx_storage.c
src/platform/nx/vfs/vfs_nx_gc.c
src/platform/nx/utils.c
src/platform/nx/reboot_to_payload/ams_bpc.c
src/platform/nx/reboot_to_payload/reboot_to_payload.c
src/platform/nx/rtc/max77620-rtc.c
src/platform/nx/custom_commands.c
src/log/log.c
)
target_link_libraries(libusbhsfs PRIVATE ${ntfs_3g_lib} ${lwext4_lib})
target_include_directories(libusbhsfs PRIVATE ${ntfs_3g_inc} ${lwext4_inc})
target_compile_definitions(libusbhsfs PRIVATE GPL_BUILD)
endif()

target_link_libraries(ftpexe PRIVATE libusbhsfs)

target_sources(ftpexe PRIVATE
src/platform/nx/vfs/vfs_nx_stdio.c
src/platform/nx/vfs/vfs_nx_hdd.c
)
endif()

add_executable(ftpexe
src/platform/nx/main.c
src/platform/nx/vfs/vfs_nx_stdio.c
src/platform/nx/vfs/vfs_nx_hdd.c
${NX_SRC}
)
target_compile_definitions(ftpexe PUBLIC USE_USBHSFS=1)
ftp_add(ftpexe)
target_link_libraries(ftpexe PRIVATE ftpsrv minIni libusbhsfs)
target_link_libraries(ftpexe PRIVATE ftpsrv minIni)

nx_generate_nacp(
OUTPUT ftpexe.nacp
Expand Down Expand Up @@ -337,6 +371,12 @@ else()
ftp_add(sysftp)
target_link_libraries(sysftp PRIVATE ftpsrv_sysmod minIni)

target_compile_definitions(ftpexe PUBLIC
USE_VFS_SAVE=$<BOOL:${USE_VFS_SAVE}>
USE_VFS_STORAGE=$<BOOL:${USE_VFS_STORAGE}>
USE_VFS_GC=$<BOOL:${USE_VFS_GC}>
)

file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/420000000000011B)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/420000000000011B/flags)

Expand Down
1 change: 1 addition & 0 deletions src/platform/nx/vfs/vfs_nx_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

#include "ftpsrv_vfs.h"
#include "vfs_nx_gc.h"
#include "log/log.h"
#include <errno.h>
#include <string.h>
Expand Down
1 change: 1 addition & 0 deletions src/platform/nx/vfs/vfs_nx_hdd.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

#include "ftpsrv_vfs.h"
#include "vfs_nx_hdd.h"
#include "log/log.h"
#include <errno.h>
#include <sys/stat.h>
Expand Down
1 change: 1 addition & 0 deletions src/platform/nx/vfs/vfs_nx_save.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

#include "ftpsrv_vfs.h"
#include "vfs_nx_save.h"
#include "../utils.h"
#include "log/log.h"
#include <errno.h>
Expand Down
1 change: 1 addition & 0 deletions src/platform/nx/vfs/vfs_nx_stdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

#include "ftpsrv_vfs.h"
#include "vfs_nx_stdio.h"
#include "log/log.h"
#include <errno.h>
#include <sys/stat.h>
Expand Down
1 change: 1 addition & 0 deletions src/platform/nx/vfs/vfs_nx_storage.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "ftpsrv_vfs.h"
#include "vfs_nx_storage.h"
#include "log/log.h"
#include <errno.h>
#include <string.h>
Expand Down
25 changes: 22 additions & 3 deletions src/platform/nx/vfs_nx.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ static const FtpVfs* g_vfs[] = {
[VFS_TYPE_NONE] = &g_vfs_none,
[VFS_TYPE_ROOT] = &g_vfs_root,
[VFS_TYPE_FS] = &g_vfs_fs,
#if USE_VFS_SAVE
[VFS_TYPE_SAVE] = &g_vfs_save,
#endif
#if USE_VFS_STORAGE
[VFS_TYPE_STORAGE] = &g_vfs_storage,
#endif
#if USE_VFS_GC
[VFS_TYPE_GC] = &g_vfs_gc,
#if USE_USBHSFS
#endif
#if USE_VFS_USBHSFS
[VFS_TYPE_STDIO] = &g_vfs_stdio,
[VFS_TYPE_HDD] = &g_vfs_hdd,
#endif
Expand Down Expand Up @@ -299,8 +305,10 @@ void vfs_nx_init(bool enable_devices, bool save_writable, bool mount_bis) {
}

// bis storage
#if USE_VFS_STORAGE
vfs_storage_init();
vfs_nx_add_device("bis", VFS_TYPE_STORAGE);
#endif

// bis fs
if (mount_bis) {
Expand Down Expand Up @@ -351,13 +359,18 @@ void vfs_nx_init(bool enable_devices, bool save_writable, bool mount_bis) {
}
}

#if USE_VFS_GC
if (R_SUCCEEDED(vfs_gc_init())) {
vfs_nx_add_device("gc", VFS_TYPE_GC);
}
#endif

#if USE_VFS_SAVE
vfs_save_init(save_writable);
vfs_nx_add_device("save", VFS_TYPE_SAVE);
#if USE_USBHSFS
#endif

#if USE_VFS_USBHSFS
if (R_SUCCEEDED(romfsMountFromCurrentProcess("romfs"))) {
vfs_nx_add_device("romfs", VFS_TYPE_STDIO);
}
Expand Down Expand Up @@ -388,11 +401,17 @@ void vfs_nx_init(bool enable_devices, bool save_writable, bool mount_bis) {

void vfs_nx_exit(void) {
if (g_enabled_devices) {
#if USE_VFS_GC
vfs_gc_exit();
#endif
#if USE_VFS_STORAGE
vfs_storage_exit();
#endif
#if USE_VFS_SAVE
vfs_save_exit();
#endif
vfs_root_exit();
#if USE_USBHSFS
#if USE_VFS_USBHSFS
romfsUnmount("romfs_qlaunch");
romfsUnmount("romfs");
vfs_hdd_exit();
Expand Down
Loading

0 comments on commit a8ac234

Please sign in to comment.