Skip to content
This repository was archived by the owner on Dec 1, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The master branch of zig is not currently supported.
Choose the command that matches your desired zig-sdl3 version and run it in your project's root directory:
* For the latest tag release:
```sh
zig fetch --save git+https://github.com/Gota7/zig-sdl3#v0.1.2
zig fetch --save git+https://github.com/Gota7/zig-sdl3#v0.1.3
```
* For in progress updates (nightly):
```sh
Expand All @@ -44,6 +44,11 @@ const sdl3 = b.dependency("sdl3", .{
// Lib options.
/// .callbacks = false,
/// .ext_image = false,
/// .ext_net = false,
/// .ext_ttf = false,
/// .log_message_stack_size = 1024,
/// .main = false,
/// .renderer_debug_text_stack_size = 1024,

// Options passed directly to https://github.com/castholm/SDL (SDL3 C Bindings):
// .c_sdl_preferred_linkage = .static,
Expand Down
35 changes: 29 additions & 6 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn build(b: *std.Build) !void {
.version = .{
.major = 0,
.minor = 1,
.patch = 1,
.patch = 3,
},
};

Expand Down Expand Up @@ -73,11 +73,32 @@ pub fn build(b: *std.Build) !void {
const sdl_dep_lib = sdl_dep.artifact("SDL3");

// SDL options.
const extension_options = b.addOptions();
const options = b.addOptions();
const main_callbacks = b.option(bool, "callbacks", "Enable SDL callbacks rather than use a main function") orelse false;
extension_options.addOption(bool, "callbacks", main_callbacks);
options.addOption(bool, "callbacks", main_callbacks);
const sdl3_main = b.option(bool, "main", "Enable SDL main") orelse false;
extension_options.addOption(bool, "main", sdl3_main);
options.addOption(bool, "main", sdl3_main);
options.addOption(
usize,
"log_message_stack_size",
b.option(
usize,
"log_message_stack_size",
"Default log message stack size",
) orelse 1024,
);
options.addOption(
usize,
"renderer_debug_text_stack_size",
b.option(
usize,
"renderer_debug_text_stack_size",
"Default renderer debug text stack size",
) orelse 1024,
);

// SDL extension options.
const extension_options = b.addOptions();
const ext_image = b.option(bool, "ext_image", "Enable SDL_image extension") orelse false;
extension_options.addOption(bool, "image", ext_image);
const ext_net = b.option(bool, "ext_net", "Enable SDL_net extension") orelse false;
Expand Down Expand Up @@ -129,6 +150,7 @@ pub fn build(b: *std.Build) !void {
};

sdl3.addOptions("extension_options", extension_options);
sdl3.addOptions("options", options);
sdl3.linkLibrary(sdl_dep_lib);
if (ext_image) {
image.setup(b, sdl3, translate_c, sdl_dep_lib, c_sdl_preferred_linkage, .{
Expand All @@ -150,7 +172,7 @@ pub fn build(b: *std.Build) !void {
}

_ = setupDocs(b, sdl3);
_ = setupTest(b, cfg, extension_options, c_module);
_ = setupTest(b, cfg, extension_options, options, c_module);

_ = try setupExamples(b, sdl3, cfg, example_options);
_ = try runExample(b, sdl3, cfg, example_options);
Expand Down Expand Up @@ -238,7 +260,7 @@ pub fn setupExamples(b: *std.Build, sdl3: *std.Build.Module, cfg: Config, option
return exp;
}

pub fn setupTest(b: *std.Build, cfg: Config, extension_options: *std.Build.Step.Options, c_module: *std.Build.Module) *std.Build.Step.Compile {
pub fn setupTest(b: *std.Build, cfg: Config, extension_options: *std.Build.Step.Options, options: *std.Build.Step.Options, c_module: *std.Build.Module) *std.Build.Step.Compile {
const test_module = b.createModule(.{
.root_source_file = cfg.root_source_file,
.target = cfg.target,
Expand All @@ -252,6 +274,7 @@ pub fn setupTest(b: *std.Build, cfg: Config, extension_options: *std.Build.Step.
.root_module = test_module,
});
tst.root_module.addOptions("extension_options", extension_options);
tst.root_module.addOptions("options", options);
const sdl_dep = b.dependency("sdl", .{
.target = cfg.target,
.optimize = cfg.optimize,
Expand Down
20 changes: 10 additions & 10 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
.{
.name = .sdl3,
.version = "0.1.2",
.version = "0.1.3",
.minimum_zig_version = "0.15.1",
.dependencies = .{
.sdl = .{
.url = "git+https://github.com/castholm/SDL.git?ref=v0.3.0%2B3.2.22#b1913e7c31ad72ecfd3ab04aeac387027754cfaf",
.hash = "sdl-0.3.0+3.2.22-7uIn9Pg3fwGG2IyIOPxxOSVe-75nUng9clt7tXGFLzMr",
.url = "git+https://github.com/castholm/SDL.git?ref=v0.3.1%2B3.2.24#1d4b8dcc03bd216712b55318b4ad2402b5511490",
.hash = "sdl-0.3.1+3.2.24-7uIn9L9AfwFQf90JcTh3Slw__ZA8SEomk6fQI9F8ItY0",
},
.sdl_image = .{
.url = "git+https://github.com/libsdl-org/SDL_image?ref=release-3.2.x#59adab53b95cd553a1c77f1c7665a980e323dfdd",
Expand All @@ -32,17 +32,17 @@
},
},
.paths = .{
"build.zig",
"build.zig.zon",
"build",
"data",
"examples",
"src",
"template",
"bindings.yaml",
"build",
"generate.zig",
"build.zig",
"build.zig.zon",
"flake.lock",
"flake.nix",
"LICENSE",
"main_callbacks.c",
"README",
"README.md",
},
.fingerprint = 0x6188f62f43f56436,
}
22 changes: 10 additions & 12 deletions src/log.zig
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
const c = @import("c");
const errors = @import("errors.zig");
const options = @import("options");
const sdl3 = @import("sdl3.zig");
const std = @import("std");

/// Maximum stack size to use for a log message.
const max_log_message_stack = 1024;

/// The prototype for the log output callback function.
///
/// ## Function Parameters
Expand Down Expand Up @@ -168,7 +166,7 @@ pub const Category = enum(c_int) {
comptime fmt: []const u8,
args: anytype,
) !void {
var fallback = std.heap.stackFallback(max_log_message_stack, sdl3.allocator);
var fallback = std.heap.stackFallback(options.log_message_stack_size, sdl3.allocator);
const allocator = fallback.get();
const msg = try std.fmt.allocPrintSentinel(allocator, fmt, args, 0);
defer allocator.free(msg);
Expand Down Expand Up @@ -197,7 +195,7 @@ pub const Category = enum(c_int) {
comptime fmt: []const u8,
args: anytype,
) !void {
var fallback = std.heap.stackFallback(max_log_message_stack, sdl3.allocator);
var fallback = std.heap.stackFallback(options.log_message_stack_size, sdl3.allocator);
const allocator = fallback.get();
const msg = try std.fmt.allocPrintSentinel(allocator, fmt, args, 0);
defer allocator.free(msg);
Expand Down Expand Up @@ -225,7 +223,7 @@ pub const Category = enum(c_int) {
comptime fmt: []const u8,
args: anytype,
) !void {
var fallback = std.heap.stackFallback(max_log_message_stack, sdl3.allocator);
var fallback = std.heap.stackFallback(options.log_message_stack_size, sdl3.allocator);
const allocator = fallback.get();
const msg = try std.fmt.allocPrintSentinel(allocator, fmt, args, 0);
defer allocator.free(msg);
Expand Down Expand Up @@ -253,7 +251,7 @@ pub const Category = enum(c_int) {
comptime fmt: []const u8,
args: anytype,
) !void {
var fallback = std.heap.stackFallback(max_log_message_stack, sdl3.allocator);
var fallback = std.heap.stackFallback(options.log_message_stack_size, sdl3.allocator);
const allocator = fallback.get();
const msg = try std.fmt.allocPrintSentinel(allocator, fmt, args, 0);
defer allocator.free(msg);
Expand Down Expand Up @@ -281,7 +279,7 @@ pub const Category = enum(c_int) {
comptime fmt: []const u8,
args: anytype,
) !void {
var fallback = std.heap.stackFallback(max_log_message_stack, sdl3.allocator);
var fallback = std.heap.stackFallback(options.log_message_stack_size, sdl3.allocator);
const allocator = fallback.get();
const msg = try std.fmt.allocPrintSentinel(allocator, fmt, args, 0);
defer allocator.free(msg);
Expand Down Expand Up @@ -309,7 +307,7 @@ pub const Category = enum(c_int) {
comptime fmt: []const u8,
args: anytype,
) !void {
var fallback = std.heap.stackFallback(max_log_message_stack, sdl3.allocator);
var fallback = std.heap.stackFallback(options.log_message_stack_size, sdl3.allocator);
const allocator = fallback.get();
const msg = try std.fmt.allocPrintSentinel(allocator, fmt, args, 0);
defer allocator.free(msg);
Expand Down Expand Up @@ -337,7 +335,7 @@ pub const Category = enum(c_int) {
comptime fmt: []const u8,
args: anytype,
) !void {
var fallback = std.heap.stackFallback(max_log_message_stack, sdl3.allocator);
var fallback = std.heap.stackFallback(options.log_message_stack_size, sdl3.allocator);
const allocator = fallback.get();
const msg = try std.fmt.allocPrintSentinel(allocator, fmt, args, 0);
defer allocator.free(msg);
Expand Down Expand Up @@ -365,7 +363,7 @@ pub const Category = enum(c_int) {
comptime fmt: []const u8,
args: anytype,
) !void {
var fallback = std.heap.stackFallback(max_log_message_stack, sdl3.allocator);
var fallback = std.heap.stackFallback(options.log_message_stack_size, sdl3.allocator);
const allocator = fallback.get();
const msg = try std.fmt.allocPrintSentinel(allocator, fmt, args, 0);
defer allocator.free(msg);
Expand Down Expand Up @@ -449,7 +447,7 @@ pub fn log(
comptime fmt: []const u8,
args: anytype,
) !void {
var fallback = std.heap.stackFallback(max_log_message_stack, sdl3.allocator);
var fallback = std.heap.stackFallback(options.log_message_stack_size, sdl3.allocator);
const allocator = fallback.get();
const msg = try std.fmt.allocPrintSentinel(allocator, fmt, args, 0);
defer allocator.free(msg);
Expand Down
6 changes: 2 additions & 4 deletions src/render.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const blend_mode = @import("blend_mode.zig");
const errors = @import("errors.zig");
const events = @import("events.zig");
const gpu = @import("gpu.zig");
const options = @import("options");
const pixels = @import("pixels.zig");
const properties = @import("properties.zig");
const rect = @import("rect.zig");
Expand All @@ -11,9 +12,6 @@ const std = @import("std");
const surface = @import("surface.zig");
const video = @import("video.zig");

/// Maximum stack size to use for a message stack.
const debug_text_stack = 1024;

/// The size, in pixels, of a single `render.Renderer.renderDebugText()` character.
///
/// ## Remarks
Expand Down Expand Up @@ -1299,7 +1297,7 @@ pub const Renderer = struct {
comptime fmt: []const u8,
args: anytype,
) !void {
var fallback = std.heap.stackFallback(debug_text_stack, sdl3.allocator);
var fallback = std.heap.stackFallback(options.renderer_debug_text_stack_size, sdl3.allocator);
const allocator = fallback.get();
const msg = try std.fmt.allocPrintZ(allocator, fmt, args);
defer allocator.free(msg);
Expand Down
3 changes: 2 additions & 1 deletion src/sdl3.zig
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ pub const Locale = @import("locale.zig").Locale;
pub const log = @import("log.zig");

/// Main callback functions when desired.
pub const main_callbacks = if (extension_options.callbacks) @import("main_callbacks.zig") else void;
pub const main_callbacks = if (options.callbacks) @import("main_callbacks.zig") else void;

/// Ability to call other main functions.
///
Expand Down Expand Up @@ -822,6 +822,7 @@ pub const vulkan = @import("vulkan.zig");

// Others.
const extension_options = @import("extension_options");
const options = @import("options");
const std = @import("std");

//
Expand Down