Skip to content

Commit

Permalink
Clean nimble and CMake configs, make incremental builds work reliably
Browse files Browse the repository at this point in the history
  • Loading branch information
samdze authored Jul 31, 2023
1 parent c553bdf commit 7edd981
Show file tree
Hide file tree
Showing 18 changed files with 102 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,4 @@ jobs:
- name: Run headless test
working-directory: ./tests
run: xvfb-run ../PlaydateSDK-*/bin/PlaydateSimulator playdate_tests.pdx
run: xvfb-run ../PlaydateSDK-*/bin/PlaydateSimulator playdate.pdx
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ This package is an independent bindings library, not affiliated with Panic.
You can quickly start using the bindings opening the `playdate_example` project included in this repository.<br>
If you want to start from scratch, here are the steps to follow:

1. If you haven't run it already, start by initializing your nimble package and follow the instructions:
1. If you haven't done it already, start creating a folder (snake_case) and initializing your nimble package inside it running:

```
nimble init
```
Choose `binary` as the package type.

2. Install the `playdate` package:

```
nimble install playdate
```

3. Move into your package directory.<br>
Add the `playdate` package as a dependency and configure the build tasks by running the following:
3. Add the `playdate` package as a dependency and configure the build tasks by running the following:

```
echo 'requires "playdate"' >> *.nimble;
Expand Down Expand Up @@ -111,6 +111,11 @@ For simulator + device (pdx):
nimble all
```

You can also build for simulator and launch it in one command:
```sh
nimble simulate
```

The example project `playdate_example` also contains VSCode launch configurations to build, start and debug your Nim application from the editor.

