Skip to content

Commit

Permalink
Implement pdn (samdze#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nycto committed Feb 13, 2025
1 parent 6b07aaf commit 97b685d
Show file tree
Hide file tree
Showing 16 changed files with 350 additions and 233 deletions.
8 changes: 7 additions & 1 deletion .github/actions/build-setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ runs:
- run: nimble --accept refresh
shell: bash

- run: nimble install
- run: nimble install --verbose
shell: bash

- run: echo "/github/home/.nimble/bin" >> $GITHUB_PATH
shell: bash

- run: which pdn
shell: bash

- name: Locally publish playdate nimble package
Expand Down
5 changes: 0 additions & 5 deletions .github/actions/project-setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ runs:
using: "composite"
steps:

- name: Nimble example setup
shell: bash
working-directory: ${{ inputs.working-directory }}
run: nimble configure;

- name: Install dependencies
shell: bash
working-directory: ${{ inputs.working-directory }}
Expand Down
13 changes: 5 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
- uses: ./.github/actions/project-setup
with:
working-directory: ./playdate_example
- run: nimble simulator
- run: pdn simulator
working-directory: ./playdate_example

example-project:
strategy:
matrix:
Expand All @@ -30,7 +30,7 @@ jobs:
- uses: ./.github/actions/project-setup
with:
working-directory: ./playdate_example
- run: nimble ${{ matrix.target }}
- run: pdn ${{ matrix.target }}
working-directory: ./playdate_example

tests:
Expand Down Expand Up @@ -77,10 +77,7 @@ jobs:
pulseaudio -D --exit-idle-time=-1
pactl load-module module-null-sink sink_name=SpeakerOutput sink_properties=device.description="Dummy_Output"
- run: echo 'switch("d", "${{ matrix.build-flags }}")' >> configs.nims
working-directory: ./tests

- run: nimble simulator
- run: pdn simulator -d:${{ matrix.build-flags }}
working-directory: ./tests

# The first time the simulator runs, it prompts the user with an alert. Obviously, we're running headless,
Expand All @@ -99,4 +96,4 @@ jobs:
working-directory: ./tests
run: |
export HOME="/config"
xvfb-run ../PlaydateSDK-*/bin/PlaydateSimulator tests.pdx
xvfb-run ../PlaydateSDK-*/bin/PlaydateSimulator playdate_tests.pdx
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ htmldocs/
src/tests/
pdex.bin
*.pdx
tests/source/pdxinfo

# macOS general
.DS_Store
Expand Down Expand Up @@ -58,4 +59,9 @@ tests/t_*
tests/playdate_tests

# IntelliJ IDEA
.idea
.idea
nimble.develop
nimble.paths

# Binaries
pdn
4 changes: 4 additions & 0 deletions config.nims
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# begin Nimble config (version 2)
when withDir(thisDir(), system.fileExists("nimble.paths")):
include "nimble.paths"
# end Nimble config
4 changes: 2 additions & 2 deletions playdate.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ author = "Samuele Zolfanelli"
description = "Playdate Nim bindings with extra features."
license = "MIT"
srcDir = "src"

installExt = @["nim"]
bin = @["pdn"]

# Dependencies

requires "nim >= 2.0.0"
# requires "nimble < 0.14.0"
3 changes: 3 additions & 0 deletions playdate_example/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
*.pdx
source/pdex.*
*.dSYM
playdate_example.pdx.zip
playdate_example.pdx
source/pdxinfo
4 changes: 0 additions & 4 deletions playdate_example/source/pdxinfo

This file was deleted.

66 changes: 66 additions & 0 deletions src/pdn.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import std/[parseopt, strutils, os, macros, options]
import playdate/build/[utils, actions]

type
BuildCommand = enum device, simulate, simulator, clean, bundle
## The various actions that can be executed by this script

CliConfig = object
## Configurations collected from the Cli
command: BuildCommand
noAutoConfig: bool
sdkPath: Option[string]
extraArgs: seq[string]

proc getCliConfig(): CliConfig =
## Parses the build configuration from the input options
for kind, key, val in getopt():
template addExtraArg() =
var command = if kind == cmdLongOption: "--" else: "-"
command &= key
if val != "":
command &= ":" & val
result.extraArgs.add(command)

case kind
of cmdArgument:
result.command = parseEnum[BuildCommand](key)
of cmdLongOption, cmdShortOption:
case key
of "sdk-path": result.sdkPath = some(val)
of "no-auto-config": result.noAutoConfig = true
else: addExtraArg()
of cmdEnd:
discard

let build = getCliConfig()

let dump = getNimbleDump()

let conf = PlaydateConf(
dump: dump,
kind: if build.command == device: DeviceBuild else: SimulatorBuild,
sdkPath: sdkPath(build.sdkPath),
pdxName: dump.name & ".pdx",
nimbleArgs: build.extraArgs,
noAutoConfig: build.noAutoConfig
)

case build.command
of device, simulate, simulator:
conf.configureBuild()
of clean, bundle:
discard

case build.command
of simulator:
conf.simulatorBuild()
of simulate:
conf.simulatorBuild()
conf.runSimulator()
of device:
conf.deviceBuild()
of clean:
conf.runClean()
of bundle:
conf.bundlePDX()
6 changes: 5 additions & 1 deletion src/playdate/bindings/malloc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

{.push stackTrace: off.}

import ../util/initreqs
when (compiles do:
import playdate/util/initreqs):
import playdate/util/initreqs
else:
import ../util/initreqs

when defined(memProfiler):

Expand Down
Loading

0 comments on commit 97b685d

Please sign in to comment.