updated generated files
This commit is contained in:
parent
cca2376228
commit
27157135ed
14
README.md
14
README.md
|
|
@ -37,13 +37,21 @@ You can specify which repo to use with `-Dsdl-url=<repo-url>` the git refs will
|
||||||
|
|
||||||
`-Dofficial` will use libsdl org's github repo.
|
`-Dofficial` will use libsdl org's github repo.
|
||||||
|
|
||||||
If you already have SDL headers locally, use `-DtargetDir=<path>` instead of fetching from git:
|
If you already have SDL headers locally, use `-DsourceDir=<path>` instead of fetching from git:
|
||||||
|
|
||||||
```
|
```
|
||||||
zig build generate -DtargetDir=D:/path/to/SDL
|
zig build generate -DsourceDir=D:/path/to/SDL
|
||||||
```
|
```
|
||||||
|
|
||||||
`targetDir` may point at an SDL checkout root (`include/SDL3`) or directly at a directory containing the SDL headers. Generated outputs go to `<targetDir>/api` and `<targetDir>/json`, and parser scratch directories (`tmp`, `debug`, `archive`) are rooted there as well.
|
`sourceDir` may point at an SDL checkout root (`include/SDL3`) or directly at a directory containing the SDL headers. Generated outputs go to `<sourceDir>/api` and `<sourceDir>/json` unless `-DoutputDir` is provided.
|
||||||
|
|
||||||
|
If you want to read headers from one location and write outputs somewhere else, add `-DoutputDir=<path>`:
|
||||||
|
|
||||||
|
```
|
||||||
|
zig build generate -DsourceDir=D:/path/to/SDL -DoutputDir=D:/path/to/output
|
||||||
|
```
|
||||||
|
|
||||||
|
That writes `api/` and `json/` under `outputDir` while still reading headers from `sourceDir`. `--basedir` remains the parser working directory for `tmp/`, `debug/`, and `archive/debug`.
|
||||||
|
|
||||||
## Parser Usage
|
## Parser Usage
|
||||||
|
|
||||||
|
|
|
||||||
48
build.zig
48
build.zig
|
|
@ -1,13 +1,13 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
fn resolveHeaderRoot(allocator: std.mem.Allocator, target_dir: []const u8) ![]const u8 {
|
fn resolveHeaderRoot(allocator: std.mem.Allocator, source_dir: []const u8) ![]const u8 {
|
||||||
const include_sdl3 = try std.fs.path.join(allocator, &.{ target_dir, "include", "SDL3" });
|
const include_sdl3 = try std.fs.path.join(allocator, &.{ source_dir, "include", "SDL3" });
|
||||||
defer allocator.free(include_sdl3);
|
defer allocator.free(include_sdl3);
|
||||||
if (std.fs.cwd().access(include_sdl3, .{})) {
|
if (std.fs.cwd().access(include_sdl3, .{})) {
|
||||||
return try allocator.dupe(u8, "include/SDL3");
|
return try allocator.dupe(u8, "include/SDL3");
|
||||||
} else |_| {}
|
} else |_| {}
|
||||||
|
|
||||||
const sdl3_dir = try std.fs.path.join(allocator, &.{ target_dir, "SDL3" });
|
const sdl3_dir = try std.fs.path.join(allocator, &.{ source_dir, "SDL3" });
|
||||||
defer allocator.free(sdl3_dir);
|
defer allocator.free(sdl3_dir);
|
||||||
if (std.fs.cwd().access(sdl3_dir, .{})) {
|
if (std.fs.cwd().access(sdl3_dir, .{})) {
|
||||||
return try allocator.dupe(u8, "SDL3");
|
return try allocator.dupe(u8, "SDL3");
|
||||||
|
|
@ -156,16 +156,17 @@ const MakeDirStep = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn generateApi(b: *std.Build, parser_exe: *std.Build.Step.Compile, fetch_sdl_step: *std.Build.Step) void {
|
pub fn generateApi(b: *std.Build, parser_exe: *std.Build.Step.Compile, fetch_sdl_step: *std.Build.Step) void {
|
||||||
const target_dir = b.option([]const u8, "targetDir", "Parse SDL headers from an existing local directory and generate api/ there instead of fetching git");
|
const source_dir = b.option([]const u8, "sourceDir", "Parse SDL headers from an existing local directory instead of fetching git");
|
||||||
|
const output_dir = b.option([]const u8, "outputDir", "Directory where generated api/ and json/ folders should be written");
|
||||||
const basedir = b.option([]const u8, "basedir", "Working directory for the parser to execute in");
|
const basedir = b.option([]const u8, "basedir", "Working directory for the parser to execute in");
|
||||||
const effective_basedir = target_dir orelse basedir;
|
const effective_output_dir = output_dir orelse source_dir;
|
||||||
const header_root_suffix = if (target_dir) |dir| resolveHeaderRoot(b.allocator, dir) catch @panic("OOM") else null;
|
const header_root_suffix = if (source_dir) |dir| resolveHeaderRoot(b.allocator, dir) catch @panic("OOM") else null;
|
||||||
|
|
||||||
// Archive existing json/ and api/ directories before regenerating
|
// Archive existing json/ and api/ directories before regenerating
|
||||||
const archive_step = ArchiveStep.create(b, effective_basedir);
|
const archive_step = ArchiveStep.create(b, effective_output_dir);
|
||||||
|
|
||||||
const generation_root = if (target_dir != null) archive_step else fetch_sdl_step;
|
const generation_root = if (source_dir != null) archive_step else fetch_sdl_step;
|
||||||
if (target_dir == null) {
|
if (source_dir == null) {
|
||||||
fetch_sdl_step.dependOn(archive_step);
|
fetch_sdl_step.dependOn(archive_step);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -176,10 +177,17 @@ pub fn generateApi(b: *std.Build, parser_exe: *std.Build.Step.Compile, fetch_sdl
|
||||||
_ = marker_file;
|
_ = marker_file;
|
||||||
wf.step.dependOn(generation_root);
|
wf.step.dependOn(generation_root);
|
||||||
|
|
||||||
// Create basedir if specified
|
var path_prep_step: *std.Build.Step = &wf.step;
|
||||||
const basedir_step = if (effective_basedir) |dir| MakeDirStep.create(b, dir) else &wf.step;
|
if (effective_output_dir) |dir| {
|
||||||
if (effective_basedir != null)
|
const output_dir_step = MakeDirStep.create(b, dir);
|
||||||
basedir_step.dependOn(&wf.step);
|
output_dir_step.dependOn(path_prep_step);
|
||||||
|
path_prep_step = output_dir_step;
|
||||||
|
}
|
||||||
|
if (basedir) |dir| {
|
||||||
|
const basedir_step = MakeDirStep.create(b, dir);
|
||||||
|
basedir_step.dependOn(path_prep_step);
|
||||||
|
path_prep_step = basedir_step;
|
||||||
|
}
|
||||||
|
|
||||||
// All public SDL3 API headers (53 total)
|
// All public SDL3 API headers (53 total)
|
||||||
// Skipped: assert, thread, hidapi, mutex, tray (not core APIs or problematic)
|
// Skipped: assert, thread, hidapi, mutex, tray (not core APIs or problematic)
|
||||||
|
|
@ -239,12 +247,12 @@ pub fn generateApi(b: *std.Build, parser_exe: *std.Build.Step.Compile, fetch_sdl
|
||||||
};
|
};
|
||||||
|
|
||||||
const regenerate_step = b.step("generate", "Regenerate bindings from SDL headers");
|
const regenerate_step = b.step("generate", "Regenerate bindings from SDL headers");
|
||||||
const header_root = if (target_dir) |dir|
|
const header_root = if (source_dir) |dir|
|
||||||
b.fmt("{s}/{s}", .{ dir, header_root_suffix.? })
|
b.fmt("{s}/{s}", .{ dir, header_root_suffix.? })
|
||||||
else
|
else
|
||||||
"sdl3/include/SDL3";
|
"sdl3/include/SDL3";
|
||||||
const output_root = if (target_dir) |dir| b.fmt("{s}/api", .{dir}) else "api";
|
const output_root = if (effective_output_dir) |dir| b.fmt("{s}/api", .{dir}) else "api";
|
||||||
const json_root = if (target_dir) |dir| b.fmt("{s}/json", .{dir}) else "json";
|
const json_root = if (effective_output_dir) |dir| b.fmt("{s}/json", .{dir}) else "json";
|
||||||
|
|
||||||
const timestamp_arg = b.fmt("--timestamp={d}", .{timestamp});
|
const timestamp_arg = b.fmt("--timestamp={d}", .{timestamp});
|
||||||
|
|
||||||
|
|
@ -253,21 +261,21 @@ pub fn generateApi(b: *std.Build, parser_exe: *std.Build.Step.Compile, fetch_sdl
|
||||||
regenerate.addArg(b.fmt("{s}/{s}", .{ header_root, header_info.header }));
|
regenerate.addArg(b.fmt("{s}/{s}", .{ header_root, header_info.header }));
|
||||||
regenerate.addArg(b.fmt("--output={s}/{s}.zig", .{ output_root, header_info.output }));
|
regenerate.addArg(b.fmt("--output={s}/{s}.zig", .{ output_root, header_info.output }));
|
||||||
regenerate.addArg(timestamp_arg);
|
regenerate.addArg(timestamp_arg);
|
||||||
if (effective_basedir) |dir| {
|
if (basedir) |dir| {
|
||||||
regenerate.addArg(b.fmt("--basedir={s}", .{dir}));
|
regenerate.addArg(b.fmt("--basedir={s}", .{dir}));
|
||||||
}
|
}
|
||||||
// regenerate.addArg(b.fmt("--output=api/{s}.zig --mocks=mocks/{s}.c", .{ header_info.output, header_info.output }));
|
// regenerate.addArg(b.fmt("--output=api/{s}.zig --mocks=mocks/{s}.c", .{ header_info.output, header_info.output }));
|
||||||
regenerate.step.dependOn(basedir_step);
|
regenerate.step.dependOn(path_prep_step);
|
||||||
regenerate_step.dependOn(®enerate.step);
|
regenerate_step.dependOn(®enerate.step);
|
||||||
|
|
||||||
const regenerateJson = b.addRunArtifact(parser_exe);
|
const regenerateJson = b.addRunArtifact(parser_exe);
|
||||||
regenerateJson.addArg(b.fmt("{s}/{s}", .{ header_root, header_info.header }));
|
regenerateJson.addArg(b.fmt("{s}/{s}", .{ header_root, header_info.header }));
|
||||||
regenerateJson.addArg(b.fmt("--generate-json={s}/{s}.json", .{ json_root, header_info.output }));
|
regenerateJson.addArg(b.fmt("--generate-json={s}/{s}.json", .{ json_root, header_info.output }));
|
||||||
regenerateJson.addArg(timestamp_arg);
|
regenerateJson.addArg(timestamp_arg);
|
||||||
if (effective_basedir) |dir| {
|
if (basedir) |dir| {
|
||||||
regenerateJson.addArg(b.fmt("--basedir={s}", .{dir}));
|
regenerateJson.addArg(b.fmt("--basedir={s}", .{dir}));
|
||||||
}
|
}
|
||||||
regenerateJson.step.dependOn(basedir_step);
|
regenerateJson.step.dependOn(path_prep_step);
|
||||||
regenerate_step.dependOn(®enerateJson.step);
|
regenerate_step.dependOn(®enerateJson.step);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue