Bazel rules for building and running Playdate applications in Swift and C.
Caution
This is all very much a work in progress. Things will break and change over time but it'll be fun.
See the examples directory for the latest tested examples on using the rules.
Bazel release | Min. rules version | Final rules version |
---|---|---|
7.0.0 | current | current |
macOS | Linux | Windows | |
---|---|---|---|
Supported platform | ✅ | ❌ | ❌ |
Swift | C | Lua | |
---|---|---|---|
Supported language | ✅ | ✅ | ❌ |
rules_playdate
provides a set of Bazel rules and toolchains for building Playdate applications.
-
Download the Playdate SDK. You can download the SDK from the play.date/dev site.
-
Depend on the required rules to build your Playdate application, the following example uses macOS as the development platform. See the release notes for a snippet on adding
rules_playdate
as a dependency. -
Create the targets in a
BUILD.bazel
:load("@rules_apple//apple:macos.bzl", "macos_dylib") load("@rules_playdate//playdate:playdate.bzl", "playdate_application") load("@rules_swift//swift:swift.bzl", "swift_library") # Define a Swift library which contains your application's code. swift_library( name = "MyApp.swift_lib", srcs = ["MyApp.swift"], deps = [ ... ], ) # Define a dylib target to package the `swift_library` as a dynamic library. macos_dylib( name = "MyApp_macos_lib", deps = [":MyApp.swift_lib"], minimum_os_version = "14.0", ) # Define a Playdate application playdate_application( name = "MyApp", library = ":MyApp_macos_lib", )
-
You can build the Playdate application:
bazel build //path/to:MyApp
-
You can run the Playdate application in the Playdate Simulator:
bazel run //path/to:MyApp
This project is mostly focused on providing build rules for the Playdate and not any additional APIs around the SDK. However, there are some simple Swift and C libraries which wrap the Playdate SDK API to make it easier to get started. You may use these libraries or use the Playdate SDK directly.
See the @rules_playdate//playdate/lib targets for more information. For any information on the Playdate SDK, please refer to the Playdate SDK documentation.
Swift playdate support is pretty experimental as building with Swift for embedded platforms is not supported in any official release yet. You will need to use a development version of the Swift toolchain that supports building for embedded platforms. The best starting point to learn more are the examples here and the Byte-sized Swift: Building Tiny Games for the Playdate blog post.
load("@rules_swift//swift:swift.bzl", "swift_library")
swift_library(
name = "MyApp.swift_lib",
srcs = ["MyApp.swift"],
deps = ["@rules_playdate//playdate/lib/swift:playdate"],
)
import Playdate
let displayAPI = playdateAPI.display.unsafelyUnwrapped.pointee
For C libraries, you may use the C API directly from the Playdate SDK. It is defined as a cc_library
target via the playdate_sdk
module extension.
load("@rules_cc//cc:defs.bzl", "cc_library")
cc_library(
name = "MyApp.c_lib",
srcs = ["MyApp.c"],
deps = ["@playdate_sdk//:pd_api"],
# You may also use a thin wrapper around the C API with:
# deps = ["@rules_playdate//playdate/lib/c:playdate"],
)
// in MyApp.h
#include "pd_api.h"
// or #include "cplaydate.h" if using the wrapper