Each project also contains a simple CMakeLists.txt as a starting point in case you'd want to add libraries or other external code.
Expand Down
2 changes: 1 addition & 1 deletion playdate.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.9.0"
version = "0.9.3"
author = "Samuele Zolfanelli"
description = "Playdate Nim bindings with extra features."
license = "MIT"
Expand Down
6 changes: 3 additions & 3 deletions playdate_example/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"name": "Debug PDX",
"program": "${env:PLAYDATE_SDK_PATH}/bin/Playdate Simulator",
"args": [
"${workspaceFolder}/playdate_example.pdx"
"${workspaceFolder}/playdate.pdx"
],
"cwd": "${workspaceFolder}",
"osx": {
Expand All @@ -33,7 +33,7 @@
"program": "${env:PLAYDATE_SDK_PATH}/bin/Playdate Simulator",
"preLaunchTask": "Build Universal PDX",
"args": [
"${workspaceFolder}/playdate_example.pdx"
"${workspaceFolder}/playdate.pdx"
],
"cwd": "${workspaceFolder}",
"osx": {
Expand All @@ -56,7 +56,7 @@
"program": "${env:PLAYDATE_SDK_PATH}/bin/Playdate Simulator",
"preLaunchTask": "Build Simulator PDX",
"args": [
"${workspaceFolder}/playdate_example.pdx"
"${workspaceFolder}/playdate.pdx"
],
"cwd": "${workspaceFolder}",
"osx": {
Expand Down
7 changes: 6 additions & 1 deletion playdate_example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# $ENV{PLAYDATE_PROJECT_NAME}: the project name
# $ENV{PLAYDATE_MODULE_DIR}: the path to the installed playdate Nim module
# $ENV{NIM_CACHE_DIR}: the path to the project Nim cache files
# $ENV{NIM_C_SOURCE_FILES}: list of semicolon-separated, Nim-generated C files that have to be compiled
# $ENV{NIM_INCLUDE_DIR}: the path to required Nim header files

cmake_minimum_required(VERSION 3.14)
Expand All @@ -15,4 +16,8 @@ set(CMAKE_C_STANDARD 11)
project($ENV{PLAYDATE_PROJECT_NAME} C ASM)

# Include the playdate module CMake configuration
include($ENV{PLAYDATE_MODULE_DIR}/playdate.cmake)
include($ENV{PLAYDATE_MODULE_DIR}/playdate.cmake)

# Targets:
# ${PLAYDATE_GAME_NAME}: simulator
# ${PLAYDATE_GAME_DEVICE}: device
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 7 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# $ENV{PLAYDATE_PROJECT_NAME}: the project name
# $ENV{PLAYDATE_MODULE_DIR}: the path to the installed playdate Nim module
# $ENV{NIM_CACHE_DIR}: the path to the project Nim cache files
# $ENV{NIM_C_SOURCE_FILES}: list of semicolon-separated, Nim-generated C files that have to be compiled
# $ENV{NIM_INCLUDE_DIR}: the path to required Nim header files

cmake_minimum_required(VERSION 3.14)
Expand All @@ -14,5 +15,9 @@ set(CMAKE_C_STANDARD 11)
# Setup the project and its name from the environment
project($ENV{PLAYDATE_PROJECT_NAME} C ASM)

# Include the playdate module CMake configuration
include($ENV{PLAYDATE_MODULE_DIR}/playdate.cmake)
# Include the playdate module CMake configuration, this defines the targets
include($ENV{PLAYDATE_MODULE_DIR}/playdate.cmake)

# Targets:
# ${PLAYDATE_GAME_NAME}: simulator
# ${PLAYDATE_GAME_DEVICE}: device
56 changes: 21 additions & 35 deletions src/playdate.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,18 @@ endif()
set(CMAKE_CONFIGURATION_TYPES "Debug;Release")
set(CMAKE_XCODE_GENERATE_SCHEME TRUE)

file(GLOB nim_source_files "$ENV{NIM_CACHE_DIR}/*.c")

# Game Name Customization
set(PLAYDATE_GAME_NAME $ENV{PLAYDATE_PROJECT_NAME})
set(PLAYDATE_GAME_DEVICE $ENV{PLAYDATE_PROJECT_NAME})
set(PLAYDATE_GAME_NAME $ENV{PLAYDATE_PROJECT_NAME}_simulator)
set(PLAYDATE_GAME_DEVICE $ENV{PLAYDATE_PROJECT_NAME}_device)

# Include Nim required headers
include_directories($ENV{NIM_INCLUDE_DIR})

if (TOOLCHAIN STREQUAL "armgcc")
add_executable(${PLAYDATE_GAME_DEVICE} ${nim_source_files})
add_executable(${PLAYDATE_GAME_DEVICE} $ENV{NIM_C_SOURCE_FILES})
target_link_libraries(${PLAYDATE_GAME_DEVICE} rdimon c m gcc nosys)
else()
add_library(${PLAYDATE_GAME_NAME} SHARED ${nim_source_files})
add_library(${PLAYDATE_GAME_NAME} SHARED $ENV{NIM_C_SOURCE_FILES})
endif()

include(${SDK}/C_API/buildsupport/playdate.cmake)
Expand All @@ -51,67 +49,55 @@ if (TOOLCHAIN STREQUAL "armgcc")
TARGET ${PLAYDATE_GAME_DEVICE} POST_BUILD
COMMAND ${CMAKE_STRIP} --strip-unneeded -R .comment -g
${PLAYDATE_GAME_DEVICE}.elf
-o ${CMAKE_CURRENT_SOURCE_DIR}/Source/pdex.elf
-o ${CMAKE_CURRENT_SOURCE_DIR}/source/pdex.elf
)

add_custom_command(
TARGET ${PLAYDATE_GAME_DEVICE} POST_BUILD
COMMAND ${PDC} Source ${PLAYDATE_GAME_NAME}.pdx
COMMAND ${PDC} source playdate.pdx
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

set_property(
TARGET ${PLAYDATE_GAME_DEVICE} PROPERTY ADDITIONAL_CLEAN_FILES
${CMAKE_CURRENT_SOURCE_DIR}/${PLAYDATE_GAME_NAME}.pdx
${CMAKE_CURRENT_SOURCE_DIR}/playdate.pdx
)

else ()

if (MSVC)
# MSVC not supported
message(FATAL_ERROR "MSVC is not supported! Use MinGW.")

elseif(MINGW)
target_compile_definitions(${PLAYDATE_GAME_NAME} PUBLIC _WINDLL=1)
add_custom_command(
TARGET ${PLAYDATE_GAME_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_BINARY_DIR}/lib${PLAYDATE_GAME_NAME}.dll
${CMAKE_CURRENT_SOURCE_DIR}/Source/pdex.dll)
set(DYLIB_EXT "dll")

elseif(APPLE)
target_sources(${PLAYDATE_GAME_NAME} PRIVATE ${SDK}/C_API/buildsupport/setup.c)
if(${CMAKE_GENERATOR} MATCHES "Xcode" )
set(BUILD_SUB_DIR $<CONFIG>/)
set_property(TARGET ${PLAYDATE_GAME_NAME} PROPERTY XCODE_SCHEME_ARGUMENTS \"${CMAKE_CURRENT_SOURCE_DIR}/${PLAYDATE_GAME_NAME}.pdx\")
set_property(TARGET ${PLAYDATE_GAME_NAME} PROPERTY XCODE_SCHEME_EXECUTABLE ${SDK}/bin/Playdate\ Simulator.app)
endif()

add_custom_command(
TARGET ${PLAYDATE_GAME_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_BINARY_DIR}/${BUILD_SUB_DIR}lib${PLAYDATE_GAME_NAME}.dylib
${CMAKE_CURRENT_SOURCE_DIR}/Source/pdex.dylib)
set(DYLIB_EXT "dylib")

elseif(UNIX)
target_sources(${PLAYDATE_GAME_NAME} PRIVATE ${SDK}/C_API/buildsupport/setup.c)
add_custom_command(
TARGET ${PLAYDATE_GAME_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_BINARY_DIR}/lib${PLAYDATE_GAME_NAME}.so
${CMAKE_CURRENT_SOURCE_DIR}/Source/pdex.so)
set(DYLIB_EXT "so")

else()
message(FATAL_ERROR "Platform not supported!")
endif()

add_custom_command(
TARGET ${PLAYDATE_GAME_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_BINARY_DIR}/${BUILD_SUB_DIR}lib${PLAYDATE_GAME_NAME}.${DYLIB_EXT}
${CMAKE_CURRENT_SOURCE_DIR}/source/pdex.${DYLIB_EXT})

set_property(
TARGET ${PLAYDATE_GAME_NAME} PROPERTY ADDITIONAL_CLEAN_FILES
${CMAKE_CURRENT_SOURCE_DIR}/${PLAYDATE_GAME_NAME}.pdx
${CMAKE_CURRENT_SOURCE_DIR}/playdate.pdx
)

add_custom_command(
TARGET ${PLAYDATE_GAME_NAME} POST_BUILD
COMMAND ${PDC} ${CMAKE_CURRENT_SOURCE_DIR}/Source
${CMAKE_CURRENT_SOURCE_DIR}/${PLAYDATE_GAME_NAME}.pdx)
COMMAND ${PDC} ${CMAKE_CURRENT_SOURCE_DIR}/source
${CMAKE_CURRENT_SOURCE_DIR}/playdate.pdx)

endif ()
1 change: 1 addition & 0 deletions src/playdate/build/config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ when defined(simulator):
switch("checks", "on")
switch("index", "on")
switch("debuginfo", "on")
switch("stackTrace", "on")
switch("lineTrace", "on")
switch("lineDir", "on")
switch("debugger", "native")
Expand Down
Loading

0 comments on commit 7edd981

Please sign in to comment.