Skip to content

Commit 7b7f55c

Browse files
Merge pull request #11 from PhantomUIx/feat/refactor
refactor: start over
2 parents 66671d7 + 9fab306 commit 7b7f55c

File tree

117 files changed

+3257
-4268
lines changed

Some content is hidden

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

117 files changed

+3257
-4268
lines changed

.github/workflows/build.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ jobs:
1919
optimize: [ReleaseSmall, Debug]
2020
steps:
2121
- uses: actions/checkout@v4
22-
- uses: goto-bus-stop/setup-zig@v2
22+
- uses: mlugg/setup-zig@v1
2323
- name: Build
2424
run: |
2525
zig build -Dtarget=${{ matrix.target }} -Doptimize=${{ matrix.optimize }}
2626
- name: Test
2727
run: |
28-
zig build test
28+
zig build test -Dtarget=${{ matrix.target }} -Doptimize=${{ matrix.optimize }}
2929
windows:
3030
runs-on: windows-latest
3131
strategy:
@@ -34,13 +34,14 @@ jobs:
3434
optimize: [ReleaseSmall, Debug]
3535
steps:
3636
- uses: actions/checkout@v4
37-
- uses: goto-bus-stop/setup-zig@v2
37+
- uses: mlugg/setup-zig@v1
3838
- name: Build
3939
run: |
4040
zig build -Dtarget=${{ matrix.target }} -Doptimize=${{ matrix.optimize }}
4141
- name: Test
42+
if: ${{ startsWith(matrix.target, 'x86_64') }}
4243
run: |
43-
zig build test
44+
zig build test -Dtarget=${{ matrix.target }} -Doptimize=${{ matrix.optimize }}
4445
linux:
4546
runs-on: ubuntu-latest
4647
strategy:
@@ -49,10 +50,11 @@ jobs:
4950
optimize: [ReleaseSmall, Debug]
5051
steps:
5152
- uses: actions/checkout@v4
52-
- uses: goto-bus-stop/setup-zig@v2
53+
- uses: mlugg/setup-zig@v1
54+
- uses: docker/setup-qemu-action@v3
5355
- name: Build
5456
run: |
5557
zig build -Dtarget=${{ matrix.target }} -Doptimize=${{ matrix.optimize }}
5658
- name: Test
5759
run: |
58-
zig build test
60+
zig build test -Dtarget=${{ matrix.target }} -Doptimize=${{ matrix.optimize }}

.gitignore

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

build.zig

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

4-
pub const Sdk = @import("src/phantom/sdk.zig");
5-
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);
63-
64-
const fullSource = try Sdk.updateSource(b.allocator, rootSource.*, src);
65-
errdefer b.allocator.free(fullSource);
66-
67-
b.allocator.free(rootSource.*);
68-
rootSource.* = fullSource;
69-
}
70-
71-
pub fn build(b: *std.Build) !void {
3+
pub fn build(b: *std.Build) void {
724
const target = b.standardTargetOptions(.{});
735
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;
796

80-
const vizops = b.dependency("vizops", .{
7+
const zigimg = b.dependency("zigimg", .{
818
.target = target,
829
.optimize = optimize,
8310
});
8411

85-
const metaplus = b.dependency("metaplus", .{
12+
const z2d = b.dependency("z2d", .{
8613
.target = target,
8714
.optimize = optimize,
8815
});
8916

90-
const anyplus = b.dependency("any+", .{
17+
const module = b.addModule("phantom", .{
18+
.root_source_file = b.path("lib/phantom.zig"),
9119
.target = target,
9220
.optimize = optimize,
21+
.imports = &.{
22+
.{
23+
.name = "zigimg",
24+
.module = zigimg.module("zigimg"),
25+
},
26+
.{
27+
.name = "z2d",
28+
.module = z2d.module("z2d"),
29+
},
30+
},
9331
});
9432

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+"),
33+
const autodoc_test = b.addObject(.{
34+
.name = "phantom",
35+
.root_module = module,
11436
});
11537

116-
try phantomDeps.append(.{
117-
.name = "phantom.options",
118-
.module = phantomOptions.createModule(),
38+
const install_docs = b.addInstallDirectory(.{
39+
.source_dir = autodoc_test.getEmittedDocs(),
40+
.install_dir = .prefix,
41+
.install_subdir = "doc/phantom",
11942
});
12043

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);
128-
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-
});
44+
b.getInstallStep().dependOn(&install_docs.step);
13745

138-
const depSourceRootPath = b.pathJoin(&.{ pkg.build_root, "src" });
139-
try addSourceFiles(b, &fileOverrides, &rootSource, phantomSource, depSourceRootPath);
46+
const step_test = b.step("test", "Run unit tests");
14047

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-
}
150-
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-
}
159-
}
160-
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];
164-
165-
try addSourceFiles(b, &fileOverrides, &rootSource, phantomSource, modulePath);
166-
167-
if (modulePathLen < importModuleString.len) {
168-
const imports = try Sdk.ModuleImport.decode(b.allocator, importModuleString[(modulePathLen + 1)..]);
169-
defer imports.deinit();
170-
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-
}
178-
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;
198-
199-
const entryPath = b.pathJoin(&.{ "phantom", entry.path });
200-
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-
}
208-
}
209-
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");
216-
217-
const unit_tests = b.addTest(.{
218-
.root_source_file = phantom.root_source_file.?,
48+
const test_exe = b.addTest(.{
21949
.target = target,
22050
.optimize = optimize,
51+
.root_module = module,
22152
});
22253

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-
},
255-
});
256-
257-
pkg_example.root_module.addImport("vizops", vizops.module("vizops"));
258-
pkg_example.root_module.addImport("options", exe_options.createModule());
259-
260-
sdk.installPackage(pkg_example);
261-
262-
if (!no_docs) {
263-
const docs = b.addInstallDirectory(.{
264-
.source_dir = unit_tests.getEmittedDocs(),
265-
.install_dir = .prefix,
266-
.install_subdir = "docs",
267-
});
268-
269-
b.getInstallStep().dependOn(&docs.step);
270-
}
54+
const test_run = b.addRunArtifact(test_exe);
55+
step_test.dependOn(&test_run.step);
27156
}

build.zig.zon

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
.{
2-
.name = "phantom",
2+
.name = .phantom,
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/TUSF/zigimg/archive/256cf2655bb887a30c57d8cbc1b9590643f0a824.tar.gz",
8+
.hash = "zigimg-0.1.0-lly-O3AVEQBq5UYuvW77W180h6v41vJ9WXtBhrbLwtNH",
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/67d2e2e1891cd467fb7cb7c072bcf33dae2589a4.tar.gz",
12+
.hash = "z2d-0.6.2-j5P_HjzpCgBdWm_1K6nob_MIb5YQqW5zyUCX9B5QnUeZ",
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/f3c5d503e540ada8cbcb056420de240af0c094f7.tar.gz",
16+
.hash = "wayland-0.4.0-dev-lQa1kjfIAQCmhhQu3xF0KH-94-TzeMXOqfnP0-Dg6Wyy",
1717
},
1818
},
19+
.fingerprint = 0x6896f6aeaa10b7f9,
1920
}

0 commit comments

Comments
 (0)