-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.zig
163 lines (136 loc) · 5.93 KB
/
build.zig
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
const std = @import("std");
const Builder = std.build.Builder;
const Pkg = std.build.Pkg;
const iup_libs_path = "lib/iup";
const cd_libs_path = "lib/cd";
const im_libs_path = "lib/im";
fn addIupReference(b: *std.build.Builder, artifact: *std.build.LibExeObjStep) !void {
artifact.addIncludePath(.{
.path = iup_libs_path ++ "/include",
});
const iup_libs = .{
"iupcd", "iupgl", "iup_mglplot",
"iup", "iupcontrols", "iupimglib",
"iup_plot", "iuptuio", "iupglcontrols",
"iupim", "iup_scintilla",
};
inline for (iup_libs) |lib| {
artifact.linkSystemLibrary(lib);
}
if (artifact.target.isWindows()) {
artifact.addLibraryPath(.{ .path = iup_libs_path });
artifact.addLibraryPath(.{ .path = cd_libs_path });
var copy_libs = CopyLibrariesStep.create(b, artifact);
artifact.step.dependOn(©_libs.step);
const windows_libs = .{
"iupole", "iupgl", "zlib1",
"Gdi32", "User32", "Shell32",
"Comctl32", "Comdlg32", "Ole32",
"Advapi32",
};
inline for (windows_libs) |lib| {
artifact.linkSystemLibrary(lib);
}
artifact.subsystem = if (artifact.kind == .exe) .Windows else .Console;
}
}
pub fn build(b: *Builder) !void {
const mode = b.standardOptimizeOption(.{});
var main_tests = b.addTest(
.{
.root_source_file = .{ .path = "src/iup.zig" },
.optimize = mode,
},
);
main_tests.linkLibC();
try addIupReference(b, main_tests);
const test_step = b.step("test", "Run bindings tests");
const main_test_cmd = b.addRunArtifact(main_tests);
main_test_cmd.step.dependOn(&b.addInstallArtifact(main_tests, .{}).step);
test_step.dependOn(&main_test_cmd.step);
var @"7gui_test" = b.addTest(
.{
.name = "7gui_test",
.root_source_file = .{ .path = "src/7gui/tests.zig" },
.optimize = mode,
.main_pkg_path = .{ .path = "src" },
.link_libc = true,
},
);
try addIupReference(b, @"7gui_test");
const @"7gui_test_step" = b.step("7gui_test", "7GUI demo tests");
const @"7gui_test_cmd" = b.addRunArtifact(@"7gui_test");
@"7gui_test_cmd".step.dependOn(&b.addInstallArtifact(@"7gui_test", .{}).step);
@"7gui_test_step".dependOn(&@"7gui_test".step);
try addExample(b, "run", "IUP notepad example", "src/notepad_example.zig", mode);
try addExample(b, "tabs", "IUP tabs example", "src/tabs_example.zig", mode);
try addExample(b, "button", "IUP buttons example", "src/button_example.zig", mode);
try addExample(b, "image", "IUP image example", "src/image_example.zig", mode);
try addExample(b, "list", "IUP list example", "src/list_example.zig", mode);
try addExample(b, "tree", "IUP tree example", "src/tree_example.zig", mode);
try addExample(b, "mdi", "IUP mdi example", "src/mdi_example.zig", mode);
try addExample(b, "gauge", "IUP gauge example", "src/gauge_example.zig", mode);
try addExample(b, "counter", "7GUI Counter", "src/7gui/counter.zig", mode);
try addExample(b, "tempConv", "7GUI Temperature Converter", "src/7gui/temp_conv.zig", mode);
try addExample(b, "bookFlight", "7GUI Flight Booker", "src/7gui/book_flight.zig", mode);
try addExample(b, "timer", "7GUI Timer", "src/7gui/timer.zig", mode);
try addExample(b, "crud", "7GUI Crud", "src/7gui/crud.zig", mode);
try addExample(b, "circle", "7GUI Circle Drawer", "src/7gui/circle.zig", mode);
try addExample(b, "cells", "7GUI Cells", "src/7gui/cells.zig", mode);
}
fn addExample(b: *Builder, comptime name: []const u8, comptime description: []const u8, comptime file: []const u8, mode: std.builtin.OptimizeMode) !void {
const example = b.addExecutable(
.{
.name = name,
.optimize = mode,
.root_source_file = .{ .path = file },
.main_pkg_path = .{ .path = "src" },
.link_libc = true,
},
);
try addIupReference(b, example);
const example_cmd = b.addRunArtifact(example);
example_cmd.step.dependOn(&b.addInstallArtifact(example, .{}).step);
const example_step = b.step(name, description);
example_step.dependOn(&example_cmd.step);
}
const CopyLibrariesStep = struct {
const Self = @This();
builder: *std.build.Builder,
step: std.build.Step,
artifact: *std.build.LibExeObjStep,
pub fn create(builder: *std.build.Builder, artifact: *std.build.LibExeObjStep) *Self {
var self = builder.allocator.create(Self) catch unreachable;
self.* = .{
.builder = builder,
.step = std.build.Step.init(.{
.id = .custom,
.name = "Copy shared libraries",
.owner = builder,
.makeFn = &make,
}),
.artifact = artifact,
};
return self;
}
fn make(step: *std.build.Step, progress: *std.Progress.Node) !void {
_ = progress;
const self = @fieldParentPtr(Self, "step", step);
const full_dest_path = self.builder.getInstallPath(.bin, "");
var cwd = std.fs.cwd();
defer cwd.close();
inline for (.{ iup_libs_path, cd_libs_path, im_libs_path }) |libs_path| {
const full_src_dir = self.builder.pathFromRoot(libs_path);
var src_dir = try cwd.openIterableDir(full_src_dir, .{});
defer src_dir.close();
var dest_dir = try cwd.openIterableDir(full_dest_path, .{});
defer dest_dir.close();
var it = src_dir.iterate();
while (try it.next()) |entry| {
const extension = if (self.artifact.target.isWindows()) ".dll" else ".so";
if (!std.ascii.endsWithIgnoreCase(entry.name, extension)) continue;
_ = try std.fs.Dir.updateFile(src_dir.dir, entry.name, dest_dir.dir, entry.name, .{});
}
}
}
};