Skip to content

Commit

Permalink
Move to a 100% Nim build system
Browse files Browse the repository at this point in the history
  • Loading branch information
samdze authored Aug 3, 2023
1 parent 7edd981 commit 9de0d4e
Show file tree
Hide file tree
Showing 16 changed files with 357 additions and 322 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ jobs:
- name: Update dependencies
run: apt-get update
- name: Install dependencies
run: apt-get install -y make libpng16-16 gcc-arm-none-eabi
- name: Setup CMake
uses: lukka/get-cmake@latest
run: apt-get install -y libpng16-16 gcc-arm-none-eabi
- uses: actions/checkout@v1
- name: Download playdate SDK
run: wget https://download.panic.com/playdate_sdk/Linux/PlaydateSDK-latest.tar.gz
Expand Down Expand Up @@ -59,9 +57,7 @@ jobs:
- name: Update dependencies
run: apt-get update
- name: Install dependencies
run: apt-get install -y make libpng16-16 gcc-arm-none-eabi xvfb libgtk-3-0 sudo libwebkit2gtk-4.0 libwebkit2gtk-4.0-dev libsdl2-dev pulseaudio
- name: Setup CMake
uses: lukka/get-cmake@latest
run: apt-get install -y libpng16-16 gcc-arm-none-eabi xvfb libgtk-3-0 sudo libwebkit2gtk-4.0 libwebkit2gtk-4.0-dev libsdl2-dev pulseaudio

# Because we are headless there is no audio driver to interact with by default, which causes a set
# of warnings to be emitted. This set of commands sets up a dummy audio sink that silences those warnings.
Expand Down
28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,10 @@ This package is an independent bindings library, not affiliated with Panic.
### Prerequisites

- Playdate SDK
- Nim 1.6.10+ (check with `nim -v`)
- Nim 1.6.10+ (check with `nim -v`, untested with 2.0+)
- Nimble 0.13.1 (check with `nimble -v`)
- `PLAYDATE_SDK_PATH` environment variable
- Make and CMake (3.19+)
- [SDK Prerequisites](https://sdk.play.date/Inside%20Playdate%20with%20C.html#_prerequisites) based on OS, and:
- Linux: a C compiler, `arm-none-eabi-newlib` package (naming varies based on distro).
- macOS: a C compiler. Included in Xcode Command Line Tools.
- Windows: MinGW. [Getting started](https://code.visualstudio.com/docs/cpp/config-mingw)
- [SDK Prerequisites](https://sdk.play.date/Inside%20Playdate%20with%20C.html#_prerequisites) based on OS, and [MinGW on Windows](https://code.visualstudio.com/docs/cpp/config-mingw).

### Installation

Expand Down Expand Up @@ -118,7 +114,25 @@ 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.
Each project contains a `config.nims` file that can be edited to customize how the project should be built, e.g. adding libraries or other external code.<br>
Here's an example of a `config.nims` that links a pre-built static library called chipmunk:
```nim
include playdate/build/config
# Add a search path for libraries based on OS.
if defined(device):
switch("passL", "-L" & getCurrentDir() / "lib" / "device")
elif defined(windows):
switch("passL", "-L" & getCurrentDir() / "lib" / "windows")
elif defined(macosx):
switch("passL", "-L" & getCurrentDir() / "lib" / "macos")
elif defined(linux):
switch("passL", "-L" & getCurrentDir() / "lib" / "linux")
else:
echo "Platform not supported!"
# Link the chipmunk library.
switch("passL", "-lchipmunk")
```

---
This project is perfectly usable but do note that it's still a work in progress, here's what is missing right now:
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.3"
version = "0.10.0"
author = "Samuele Zolfanelli"
description = "Playdate Nim bindings with extra features."
license = "MIT"
Expand Down
5 changes: 3 additions & 2 deletions playdate_example/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
playdate_example.pdx
Source/pdex.*
playdate.pdx
source/pdex.*
*.dSYM
23 changes: 0 additions & 23 deletions playdate_example/CMakeLists.txt

This file was deleted.

23 changes: 0 additions & 23 deletions src/CMakeLists.txt

This file was deleted.

103 changes: 0 additions & 103 deletions src/playdate.cmake

This file was deleted.

27 changes: 26 additions & 1 deletion src/playdate/api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,29 @@ macro initSDK*() =

when not defined(simulator):
proc fini() {.cdecl, exportc: "_fini".} =
discard
discard

when not defined(simulator) and defined(release):
proc close(file: cint): cint {.cdecl, exportc: "_close".} =
return -1

proc fstat(file: cint, st: pointer): cint {.cdecl, exportc: "_fstat".} =
return -1

proc getpid(): cint {.cdecl, exportc: "_getpid".} =
return 1

proc isatty(file: cint): cint {.cdecl, exportc: "_isatty".} =
return 0

proc kill(pid, sig: cint): cint {.cdecl, exportc: "_kill".} =
return 0

proc lseek(file, pos, whence: cint): cint {.cdecl, exportc: "_lseek".} =
return -1

proc read(file: cint, pt: ptr cchar, len: cint): cint {.cdecl, exportc: "_read".} =
return 0

proc write(handle: cint, data: ptr cchar, size: cint): cint {.cdecl, exportc: "_write".} =
return -1
4 changes: 2 additions & 2 deletions src/playdate/bindings/system.nim
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ sdktype:
getSecondsSinceEpoch {.importc: "getSecondsSinceEpoch".}: proc (milliseconds: ptr cuint): cuint {.cdecl, raises: [].}
drawFPS {.importsdk.}: proc (x: cint; y: cint)
setUpdateCallback {.importc: "setUpdateCallback".}: proc (update: PDCallbackFunctionRaw, userdata: pointer) {.cdecl, raises: [].}
getButtonState {.importc: "getButtonState".}: proc (current: ptr uint32;
pushed: ptr uint32; released: ptr uint32) {.cdecl, raises: [].}
getButtonState {.importc: "getButtonState".}: proc (current: ptr PDButton;
pushed: ptr PDButton; released: ptr PDButton) {.cdecl, raises: [].}
setPeripheralsEnabled* {.importc.}: proc (mask: PDPeripherals) {.cdecl, raises: [].}
getAccelerometer {.importc: "getAccelerometer".}: proc (outx: ptr cfloat;
outy: ptr cfloat; outz: ptr cfloat) {.cdecl, raises: [].}
Expand Down
Loading

0 comments on commit 9de0d4e

Please sign in to comment.