Skip to content

Commit 82d865b

Browse files
refactor: start over
1 parent 66671d7 commit 82d865b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+2599
-4250
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
zig-out
2-
zig-cache
2+
.zig-cache
33
result
44
result-*

build.zig

Lines changed: 71 additions & 231 deletions
Original file line numberDiff line numberDiff line change
@@ -1,271 +1,111 @@
11
const std = @import("std");
2-
const metap = @import("metaplus").@"meta+";
32

4-
pub const Sdk = @import("src/phantom/sdk.zig");
3+
const WaylandScanner = @import("zig-wayland").Scanner;
54

6-
pub const DisplayBackendType = metap.enums.fields.mix(metap.enums.fromDecls(@import("src/phantom/display/backends.zig")), Sdk.TypeFor(.displays));
7-
pub const FontBackendType = metap.enums.fields.mix(metap.enums.fromDecls(@import("src/phantom/fonts/backends.zig")), Sdk.TypeFor(.fonts));
8-
pub const PlatformBackendType = metap.enums.fields.mix(metap.enums.fromDecls(@import("src/phantom/platform/backends.zig")), Sdk.TypeFor(.platforms));
9-
pub const SceneBackendType = metap.enums.fields.mix(metap.enums.fromDecls(@import("src/phantom/scene/backends.zig")), Sdk.TypeFor(.scenes));
10-
pub const ImageFormatType = metap.enums.fields.mix(metap.enums.fromDecls(@import("src/phantom/painting/image/formats.zig")), Sdk.TypeFor(.imageFormats));
11-
12-
fn addSourceFiles(
13-
b: *std.Build,
14-
fileOverrides: *std.StringHashMap([]const u8),
15-
rootSource: *[]const u8,
16-
phantomSource: *std.Build.Step.WriteFile,
17-
rootPath: []const u8,
18-
) !void {
19-
var depSourceRoot = try std.fs.openDirAbsolute(b.pathJoin(&.{ rootPath, "phantom" }), .{ .iterate = true });
20-
defer depSourceRoot.close();
21-
22-
var walker = try depSourceRoot.walk(b.allocator);
23-
defer walker.deinit();
24-
25-
while (try walker.next()) |entry| {
26-
if (entry.kind == .directory) continue;
27-
28-
const entryPath = b.pathJoin(&.{ rootPath, "phantom", entry.path });
29-
var entrySource = try Sdk.readAll(b.allocator, entryPath);
30-
errdefer b.allocator.free(entrySource);
31-
32-
const entrypointRel = try std.fs.path.relative(b.allocator, std.fs.path.dirname(entryPath).?, b.pathJoin(&.{ rootPath, "phantom.zig" }));
33-
defer b.allocator.free(entrypointRel);
34-
35-
const entrySourceOrig = entrySource;
36-
entrySource = try std.mem.replaceOwned(u8, b.allocator, entrySourceOrig, "@import(\"phantom\")", b.fmt("@import(\"{s}\")", .{entrypointRel}));
37-
b.allocator.free(entrySourceOrig);
38-
39-
if (fileOverrides.getPtr(entry.path)) |sourceptr| {
40-
const fullSource = try Sdk.updateSource(b.allocator, sourceptr.*, entrySource);
41-
errdefer b.allocator.free(fullSource);
42-
43-
b.allocator.free(sourceptr.*);
44-
sourceptr.* = fullSource;
45-
} else {
46-
const origPath = b.pathFromRoot(b.pathJoin(&.{ "src/phantom", entry.path }));
47-
if (Sdk.readAll(b.allocator, origPath) catch null) |origSource| {
48-
defer b.allocator.free(origSource);
49-
50-
const fullSource = try Sdk.updateSource(b.allocator, origSource, entrySource);
51-
errdefer b.allocator.free(fullSource);
52-
53-
try fileOverrides.put(try b.allocator.dupe(u8, entry.path), fullSource);
54-
b.allocator.free(entrySource);
55-
} else {
56-
_ = phantomSource.add(b.pathJoin(&.{ "phantom", entry.path }), entrySource);
57-
}
58-
}
59-
}
60-
61-
const src = try Sdk.readAll(b.allocator, b.pathJoin(&.{ rootPath, "phantom.zig" }));
62-
defer b.allocator.free(src);
5+
pub fn build(b: *std.Build) void {
6+
const target = b.standardTargetOptions(.{});
7+
const optimize = b.standardOptimizeOption(.{});
8+
const linkage = b.option(std.builtin.LinkMode, "linkage", "Whether to link as a static or dynamic binary");
639

64-
const fullSource = try Sdk.updateSource(b.allocator, rootSource.*, src);
65-
errdefer b.allocator.free(fullSource);
10+
const fsys_default = linkage == .dynamic and switch (target.result.os.tag) {
11+
.linux, .windows, .macos => true,
12+
else => false,
13+
};
6614

67-
b.allocator.free(rootSource.*);
68-
rootSource.* = fullSource;
69-
}
15+
const fsys_cairo = b.systemIntegrationOption("cairo", .{
16+
.default = fsys_default,
17+
});
7018

71-
pub fn build(b: *std.Build) !void {
72-
const target = b.standardTargetOptions(.{});
73-
const optimize = b.standardOptimizeOption(.{});
74-
const no_docs = b.option(bool, "no-docs", "skip installing documentation") orelse false;
75-
const no_importer = b.option(bool, "no-importer", "disables the import system (not recommended)") orelse false;
76-
const display_backend = b.option(DisplayBackendType, "display-backend", "The display backend to use for the example") orelse .headless;
77-
const platform_backend = b.option(PlatformBackendType, "platform-backend", "The display backend to use for the example") orelse .std;
78-
const scene_backend = b.option(SceneBackendType, "scene-backend", "The scene backend to use for the example") orelse .headless;
19+
const fsys_wayland = b.systemIntegrationOption("wayland", .{
20+
.default = fsys_default,
21+
});
7922

80-
const vizops = b.dependency("vizops", .{
23+
const zigimg = b.dependency("zigimg", .{
8124
.target = target,
8225
.optimize = optimize,
8326
});
8427

85-
const metaplus = b.dependency("metaplus", .{
28+
const z2d = b.dependency("z2d", .{
8629
.target = target,
8730
.optimize = optimize,
8831
});
8932

90-
const anyplus = b.dependency("any+", .{
33+
const module = b.addModule("phantom", .{
34+
.root_source_file = b.path("src/phantom.zig"),
9135
.target = target,
9236
.optimize = optimize,
37+
.imports = &.{
38+
.{
39+
.name = "zigimg",
40+
.module = zigimg.module("zigimg"),
41+
},
42+
.{
43+
.name = "z2d",
44+
.module = z2d.module("z2d"),
45+
},
46+
},
9347
});
9448

95-
const phantomOptions = b.addOptions();
96-
phantomOptions.addOption(bool, "no_importer", no_importer);
97-
98-
var phantomDeps = std.ArrayList(std.Build.Module.Import).init(b.allocator);
99-
errdefer phantomDeps.deinit();
100-
101-
try phantomDeps.append(.{
102-
.name = "vizops",
103-
.module = vizops.module("vizops"),
104-
});
105-
106-
try phantomDeps.append(.{
107-
.name = "meta+",
108-
.module = metaplus.module("meta+"),
109-
});
110-
111-
try phantomDeps.append(.{
112-
.name = "any+",
113-
.module = anyplus.module("any+"),
114-
});
115-
116-
try phantomDeps.append(.{
117-
.name = "phantom.options",
118-
.module = phantomOptions.createModule(),
119-
});
120-
121-
const phantomSource = b.addWriteFiles();
122-
123-
var fileOverrides = std.StringHashMap([]const u8).init(b.allocator);
124-
defer fileOverrides.deinit();
125-
126-
var rootSource = try Sdk.readAll(b.allocator, b.pathFromRoot("src/phantom.zig"));
127-
defer b.allocator.free(rootSource);
49+
const options = b.addOptions();
50+
options.addOption(bool, "cairo", fsys_cairo);
51+
options.addOption(bool, "wayland", fsys_wayland);
12852

129-
if (!no_importer) {
130-
inline for (Sdk.availableDepenencies) |dep| {
131-
const pkg = @field(@import("root").dependencies.packages, dep[1]);
132-
const pkgdep = b.dependencyInner(dep[0], pkg.build_root, if (@hasDecl(pkg, "build_zig")) pkg.build_zig else null, pkg.deps, .{
133-
.target = target,
134-
.optimize = optimize,
135-
.@"no-importer" = true,
136-
});
137-
138-
const depSourceRootPath = b.pathJoin(&.{ pkg.build_root, "src" });
139-
try addSourceFiles(b, &fileOverrides, &rootSource, phantomSource, depSourceRootPath);
140-
141-
var iter = pkgdep.module(dep[0]).import_table.iterator();
142-
while (iter.next()) |entry| {
143-
var alreadyExists = false;
144-
for (phantomDeps.items) |i| {
145-
if (std.mem.eql(u8, i.name, entry.key_ptr.*)) {
146-
alreadyExists = true;
147-
break;
148-
}
149-
}
53+
if (fsys_cairo) {
54+
module.linkSystemLibrary("cairo", .{
55+
.needed = true,
56+
.preferred_link_mode = linkage orelse .dynamic,
57+
});
15058

151-
if (!alreadyExists or !std.mem.eql(u8, entry.key_ptr.*, "phantom")) {
152-
try phantomDeps.append(.{
153-
.name = entry.key_ptr.*,
154-
.module = entry.value_ptr.*,
155-
});
156-
}
157-
}
158-
}
59+
module.link_libc = true;
15960
}
16061

161-
if (b.option([]const u8, "import-module", "inject a module to be imported")) |importModuleString| {
162-
const modulePathLen = std.mem.indexOf(u8, importModuleString, ":") orelse importModuleString.len;
163-
const modulePath = importModuleString[0..modulePathLen];
62+
if (fsys_wayland) {
63+
const scanner = WaylandScanner.create(b, .{});
16464

165-
try addSourceFiles(b, &fileOverrides, &rootSource, phantomSource, modulePath);
65+
scanner.generate("wl_compositor", 1);
66+
scanner.generate("wl_output", 1);
67+
scanner.generate("wl_shm", 1);
16668

167-
if (modulePathLen < importModuleString.len) {
168-
const imports = try Sdk.ModuleImport.decode(b.allocator, importModuleString[(modulePathLen + 1)..]);
169-
defer imports.deinit();
69+
const wayland = b.createModule(.{ .root_source_file = scanner.result });
17070

171-
for (imports.value) |dep| {
172-
var alreadyExists = false;
173-
for (phantomDeps.items) |i| {
174-
if (std.mem.eql(u8, i.name, dep.name)) {
175-
alreadyExists = true;
176-
break;
177-
}
71+
module.addImport("wayland", wayland);
17872

179-
if (!alreadyExists or !std.mem.eql(u8, dep.name, "phantom")) {
180-
try phantomDeps.append(.{
181-
.name = dep.name,
182-
.module = try dep.createModule(b, target, optimize),
183-
});
184-
}
185-
}
186-
}
187-
}
188-
}
189-
190-
var phantomSourceRoot = try std.fs.openDirAbsolute(b.pathFromRoot("src/phantom"), .{ .iterate = true });
191-
defer phantomSourceRoot.close();
192-
193-
var walker = try phantomSourceRoot.walk(b.allocator);
194-
defer walker.deinit();
195-
196-
while (try walker.next()) |entry| {
197-
if (entry.kind == .directory) continue;
73+
module.linkSystemLibrary("wayland-client", .{
74+
.needed = true,
75+
.preferred_link_mode = linkage orelse .dynamic,
76+
});
19877

199-
const entryPath = b.pathJoin(&.{ "phantom", entry.path });
78+
module.linkSystemLibrary("wayland-server", .{
79+
.needed = true,
80+
.preferred_link_mode = linkage orelse .dynamic,
81+
});
20082

201-
if (fileOverrides.get(entry.path)) |source| {
202-
_ = phantomSource.add(entryPath, source);
203-
} else {
204-
_ = phantomSource.addCopyFile(.{
205-
.path = b.pathFromRoot(b.pathJoin(&.{ "src/phantom", entry.path })),
206-
}, entryPath);
207-
}
83+
module.link_libc = true;
20884
}
20985

210-
const phantom = b.addModule("phantom", .{
211-
.root_source_file = phantomSource.add("phantom.zig", rootSource),
212-
.imports = phantomDeps.items,
213-
});
214-
215-
const step_test = b.step("test", "Run all unit tests");
86+
module.addOptions("options", options);
21687

217-
const unit_tests = b.addTest(.{
218-
.root_source_file = phantom.root_source_file.?,
219-
.target = target,
220-
.optimize = optimize,
88+
const autodoc_test = b.addObject(.{
89+
.name = "phantom",
90+
.root_module = module,
22191
});
22292

223-
for (phantomDeps.items) |dep| {
224-
unit_tests.root_module.addImport(dep.name, dep.module);
225-
}
226-
227-
const run_unit_tests = b.addRunArtifact(unit_tests);
228-
step_test.dependOn(&run_unit_tests.step);
229-
b.installArtifact(unit_tests);
230-
231-
const exe_options = b.addOptions();
232-
exe_options.addOption(DisplayBackendType, "display_backend", display_backend);
233-
exe_options.addOption(PlatformBackendType, "platform_backend", platform_backend);
234-
exe_options.addOption(SceneBackendType, "scene_backend", scene_backend);
235-
236-
const sdk = try Sdk.get(b, platform_backend, phantom);
237-
defer sdk.deinit();
238-
239-
const pkg_example = sdk.addPackage(.{
240-
.id = "dev.phantomui.example",
241-
.name = "example",
242-
.root_module = .{
243-
.root_source_file = .{
244-
.path = b.pathFromRoot("src/example.zig"),
245-
},
246-
.target = target,
247-
.optimize = optimize,
248-
},
249-
.kind = .application,
250-
.version = .{
251-
.major = 0,
252-
.minor = 1,
253-
.patch = 0,
254-
},
93+
const install_docs = b.addInstallDirectory(.{
94+
.source_dir = autodoc_test.getEmittedDocs(),
95+
.install_dir = .prefix,
96+
.install_subdir = "doc/phantom",
25597
});
25698

257-
pkg_example.root_module.addImport("vizops", vizops.module("vizops"));
258-
pkg_example.root_module.addImport("options", exe_options.createModule());
99+
b.getInstallStep().dependOn(&install_docs.step);
259100

260-
sdk.installPackage(pkg_example);
101+
const step_test = b.step("test", "Run unit tests");
261102

262-
if (!no_docs) {
263-
const docs = b.addInstallDirectory(.{
264-
.source_dir = unit_tests.getEmittedDocs(),
265-
.install_dir = .prefix,
266-
.install_subdir = "docs",
267-
});
103+
const test_exe = b.addTest(.{
104+
.target = target,
105+
.optimize = optimize,
106+
.root_module = module,
107+
});
268108

269-
b.getInstallStep().dependOn(&docs.step);
270-
}
109+
const test_run = b.addRunArtifact(test_exe);
110+
step_test.dependOn(&test_run.step);
271111
}

build.zig.zon

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
.version = "0.1.0",
44
.paths = .{"."},
55
.dependencies = .{
6-
.vizops = .{
7-
.url = "http://gitlab.midstall.com/common/vizops/-/archive/cb7a23d02c3030056a59ff0cd856d95221e8da06/vizops-cb7a23d02c3030056a59ff0cd856d95221e8da06.tar.gz",
8-
.hash = "1220813b3d22d110b409ec8619fc1da2bc2ba2e71eb37b6a921ad228b485135793be",
6+
.zigimg = .{
7+
.url = "https://github.com/zigimg/zigimg/archive/efe99b6bbf5e226fbeaef124fbeb7f71c59a5959.tar.gz",
8+
.hash = "122062addce20425797c4682a057a55578e9df23b0bb07ef62a6c7fdf0cdb05db12e",
99
},
10-
.metaplus = .{
11-
.url = "http://gitlab.midstall.com/common/meta-plus/-/archive/9f8c3828e3c4445b80185dd24eeb61d0386b23dc/meta-plus-9f8c3828e3c4445b80185dd24eeb61d0386b23dc.tar.gz",
12-
.hash = "122057d6a6bd7ba8b95fe67d91f584c4c0140ca26e8bea09b92f63b649dff470bf56",
10+
.z2d = .{
11+
.url = "https://github.com/vancluever/z2d/archive/0ee56e929d8aa3f422ca8065cb58ef40af461234.tar.gz",
12+
.hash = "1220b74fe8b9b63a2996311de7233092a75f20de2f23abec2d30a12004d4be73544a",
1313
},
14-
.@"any+" = .{
15-
.url = "http://gitlab.midstall.com/common/any-plus/-/archive/15e70210f0525fa619bfed533c1205ff57ac2100/any-plus-15e70210f0525fa619bfed533c1205ff57ac2100.tar.gz",
16-
.hash = "12209b041a839e89ece510c07dbe62ad53b045ff0e6c44645cd1a3ea38f3b42905b9",
14+
.@"zig-wayland" = .{
15+
.url = "https://codeberg.org/ifreund/zig-wayland/archive/33eb61512079e681f0be63292ae9215c90fa253d.tar.gz",
16+
.hash = "1220471cb751c2be92b33d14b7ef97cf260bfa9e13b12fd009d88a957de298468217",
1717
},
1818
},
1919
}

0 commit comments

Comments
 (0)