-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
134 lines (123 loc) · 5.24 KB
/
build.zig
File metadata and controls
134 lines (123 loc) · 5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
const std = @import("std");
const builtin = @import("builtin");
const ExampleData = struct {
name: []const u8,
source: []const u8,
};
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = arena.allocator();
const mod = b.addModule("autobahn", .{ .root_source_file = b.path("src/root.zig"), .target = target });
const mod_tests = b.addTest(.{ .root_module = mod });
const run_mod_tests = b.addRunArtifact(mod_tests);
const test_step = b.step("test", "Run tests");
test_step.dependOn(&run_mod_tests.step);
const ztracy_dep = b.dependency("ztracy", .{
.enable_ztracy = b.option(bool, "enable_ztracy", "Enable Tracy profile markers") orelse false,
.enable_fibers = b.option(bool, "enable_fibers", "Enable Tracy fiber support") orelse false,
.on_demand = b.option(bool, "on_demand", "Build tracy with TRACY_ON_DEMAND") orelse false,
});
const ztracy_mod = ztracy_dep.module("root");
// ======================
// ==> EXAMPLE BUILDS <==
// ======================
for (&[_]ExampleData{
.{ .name = "in_place", .source = "examples/in_place.zig" },
.{ .name = "map", .source = "examples/map.zig" },
.{ .name = "filter", .source = "examples/filter.zig" },
.{ .name = "swap", .source = "examples/swap.zig" },
// .{ .name = "pthread", .source = "examples/pthread.zig" },
}) |example| {
const exe = b.addExecutable(.{
.name = example.name,
.root_module = b.createModule(.{
.root_source_file = b.path(example.source),
.target = target,
.optimize = optimize,
.imports = &.{.{ .name = "autobahn", .module = mod }},
}),
});
exe.linkLibrary(ztracy_dep.artifact("tracy"));
exe.root_module.addImport("ztracy", ztracy_mod);
b.installArtifact(exe);
const description: []const u8 = try std.fmt.allocPrint(allocator, "Run '{s}' example.", .{example.name});
const run_name: []const u8 = try std.fmt.allocPrint(allocator, "run_{s}", .{example.name});
const run_step = b.step(run_name, description);
const run_cmd = b.addRunArtifact(exe);
run_step.dependOn(&run_cmd.step);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
}
// =================================
// ==> EMSCRIPTEN EXAMPLE BUILDS <==
// =================================
// {
// const zemscripten = @import("zemscripten");
// const web_run_step = b.step("web", "Run web build.");
// const wasm = b.addLibrary(
// .{
// .name = "zigfried",
// .root_module = mod,
// },
// );
// wasm.shared_memory = true;
// wasm.root_module.single_threaded = false;
// wasm.root_module.addImport("autobahn", mod);
//
// const install_dir: std.Build.InstallDir = .{ .custom = "web" };
//
// var emcc_flags = zemscripten.emccDefaultFlags(allocator, .{
// .optimize = optimize,
// .fsanitize = true,
// });
//
// try emcc_flags.put("-sASYNCIFY", {});
// try emcc_flags.put("-sFULL-ES3=1", {});
// try emcc_flags.put("-sUSE_GLFW=3", {});
// try emcc_flags.put("-sUSE_OFFSET_CONVERTER", {});
// try emcc_flags.put("-sTOTAL_MEMORY=3072MB", {});
// try emcc_flags.put("-pthread", {});
// try emcc_flags.put("-sPTHREAD_POOL_SIZE=navigator.hardwareConcurrency", {});
// try emcc_flags.put("-sPROXY_TO_PTHREAD", {});
// try emcc_flags.put("-sOFFSCREEN_FRAMEBUFFER=1", {});
// try emcc_flags.put("-sASSERTIONS", {});
//
// const emcc_settings = zemscripten.emccDefaultSettings(allocator, .{
// .optimize = optimize,
// .emsdk_allocator = std.heap.c_allocator,
// });
//
// const emcc_step = blk: {
// const activate_emsdk_step = zemscripten.activateEmsdkStep(b);
//
// const emsdk_dep = b.dependency("emsdk", .{});
// wasm.root_module.addIncludePath(emsdk_dep.path("upstream/emscripten/cache/sysroot/include"));
//
// const emcc_step = zemscripten.emccStep(b, wasm, .{
// .optimize = optimize,
// .flags = emcc_flags,
// .settings = emcc_settings,
// .shell_file_path = b.path("shell-files/index.html"),
// .install_dir = install_dir,
// .embed_paths = &.{.{ .src_path = "assets/" }},
// });
// emcc_step.dependOn(activate_emsdk_step);
//
// break :blk emcc_step;
// };
//
// const html_filename = try std.fmt.allocPrint(b.allocator, "{s}.html", .{wasm.name});
// const emrun_step = zemscripten.emrunStep(
// b,
// b.getInstallPath(install_dir, html_filename),
// &.{},
// );
// emrun_step.dependOn(emcc_step);
// web_run_step.dependOn(emrun_step);
// }
}