Skip to content

Commit 12f233e

Browse files
committed
WIP: Editor and runner
1 parent e70146c commit 12f233e

File tree

10 files changed

+184
-51
lines changed

10 files changed

+184
-51
lines changed

.github/workflows/test.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ jobs:
9898
# uses: pyvista/setup-headless-display-action@v2
9999

100100
- name: Test headless standalone
101-
run: zig-out/bin/cetech1 --headless --max-kernel-tick 5
101+
run: zig-out/bin/cetech1_editor --headless --max-kernel-tick 5
102102

103103
- name: Test headless standalone with asset root
104-
run: zig-out/bin/cetech1 --headless --max-kernel-tick 5 --asset-root fixtures/test_asset/
104+
run: zig-out/bin/cetech1_editor --headless --max-kernel-tick 5 --asset-root fixtures/test_asset/
105105

106106
- name: Test UI headless
107-
run: zig-out/bin/cetech1 --headless --test-ui --test-ui-junit ./result.xml
107+
run: zig-out/bin/cetech1_editor --headless --test-ui --test-ui-junit ./result.xml
108108

109109
- name: Publish Test Report
110110
uses: mikepenz/action-junit-report@v4
@@ -150,13 +150,13 @@ jobs:
150150
#run: kcov --include-pattern=/cetech1/src/,/cetech/public/ kcov-output zig-out/bin/cetech1_test
151151

152152
- name: Test headless standalone
153-
run: zig-out/bin/cetech1 --headless --max-kernel-tick 5
153+
run: zig-out/bin/cetech1_editor --headless --max-kernel-tick 5
154154

155155
- name: Test headless standalone with asset root
156-
run: zig-out/bin/cetech1 --headless --max-kernel-tick 5 --asset-root fixtures/test_asset/
156+
run: zig-out/bin/cetech1_editor --headless --max-kernel-tick 5 --asset-root fixtures/test_asset/
157157

158158
- name: Test UI headless
159-
run: zig-out/bin/cetech1 --headless --test-ui --test-ui-junit ./result.xml
159+
run: zig-out/bin/cetech1_editor --headless --test-ui --test-ui-junit ./result.xml
160160

161161
- name: Publish Test Report
162162
uses: mikepenz/action-junit-report@v4
@@ -206,15 +206,15 @@ jobs:
206206
# FIXME: Windows
207207
- name: Test headless standalone
208208
shell: bash
209-
run: zig-out/bin/cetech1 --headless --max-kernel-tick 5
209+
run: zig-out/bin/cetech1_editor --headless --max-kernel-tick 5
210210

211211
- name: Test headless standalone with asset root
212212
shell: bash
213-
run: zig-out/bin/cetech1 --headless --max-kernel-tick 5 --asset-root fixtures/test_asset/
213+
run: zig-out/bin/cetech1_editor --headless --max-kernel-tick 5 --asset-root fixtures/test_asset/
214214

215215
- name: Test UI headless
216216
shell: bash
217-
run: zig-out/bin/cetech1 --headless --test-ui --test-ui-junit ./result.xml
217+
run: zig-out/bin/cetech1_editor --headless --test-ui --test-ui-junit ./result.xml
218218

219219
- name: Publish Test Report
220220
uses: mikepenz/action-junit-report@v4

build.zig

