Skip to content

Commit a8ac234

Browse files
committed
[Nx] allow for per vfs build options, add switch workflow.
1 parent 888893f commit a8ac234

File tree

9 files changed

+202
-76
lines changed

9 files changed

+202
-76
lines changed

.github/workflows/build_switch.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: build_switch
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
9+
jobs:
10+
build:
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
os: [ubuntu-latest]
15+
preset: [switch]
16+
runs-on: ${{ matrix.os }}
17+
container: devkitpro/devkita64:latest
18+
19+
steps:
20+
- uses: actions/checkout@v3
21+
22+
# fetch latest cmake
23+
- uses: lukka/get-cmake@latest
24+
25+
- name: Configure CMake
26+
# disable ftp-gc until dkpa64 container uses latest libnx
27+
run: |
28+
cmake --preset ${{ matrix.preset }} -DUSE_VFS_GC=0
29+
30+
- name: Build
31+
run: cmake --build --preset ${{ matrix.preset }} --parallel 4

CMakeLists.txt

Lines changed: 108 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -216,96 +216,130 @@ if (FTPSRV_LIB_BUILD)
216216
)
217217
else()
218218
if (NINTENDO_SWITCH)
219+
if (NOT DEFINED USE_VFS_SAVE)
220+
set(USE_VFS_SAVE TRUE)
221+
endif()
222+
if (NOT DEFINED USE_VFS_STORAGE)
223+
set(USE_VFS_STORAGE TRUE)
224+
endif()
225+
if (NOT DEFINED USE_VFS_GC)
226+
set(USE_VFS_GC TRUE)
227+
endif()
228+
if (NOT DEFINED USE_VFS_USBHSFS)
229+
set(USE_VFS_USBHSFS TRUE)
230+
endif()
231+
219232
ftp_set_options(ftpsrv 769 128 1024*64)
220233
fetch_minini()
221234

