Skip to content

Commit 636461e

Browse files
committed
Build using swiftpm
1 parent e7aa576 commit 636461e

File tree

5 files changed

+52
-1
lines changed

5 files changed

+52
-1
lines changed

Examples/Pong/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.PHONY: build
2+
build: build_simulator
3+
4+
.PHONY: build_simulator
5+
build_simulator:
6+
swift build --toolset toolset.json
7+
8+
.PHONY: clean
9+
clean:
10+
swift package clean
11+
rm -rf .build

Examples/Pong/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let playdateSDKPath: String = if let path = Context.environment["PLAYDATE_SDK_PA
1515
let package = Package(
1616
name: "Pong",
1717
platforms: [.macOS(.v14)],
18-
products: [.library(name: "Pong", targets: ["Pong"])],
18+
products: [.library(name: "Pong", type: .dynamic, targets: ["Pong"])],
1919
dependencies: [
2020
.package(path: "../.."),
2121
],

Examples/Pong/pdex.dylib

739 KB
Binary file not shown.

Examples/Pong/toolset.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"schemaVersion": "1.0",
3+
"linker": {
4+
"extraCLIOptions": [
5+
"-dead_strip",
6+
"-allow_dead_duplicates",
7+
"-lc", "-lm"
8+
]
9+
}
10+
}

Sources/CPlaydate/setup.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
#include "pd_api.h"
3+
4+
typedef int (PDEventHandler)(PlaydateAPI* playdate, PDSystemEvent event, uint32_t arg);
5+
6+
extern PDEventHandler eventHandler;
7+
8+
static void* (*pdrealloc)(void* ptr, size_t size);
9+
10+
int eventHandlerShim(PlaydateAPI* playdate, PDSystemEvent event, uint32_t arg)
11+
{
12+
if ( event == kEventInit )
13+
pdrealloc = playdate->system->realloc;
14+
15+
return eventHandler(playdate, event, arg);
16+
}
17+
18+
#if TARGET_PLAYDATE
19+
20+
void* _malloc_r(struct _reent* _REENT, size_t nbytes) { return pdrealloc(NULL,nbytes); }
21+
void* _realloc_r(struct _reent* _REENT, void* ptr, size_t nbytes) { return pdrealloc(ptr,nbytes); }
22+
void _free_r(struct _reent* _REENT, void* ptr ) { if ( ptr != NULL ) pdrealloc(ptr,0); }
23+
24+
#else
25+
26+
void* malloc(size_t nbytes) { return pdrealloc(NULL,nbytes); }
27+
void* realloc(void* ptr, size_t nbytes) { return pdrealloc(ptr,nbytes); }
28+
void free(void* ptr ) { if ( ptr != NULL ) pdrealloc(ptr,0); }
29+
30+
#endif

0 commit comments

Comments
 (0)