zig pebble sdk boilerplate

This commit is contained in:
Fabien Freling 2026-04-13 16:58:18 +02:00
commit efa5ebc43f
6 changed files with 150 additions and 0 deletions

21
build.zig Normal file
View file

@ -0,0 +1,21 @@
const std = @import("std");
const pebble_sdk = @import("pebble_sdk");
pub fn build(b: *std.Build) !void {
pebble_sdk.addPebbleApplication(b, .{
.name = "watchface_example",
.pebble = .{
.displayName = "Watchface Example",
.author = "Example",
.uuid = "547e02ad-00f0-46ab-b65c-55f42aefd29d",
.version = .{ .major = 1, .minor = 0 },
.targetPlatforms = &.{ .emery },
.watchapp = .{
.watchface = true,
},
},
.root_source_file = b.path("src/main.zig"),
.optimize = .ReleaseSmall,
});
}

13
build.zig.zon Normal file
View file

@ -0,0 +1,13 @@
.{
.name = .pebble,
.version = "0.0.1",
.dependencies = .{
.pebble_sdk = .{
.url = "git+https://github.com/vsergeev/zig-pebble-sdk?ref=master#a88635b5123bf407d0ed7a1f9bee81e6040fe22e",
.hash = "pebble_sdk-1.1.1-rN96oKykAABOtEJcRfIKUFgMHuRRoysyiotg0CXpc514",
},
},
.minimum_zig_version = "0.15.2",
.paths = .{""},
.fingerprint = 0xc5dec5e53ce15cd6,
}

27
flake.lock generated Normal file
View file

@ -0,0 +1,27 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1775888245,
"narHash": "sha256-nwASzrRDD1JBEu/o8ekKYEXm/oJW6EMCzCRdrwcLe90=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "13043924aaa7375ce482ebe2494338e058282925",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

31
flake.nix Normal file
View file

@ -0,0 +1,31 @@
{
description = "Pebble";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
};
outputs =
inputs@{ nixpkgs, ... }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
in
{
formatter.${system} = pkgs.nixfmt-rfc-style;
devShell.${system} =
with pkgs;
mkShell {
nativeBuildInputs = [
just
uv
zig
nodejs
python3
];
buildInputs = [ ];
};
};
}

13
justfile Normal file
View file

@ -0,0 +1,13 @@
pebble-sdk:
uv tool install pebble-tool --no-managed-python --no-python-downloads
pebble sdk install latest
[default]
build:
zig build
test:
PEBBLE_EMULATOR=emery zig build upload
alias b := build
alias t := test

45
src/main.zig Normal file
View file

@ -0,0 +1,45 @@
const std = @import("std");
const pebble = @import("pebble");
var s_window: ?*pebble.Window = null;
var s_text_layer: ?*pebble.TextLayer = null;
fn window_load(window: ?*pebble.Window) callconv(.c) void {
const window_layer = pebble.window_get_root_layer(window);
const bounds = pebble.layer_get_bounds(window_layer);
s_text_layer = pebble.text_layer_create(.{
.origin = .{ .x = 0, .y = @divTrunc(bounds.size.h, 2) - 25 },
.size = .{ .w = bounds.size.w, .h = 50 },
});
pebble.text_layer_set_font(s_text_layer, pebble.fonts_get_system_font(pebble.FONT_KEY_GOTHIC_28_BOLD));
pebble.text_layer_set_text_color(s_text_layer, pebble.GColorBlue);
pebble.text_layer_set_text_alignment(s_text_layer, pebble.GTextAlignmentCenter);
pebble.text_layer_set_text(s_text_layer, "Hello World!");
pebble.layer_add_child(window_layer, pebble.text_layer_get_layer(s_text_layer));
}
fn window_unload(_: ?*pebble.Window) callconv(.c) void {
pebble.text_layer_destroy(s_text_layer);
}
fn init() void {
s_window = pebble.window_create();
pebble.window_set_window_handlers(s_window, .{
.load = window_load,
.unload = window_unload,
});
pebble.window_stack_push(s_window, true);
}
fn deinit() void {
pebble.window_destroy(s_window);
}
export fn main() void {
init();
pebble.app_event_loop();
deinit();
}