222-
set(USBHSFS_GPL ON)
223-
FetchContent_Declare(libusbhsfs
224-
GIT_REPOSITORY https://github.com/DarkMatterCore/libusbhsfs.git
225-
GIT_TAG v0.2.9
235+
set(NX_SRC
236+
src/platform/nx/vfs_nx.c
237+
src/platform/nx/vfs/vfs_nx_none.c
238+
src/platform/nx/vfs/vfs_nx_root.c
239+
src/platform/nx/vfs/vfs_nx_fs.c
240+
src/platform/nx/reboot_to_payload/ams_bpc.c
241+
src/platform/nx/reboot_to_payload/reboot_to_payload.c
242+
src/platform/nx/rtc/max77620-rtc.c
243+
src/platform/nx/custom_commands.c
244+
src/platform/nx/utils.c
245+
src/log/log.c
226246
)
227247

228-
FetchContent_MakeAvailable(libusbhsfs)
229-
add_library(libusbhsfs
230-
${libusbhsfs_SOURCE_DIR}/source/usbhsfs_drive.c
231-
${libusbhsfs_SOURCE_DIR}/source/usbhsfs_log.c
232-
${libusbhsfs_SOURCE_DIR}/source/usbhsfs_manager.c
233-
${libusbhsfs_SOURCE_DIR}/source/usbhsfs_mount.c
234-
${libusbhsfs_SOURCE_DIR}/source/usbhsfs_request.c
235-
${libusbhsfs_SOURCE_DIR}/source/usbhsfs_scsi.c
236-
${libusbhsfs_SOURCE_DIR}/source/usbhsfs_utils.c
248+
target_compile_definitions(ftpsrv PUBLIC
249+
FTP_VFS_HEADER="${CMAKE_CURRENT_SOURCE_DIR}/src/platform/nx/vfs_nx.h"
250+
FTP_SOCKET_HEADER="${CMAKE_CURRENT_SOURCE_DIR}/src/platform/unistd/socket_unistd.h"
251+
VFS_NX_BUFFER_WRITES=1
237252
)
238253

239-
target_include_directories(libusbhsfs PUBLIC ${libusbhsfs_SOURCE_DIR}/include)
254+
if (USE_VFS_SAVE)
255+
list(APPEND NX_SRC src/platform/nx/vfs/vfs_nx_save.c)
256+
endif()
257+
if (USE_VFS_STORAGE)
258+
list(APPEND NX_SRC src/platform/nx/vfs/vfs_nx_storage.c)
259+
endif()
260+
if (USE_VFS_GC)
261+
list(APPEND NX_SRC src/platform/nx/vfs/vfs_nx_gc.c)
262+
endif()
240263

241-
# fatfs stuff
242-
target_sources(libusbhsfs PRIVATE
243-
${libusbhsfs_SOURCE_DIR}/source/fatfs/diskio.c
244-
${libusbhsfs_SOURCE_DIR}/source/fatfs/ff_dev.c
245-
${libusbhsfs_SOURCE_DIR}/source/fatfs/ff.c
246-
${libusbhsfs_SOURCE_DIR}/source/fatfs/ffsystem.c
247-
${libusbhsfs_SOURCE_DIR}/source/fatfs/ffunicode.c
264+
add_executable(ftpexe
265+
src/platform/nx/main.c
266+
${NX_SRC}
248267
)
249268

250-
# sxos stuff
251-
target_sources(libusbhsfs PRIVATE
252-
${libusbhsfs_SOURCE_DIR}/source/sxos/usbfs_dev.c
253-
${libusbhsfs_SOURCE_DIR}/source/sxos/usbfs.c
269+
target_compile_definitions(ftpexe PUBLIC
270+
USE_VFS_SAVE=$<BOOL:${USE_VFS_SAVE}>
271+
USE_VFS_STORAGE=$<BOOL:${USE_VFS_STORAGE}>
272+
USE_VFS_GC=$<BOOL:${USE_VFS_GC}>
273+
USE_VFS_USBHSFS=$<BOOL:${USE_VFS_USBHSFS}>
254274
)
255275

256-
if (USBHSFS_GPL)
276+
if (USE_VFS_USBHSFS)
277+
set(USBHSFS_GPL ON)
278+
FetchContent_Declare(libusbhsfs
279+
GIT_REPOSITORY https://github.com/DarkMatterCore/libusbhsfs.git
280+
GIT_TAG v0.2.9
281+
)
282+
283+
FetchContent_MakeAvailable(libusbhsfs)
284+
add_library(libusbhsfs
285+
${libusbhsfs_SOURCE_DIR}/source/usbhsfs_drive.c
286+
${libusbhsfs_SOURCE_DIR}/source/usbhsfs_log.c
287+
${libusbhsfs_SOURCE_DIR}/source/usbhsfs_manager.c
288+
${libusbhsfs_SOURCE_DIR}/source/usbhsfs_mount.c
289+
${libusbhsfs_SOURCE_DIR}/source/usbhsfs_request.c
290+
${libusbhsfs_SOURCE_DIR}/source/usbhsfs_scsi.c
291+
${libusbhsfs_SOURCE_DIR}/source/usbhsfs_utils.c
292+
)
293+
294+
target_include_directories(libusbhsfs PUBLIC ${libusbhsfs_SOURCE_DIR}/include)
295+
296+
# fatfs stuff
257297
target_sources(libusbhsfs PRIVATE
258-
${libusbhsfs_SOURCE_DIR}/source/lwext4/ext_dev.c
259-
${libusbhsfs_SOURCE_DIR}/source/lwext4/ext_disk_io.c
260-
${libusbhsfs_SOURCE_DIR}/source/lwext4/ext.c
298+
${libusbhsfs_SOURCE_DIR}/source/fatfs/diskio.c
299+
${libusbhsfs_SOURCE_DIR}/source/fatfs/ff_dev.c
300+
${libusbhsfs_SOURCE_DIR}/source/fatfs/ff.c
301+
${libusbhsfs_SOURCE_DIR}/source/fatfs/ffsystem.c
302+
${libusbhsfs_SOURCE_DIR}/source/fatfs/ffunicode.c
303+
)
261304

262-
${libusbhsfs_SOURCE_DIR}/source/ntfs-3g/ntfs_dev.c
263-
${libusbhsfs_SOURCE_DIR}/source/ntfs-3g/ntfs_disk_io.c
264-
${libusbhsfs_SOURCE_DIR}/source/ntfs-3g/ntfs.c
305+
# sxos stuff
306+
target_sources(libusbhsfs PRIVATE
307+
${libusbhsfs_SOURCE_DIR}/source/sxos/usbfs_dev.c
308+
${libusbhsfs_SOURCE_DIR}/source/sxos/usbfs.c
265309
)
266310

267-
find_library(ntfs_3g_lib ntfs-3g REQUIRED)
268-
find_path(ntfs_3g_inc ntfs-3g REQUIRED)
311+
if (USBHSFS_GPL)
312+
target_sources(libusbhsfs PRIVATE
313+
${libusbhsfs_SOURCE_DIR}/source/lwext4/ext_dev.c
314+
${libusbhsfs_SOURCE_DIR}/source/lwext4/ext_disk_io.c
315+
${libusbhsfs_SOURCE_DIR}/source/lwext4/ext.c
269316

270-
find_library(lwext4_lib lwext4 REQUIRED)
271-
find_path(lwext4_inc ext4.h REQUIRED)
317+
${libusbhsfs_SOURCE_DIR}/source/ntfs-3g/ntfs_dev.c
318+
${libusbhsfs_SOURCE_DIR}/source/ntfs-3g/ntfs_disk_io.c
319+
${libusbhsfs_SOURCE_DIR}/source/ntfs-3g/ntfs.c
320+
)
272321

273-
target_link_libraries(libusbhsfs PRIVATE ${ntfs_3g_lib} ${lwext4_lib})
274-
target_include_directories(libusbhsfs PRIVATE ${ntfs_3g_inc} ${lwext4_inc})
275-
target_compile_definitions(libusbhsfs PRIVATE GPL_BUILD)
276-
endif()
322+
find_library(ntfs_3g_lib ntfs-3g REQUIRED)
323+
find_path(ntfs_3g_inc ntfs-3g REQUIRED)
277324

278-
target_compile_definitions(ftpsrv PUBLIC
279-
FTP_VFS_HEADER="${CMAKE_CURRENT_SOURCE_DIR}/src/platform/nx/vfs_nx.h"
280-
FTP_SOCKET_HEADER="${CMAKE_CURRENT_SOURCE_DIR}/src/platform/unistd/socket_unistd.h"
281-
VFS_NX_BUFFER_WRITES=1
282-
)
325+
find_library(lwext4_lib lwext4 REQUIRED)
326+
find_path(lwext4_inc ext4.h REQUIRED)
283327

284-
set(NX_SRC
285-
src/platform/nx/vfs_nx.c
286-
src/platform/nx/vfs/vfs_nx_none.c
287-
src/platform/nx/vfs/vfs_nx_root.c
288-
src/platform/nx/vfs/vfs_nx_fs.c
289-
src/platform/nx/vfs/vfs_nx_save.c
290-
src/platform/nx/vfs/vfs_nx_storage.c
291-
src/platform/nx/vfs/vfs_nx_gc.c
292-
src/platform/nx/utils.c
293-
src/platform/nx/reboot_to_payload/ams_bpc.c
294-
src/platform/nx/reboot_to_payload/reboot_to_payload.c
295-
src/platform/nx/rtc/max77620-rtc.c
296-
src/platform/nx/custom_commands.c
297-
src/log/log.c
298-
)
328+
target_link_libraries(libusbhsfs PRIVATE ${ntfs_3g_lib} ${lwext4_lib})
329+
target_include_directories(libusbhsfs PRIVATE ${ntfs_3g_inc} ${lwext4_inc})
330+
target_compile_definitions(libusbhsfs PRIVATE GPL_BUILD)
331+
endif()
332+
333+
target_link_libraries(ftpexe PRIVATE libusbhsfs)
334+
335+
target_sources(ftpexe PRIVATE
336+
src/platform/nx/vfs/vfs_nx_stdio.c
337+
src/platform/nx/vfs/vfs_nx_hdd.c
338+
)
339+
endif()
299340

300-
add_executable(ftpexe
301-
src/platform/nx/main.c
302-
src/platform/nx/vfs/vfs_nx_stdio.c
303-
src/platform/nx/vfs/vfs_nx_hdd.c
304-
${NX_SRC}
305-
)
306-
target_compile_definitions(ftpexe PUBLIC USE_USBHSFS=1)
307341
ftp_add(ftpexe)
308-
target_link_libraries(ftpexe PRIVATE ftpsrv minIni libusbhsfs)
342+
target_link_libraries(ftpexe PRIVATE ftpsrv minIni)
309343

310344
nx_generate_nacp(
311345
OUTPUT ftpexe.nacp
@@ -337,6 +371,12 @@ else()
337371
ftp_add(sysftp)
338372
target_link_libraries(sysftp PRIVATE ftpsrv_sysmod minIni)
339373

374+
target_compile_definitions(ftpexe PUBLIC
375+
USE_VFS_SAVE=$<BOOL:${USE_VFS_SAVE}>
376+
USE_VFS_STORAGE=$<BOOL:${USE_VFS_STORAGE}>
377+
USE_VFS_GC=$<BOOL:${USE_VFS_GC}>
378+
)
379+
340380
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/420000000000011B)
341381
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/420000000000011B/flags)
342382

src/platform/nx/vfs/vfs_nx_gc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
#include "ftpsrv_vfs.h"
7+
#include "vfs_nx_gc.h"
78
#include "log/log.h"
89
#include <errno.h>
910
#include <string.h>

src/platform/nx/vfs/vfs_nx_hdd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
#include "ftpsrv_vfs.h"
7+
#include "vfs_nx_hdd.h"
78
#include "log/log.h"
89
#include <errno.h>
910
#include <sys/stat.h>

src/platform/nx/vfs/vfs_nx_save.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
#include "ftpsrv_vfs.h"
7+
#include "vfs_nx_save.h"
78
#include "../utils.h"
89
#include "log/log.h"
910
#include <errno.h>

src/platform/nx/vfs/vfs_nx_stdio.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
#include "ftpsrv_vfs.h"
7+
#include "vfs_nx_stdio.h"
78
#include "log/log.h"
89
#include <errno.h>
910
#include <sys/stat.h>

src/platform/nx/vfs/vfs_nx_storage.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "ftpsrv_vfs.h"
2+
#include "vfs_nx_storage.h"
23
#include "log/log.h"
34
#include <errno.h>
45
#include <string.h>

src/platform/nx/vfs_nx.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,16 @@ static const FtpVfs* g_vfs[] = {
2626
[VFS_TYPE_NONE] = &g_vfs_none,
2727
[VFS_TYPE_ROOT] = &g_vfs_root,
2828
[VFS_TYPE_FS] = &g_vfs_fs,
29+
#if USE_VFS_SAVE
2930
[VFS_TYPE_SAVE] = &g_vfs_save,
31+
#endif
32+
#if USE_VFS_STORAGE
3033
[VFS_TYPE_STORAGE] = &g_vfs_storage,
34+
#endif
35+
#if USE_VFS_GC
3136
[VFS_TYPE_GC] = &g_vfs_gc,
32-
#if USE_USBHSFS
37+
#endif
38+
#if USE_VFS_USBHSFS
3339
[VFS_TYPE_STDIO] = &g_vfs_stdio,
3440
[VFS_TYPE_HDD] = &g_vfs_hdd,
3541
#endif
@@ -299,8 +305,10 @@ void vfs_nx_init(bool enable_devices, bool save_writable, bool mount_bis) {
299305
}
300306

301307
// bis storage
308+
#if USE_VFS_STORAGE
302309
vfs_storage_init();
303310
vfs_nx_add_device("bis", VFS_TYPE_STORAGE);
311+
#endif
304312

305313
// bis fs
306314
if (mount_bis) {
@@ -351,13 +359,18 @@ void vfs_nx_init(bool enable_devices, bool save_writable, bool mount_bis) {
351359
}
352360
}
353361

362+
#if USE_VFS_GC
354363
if (R_SUCCEEDED(vfs_gc_init())) {
355364
vfs_nx_add_device("gc", VFS_TYPE_GC);
356365
}
366+
#endif
357367

368+
#if USE_VFS_SAVE
358369
vfs_save_init(save_writable);
359370
vfs_nx_add_device("save", VFS_TYPE_SAVE);
360-
#if USE_USBHSFS
371+
#endif
372+
373+
#if USE_VFS_USBHSFS
361374
if (R_SUCCEEDED(romfsMountFromCurrentProcess("romfs"))) {
362375
vfs_nx_add_device("romfs", VFS_TYPE_STDIO);
363376
}
@@ -388,11 +401,17 @@ void vfs_nx_init(bool enable_devices, bool save_writable, bool mount_bis) {
388401

389402
void vfs_nx_exit(void) {
390403
if (g_enabled_devices) {
404+
#if USE_VFS_GC
391405
vfs_gc_exit();
406+
#endif
407+
#if USE_VFS_STORAGE
392408
vfs_storage_exit();
409+
#endif
410+
#if USE_VFS_SAVE
393411
vfs_save_exit();
412+
#endif
394413
vfs_root_exit();
395-
#if USE_USBHSFS
414+
#if USE_VFS_USBHSFS
396415
romfsUnmount("romfs_qlaunch");
397416
romfsUnmount("romfs");
398417
vfs_hdd_exit();

0 commit comments

Comments
 (0)