Lines changed: 89 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,16 @@ pub fn updateCectechStep(
119119
pub fn createKernelExe(
120120
b: *std.Build,
121121
comptime bin_name: []const u8,
122+
comptime run_name: []const u8,
123+
comptime run_description: []const u8,
122124
runner_main: std.Build.LazyPath,
123125
cetech1_kernel: *std.Build.Module,
124126
cetech1_kernel_lib: *std.Build.Step.Compile,
125127
versionn: std.SemanticVersion,
128+
static_modules: []const []const u8,
126129
target: std.Build.ResolvedTarget,
127130
optimize: std.builtin.OptimizeMode,
128-
) *std.Build.Step.Compile {
131+
) !*std.Build.Step.Compile {
129132
const exe = b.addExecutable(.{
130133
.name = bin_name,
131134
.version = versionn,
@@ -141,11 +144,63 @@ pub fn createKernelExe(
141144
exe.linkLibrary(cetech1_kernel_lib);
142145
b.installArtifact(exe);
143146
useSystemSDK(b, target, exe);
144-
createRunStep(b, exe, "run", "Run Forest run");
145-
147+
createRunStep(b, exe, run_name, run_description);
148+
try linkStaticModules(b, exe, target, optimize, static_modules);
146149
return exe;
147150
}
148151

152+
pub fn createEditorExe(
153+
b: *std.Build,
154+
comptime base_bin_name: []const u8,
155+
root_source: std.Build.LazyPath,
156+
cetech1_kernel: *std.Build.Module,
157+
cetech1_kernel_lib: *std.Build.Step.Compile,
158+
versionn: std.SemanticVersion,
159+
static_modules: []const []const u8,
160+
target: std.Build.ResolvedTarget,
161+
optimize: std.builtin.OptimizeMode,
162+
) !*std.Build.Step.Compile {
163+
return try createKernelExe(
164+
b,
165+
base_bin_name ++ "_editor",
166+
"editor",
167+
"Run editor",
168+
root_source,
169+
cetech1_kernel,
170+
cetech1_kernel_lib,
171+
versionn,
172+
static_modules,
173+
target,
174+
optimize,
175+
);
176+
}
177+
178+
pub fn createRunnerExe(
179+
b: *std.Build,
180+
comptime base_bin_name: []const u8,
181+
root_source: std.Build.LazyPath,
182+
cetech1_kernel: *std.Build.Module,
183+
cetech1_kernel_lib: *std.Build.Step.Compile,
184+
versionn: std.SemanticVersion,
185+
static_modules: []const []const u8,
186+
target: std.Build.ResolvedTarget,
187+
optimize: std.builtin.OptimizeMode,
188+
) !*std.Build.Step.Compile {
189+
return try createKernelExe(
190+
b,
191+
base_bin_name,
192+
"run",
193+
"Run Forest Run!",
194+
root_source,
195+
cetech1_kernel,
196+
cetech1_kernel_lib,
197+
versionn,
198+
static_modules,
199+
target,
200+
optimize,
201+
);
202+
}
203+
149204
pub fn build(b: *std.Build) !void {
150205
try ensureZigVersion();
151206

@@ -317,6 +372,10 @@ pub fn build(b: *std.Build) !void {
317372

318373
// Modules
319374
const ModulesSet = std.StringArrayHashMapUnmanaged(void);
375+
376+
var internal_modules = std.ArrayListUnmanaged([]const u8){};
377+
defer internal_modules.deinit(b.allocator);
378+
320379
var module_set = ModulesSet{};
321380
defer module_set.deinit(b.allocator);
322381
for (all_modules) |module| {
@@ -403,7 +462,7 @@ pub fn build(b: *std.Build) !void {
403462
gen_ide.addArgs(&.{ "--ide", @tagName(options.ide) });
404463

405464
gen_ide.addArg("--bin-path");
406-
gen_ide.addDirectoryArg(b.path("zig-out/bin/cetech1"));
465+
gen_ide.addDirectoryArg(b.path("zig-out/bin/cetech1_editor"));
407466

408467
gen_ide.addArg("--project-path");
409468
gen_ide.addDirectoryArg(b.path(""));
@@ -446,6 +505,9 @@ pub fn build(b: *std.Build) !void {
446505
var buff: [256:0]u8 = undefined;
447506
for (dynamic_modules.keys()) |m| {
448507
const artifact_name = try std.fmt.bufPrintZ(&buff, "ct_{s}", .{m});
508+
509+
if (!module_set.contains(m)) continue;
510+
449511
const art = b.lazyDependency(m, .{
450512
.target = target,
451513
.optimize = optimize,
@@ -526,21 +588,36 @@ pub fn build(b: *std.Build) !void {
526588
});
527589

528590
//
529-
// CETech1 kernel standalone exe
591+
// CETech1 editor standalone exe
592+
//
593+
const editor_exe = try createEditorExe(
594+
b,
595+
"cetech1",
596+
b.path("src/editor/editor.zig"),
597+
kernel_module,
598+
kernel_lib,
599+
cetech1_version,
600+
static_modules.keys(),
601+
target,
602+
optimize,
603+
);
604+
editor_exe.step.dependOn(&generated_files.step);
605+
606+
//
607+
// CETech1 runner standalone exe
530608
//
531-
const exe = createKernelExe(
609+
const runner_exe = try createRunnerExe(
532610
b,
533611
"cetech1",
534-
b.path("src/main.zig"),
612+
b.path("src/runner/runner.zig"),
535613
kernel_module,
536614
kernel_lib,
537615
cetech1_version,
616+
static_modules.keys(),
538617
target,
539618
optimize,
540619
);
541-
try linkStaticModules(b, exe, target, optimize, static_modules.keys());
542-
// Make exe depends on generated files.
543-
exe.step.dependOn(&generated_files.step);
620+
runner_exe.step.dependOn(&generated_files.step);
544621

545622
//
546623
// CETech1 kernel standalone tests
@@ -557,17 +634,17 @@ pub fn build(b: *std.Build) !void {
557634
});
558635
useSystemSDK(b, target, tests);
559636
b.installArtifact(tests);
637+
try linkStaticModules(b, tests, target, optimize, static_modules.keys());
560638
tests.linkLibC();
561639
tests.linkLibrary(kernel_lib);
562640
tests.step.dependOn(&generated_files.step);
563-
try linkStaticModules(b, tests, target, optimize, static_modules.keys());
564641

565642
const run_unit_tests = b.addRunArtifact(tests);
566643
run_unit_tests.step.dependOn(b.getInstallStep());
567644
const test_step = b.step("test", "Run unit tests");
568645
test_step.dependOn(&run_unit_tests.step);
569646

570-
const run_tests_ui = b.addRunArtifact(exe);
647+
const run_tests_ui = b.addRunArtifact(editor_exe);
571648
run_tests_ui.addArgs(&.{ "--test-ui", "--headless" });
572649
run_tests_ui.step.dependOn(b.getInstallStep());
573650
const testui_step = b.step("test-ui", "Run UI headless test");
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
zig-out/bin/cetech1_test && zig-out/bin/cetech1 --asset-root fixtures/test_asset/
1+
zig-out/bin/cetech1_test && zig-out/bin/cetech1_editor --asset-root fixtures/test_asset/
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Desktop mode
2-
zig-out/bin/cetech1_test && zig-out/bin/cetech1 --asset-root fixtures/test_asset/
2+
zig-out/bin/cetech1_test && zig-out/bin/cetech1_editor --asset-root fixtures/test_asset/
33

44
# Standalone
5-
zig-out/bin/cetech1 --fullscreen --asset-root fixtures/test_asset/
5+
zig-out/bin/cetech1_editor --fullscreen --asset-root fixtures/test_asset/
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
zig-out/bin/cetech1_test.exe && zig-out/bin/cetech1.exe --asset-root fixtures/test_asset/
1+
zig-out/bin/cetech1_test.exe && zig-out/bin/cetech1_editor.exe --asset-root fixtures/test_asset/

docs/topics/getting-started.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,15 @@ CETech1 has builtin support for tracy profiler and provide Tracy as submodule, b
152152
<tab title="MacOS">
153153
<code-block lang="bash">
154154
profiler/build/tracy-profiler -a localhost
155-
zig-out/bin/cetech1 # on separate terminal
155+
zig-out/bin/cetech1_editor # on separate terminal
156156
# Have fun
157157
</code-block>
158158
</tab>
159159
<tab title="Linux">
160160
<code-block lang="bash">
161161
# install tracy by your way
162162
profiler/build/tracy-profiler -a localhost
163-
zig-out/bin/cetech1 # on separate terminal
163+
zig-out/bin/cetech1_editor # on separate terminal
164164
# Have fun
165165
</code-block>
166166
</tab>

src/main.zig renamed to src/editor/editor.zig

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ pub const std_options = std.Options{
1010

1111
pub fn main() anyerror!u8 {
1212
const descs = kernel.static_module.descs;
13-
try kernel.kernel.boot(&descs, .{});
13+
try kernel.kernel.boot(
14+
&descs,
15+
.{
16+
.ignored_modules = &.{"runner"},
17+
.ignored_modules_prefix = &.{"runner_"},
18+
},
19+
);
1420
return 0;
1521
}

src/kernel.zig

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ const BootArgs = struct {
4545
max_kernel_tick: u32 = 0,
4646
headless: bool = false,
4747
load_dynamic: bool = true,
48+
ignored_modules: ?[]const []const u8 = null,
49+
ignored_modules_prefix: ?[]const []const u8 = null,
4850
};
4951

5052
const Phase = struct {
@@ -185,7 +187,7 @@ fn setCanQuit(can_quit: *const fn () bool) void {
185187
can_quit_handler = can_quit;
186188
}
187189

188-
pub fn init(allocator: std.mem.Allocator, headless: bool) !void {
190+
pub fn init(allocator: std.mem.Allocator, headless: bool, boot_args: BootArgs) !void {
189191
_root_allocator = allocator;
190192
_main_profiler_allocator = profiler.AllocatorProfiler.init(&profiler_private.api, allocator, null);
191193
_kernel_allocator = _main_profiler_allocator.allocator();
@@ -223,7 +225,7 @@ pub fn init(allocator: std.mem.Allocator, headless: bool) !void {
223225
try tempalloc.init(_tmp_alocator_pool_allocator.allocator(), 256);
224226

225227
try apidb.init(_apidb_allocator.allocator());
226-
try modules.init(_modules_allocator.allocator());
228+
try modules.init(_modules_allocator.allocator(), boot_args.ignored_modules, boot_args.ignored_modules_prefix);
227229
try metrics.init(_metrics_allocator.allocator());
228230
try task.init(_task_allocator.allocator());
229231
try cdb_private.init(_cdb_allocator.allocator());
@@ -453,7 +455,7 @@ pub fn boot(static_modules: []const cetech1.modules.ModuleDesc, boot_args: BootA
453455
const renderer_profile = 1 == getIntArgs("--renderer-profile") orelse @intFromBool(is_debug);
454456

455457
// Init Kernel
456-
try init(gpa_allocator, _headless);
458+
try init(gpa_allocator, _headless, boot_args);
457459
defer deinit(gpa_allocator) catch undefined;
458460

459461
// Test args

0 commit comments

Comments
 (0)