-
Notifications
You must be signed in to change notification settings - Fork 20
/
build.zig
666 lines (609 loc) · 24.5 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
const std = @import("std");
const GitRepoStep = @import("GitRepoStep.zig");
const libcbuild = @import("ziglibcbuild.zig");
const luabuild = @import("luabuild.zig");
const awkbuild = @import("awkbuild.zig");
const gnumakebuild = @import("gnumakebuild.zig");
pub fn build(b: *std.build.Builder) void {
const trace_enabled = b.option(bool, "trace", "enable libc tracing") orelse false;
{
const exe = b.addExecutable(.{
.name = "genheaders",
.root_source_file = .{ .path = "src" ++ std.fs.path.sep_str ++ "genheaders.zig" },
});
const run = b.addRunArtifact(exe);
run.addArg(b.pathFromRoot("capi.txt"));
b.step("genheaders", "Generate C Headers").dependOn(&run.step);
}
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const zig_start = libcbuild.addZigStart(b, target, optimize);
b.step("start", "").dependOn(&installArtifact(b, zig_start).step);
const libc_full_static = libcbuild.addLibc(b, .{
.variant = .full,
.link = .static,
.start = .ziglibc,
.trace = trace_enabled,
.target = target,
.optimize = optimize,
});
b.installArtifact(libc_full_static);
const libc_full_shared = libcbuild.addLibc(b, .{
.variant = .full,
.link = .shared,
.start = .ziglibc,
.trace = trace_enabled,
.target = target,
.optimize = optimize,
});
b.step("libc-full-shared", "").dependOn(&installArtifact(b, libc_full_shared).step);
// TODO: create a specs file?
// you can add -specs=file to the gcc command line to override values in the spec
const libc_only_std_static = libcbuild.addLibc(b, .{
.variant = .only_std,
.link = .static,
.start = .ziglibc,
.trace = trace_enabled,
.target = target,
.optimize = optimize,
});
b.installArtifact(libc_only_std_static);
const libc_only_std_shared = libcbuild.addLibc(b, .{
.variant = .only_std,
.link = .shared,
.start = .ziglibc,
.trace = trace_enabled,
.target = target,
.optimize = optimize,
});
b.installArtifact(libc_only_std_shared);
const libc_only_posix = libcbuild.addLibc(b, .{
.variant = .only_posix,
.link = .static,
.start = .ziglibc,
.trace = trace_enabled,
.target = target,
.optimize = optimize,
});
b.installArtifact(libc_only_posix);
const libc_only_linux = libcbuild.addLibc(b, .{
.variant = .only_linux,
.link = .static,
.start = .ziglibc,
.trace = trace_enabled,
.target = target,
.optimize = optimize,
});
b.installArtifact(libc_only_linux);
const libc_only_gnu = libcbuild.addLibc(b, .{
.variant = .only_gnu,
.link = .static,
.start = .ziglibc,
.trace = trace_enabled,
.target = target,
.optimize = optimize,
});
b.installArtifact(libc_only_gnu);
const test_step = b.step("test", "Run unit tests");
const test_env_exe = b.addExecutable(.{
.name = "testenv",
.root_source_file = .{ .path = "test" ++ std.fs.path.sep_str ++ "testenv.zig" },
.target = target,
.optimize = optimize,
});
{
const exe = addTest("hello", b, target, optimize, libc_only_std_static, zig_start);
const run_step = b.addRunArtifact(exe);
run_step.addCheck(.{ .expect_stdout_exact = "Hello\n" });
test_step.dependOn(&run_step.step);
}
{
const exe = addTest("strings", b, target, optimize, libc_only_std_static, zig_start);
const run_step = b.addRunArtifact(exe);
run_step.addCheck(.{ .expect_stdout_exact = "Success!\n" });
test_step.dependOn(&run_step.step);
}
{
const exe = addTest("fs", b, target, optimize, libc_only_std_static, zig_start);
const run_step = b.addRunArtifact(test_env_exe);
run_step.addArtifactArg(exe);
run_step.addCheck(.{ .expect_stdout_exact = "Success!\n" });
test_step.dependOn(&run_step.step);
}
{
const exe = addTest("format", b, target, optimize, libc_only_std_static, zig_start);
const run_step = b.addRunArtifact(test_env_exe);
run_step.addArtifactArg(exe);
run_step.addCheck(.{ .expect_stdout_exact = "Success!\n" });
test_step.dependOn(&run_step.step);
}
{
const exe = addTest("types", b, target, optimize, libc_only_std_static, zig_start);
const run_step = b.addRunArtifact(exe);
run_step.addArg(b.fmt("{}", .{@divExact(target.toTarget().ptrBitWidth(), 8)}));
run_step.addCheck(.{ .expect_stdout_exact = "Success!\n" });
test_step.dependOn(&run_step.step);
}
{
const exe = addTest("scanf", b, target, optimize, libc_only_std_static, zig_start);
const run_step = b.addRunArtifact(exe);
run_step.addCheck(.{ .expect_stdout_exact = "Success!\n" });
test_step.dependOn(&run_step.step);
}
{
const exe = addTest("strto", b, target, optimize, libc_only_std_static, zig_start);
const run_step = b.addRunArtifact(exe);
run_step.addCheck(.{ .expect_stdout_exact = "Success!\n" });
test_step.dependOn(&run_step.step);
}
{
const exe = addTest("getopt", b, target, optimize, libc_only_std_static, zig_start);
addPosix(exe, libc_only_posix);
{
const run = b.addRunArtifact(exe);
run.addCheck(.{ .expect_stdout_exact = "aflag=0, c_arg='(null)'\n" });
test_step.dependOn(&run.step);
}
{
const run = b.addRunArtifact(exe);
run.addArgs(&.{"-a"});
run.addCheck(.{ .expect_stdout_exact = "aflag=1, c_arg='(null)'\n" });
test_step.dependOn(&run.step);
}
{
const run = b.addRunArtifact(exe);
run.addArgs(&.{ "-c", "hello" });
run.addCheck(.{ .expect_stdout_exact = "aflag=0, c_arg='hello'\n" });
test_step.dependOn(&run.step);
}
}
// this test only works on linux right now
if (target.getOsTag() == .linux) {
const exe = addTest("jmp", b, target, optimize, libc_only_std_static, zig_start);
const run_step = b.addRunArtifact(exe);
run_step.addCheck(.{ .expect_stdout_exact = "Success!\n" });
test_step.dependOn(&run_step.step);
}
addLibcTest(b, target, optimize, libc_only_std_static, zig_start, libc_only_posix);
addTinyRegexCTests(b, target, optimize, libc_only_std_static, zig_start, libc_only_posix);
_ = addLua(b, target, optimize, libc_only_std_static, libc_only_posix, zig_start);
_ = addCmph(b, target, optimize, libc_only_std_static, zig_start, libc_only_posix);
_ = addYacc(b, target, optimize, libc_only_std_static, zig_start, libc_only_posix);
_ = addYabfc(b, target, optimize, libc_only_std_static, zig_start, libc_only_posix, libc_only_gnu);
_ = addSecretGame(b, target, optimize, libc_only_std_static, zig_start, libc_only_posix, libc_only_gnu);
_ = awkbuild.addAwk(b, target, optimize, libc_only_std_static, libc_only_posix, zig_start);
_ = gnumakebuild.addGnuMake(b, target, optimize, libc_only_std_static, libc_only_posix, zig_start);
_ = @import("busybox/build.zig").add(b, target, optimize, libc_only_std_static, libc_only_posix);
_ = @import("ncurses/build.zig").add(b, target, optimize, libc_only_std_static, libc_only_posix);
}
// re-implements Build.installArtifact but also returns it
fn installArtifact(b: *std.Build, artifact: anytype) *std.Build.Step.InstallArtifact {
const install = b.addInstallArtifact(artifact, .{});
b.getInstallStep().dependOn(&install.step);
return install;
}
fn addPosix(artifact: *std.build.LibExeObjStep, zig_posix: *std.build.LibExeObjStep) void {
artifact.linkLibrary(zig_posix);
artifact.addIncludePath(.{ .path = "inc" ++ std.fs.path.sep_str ++ "posix" });
}
fn addTest(
comptime name: []const u8,
b: *std.build.Builder,
target: anytype,
optimize: anytype,
libc_only_std_static: *std.build.LibExeObjStep,
zig_start: *std.build.LibExeObjStep,
) *std.build.LibExeObjStep {
const exe = b.addExecutable(.{
.name = name,
.root_source_file = .{ .path = "test" ++ std.fs.path.sep_str ++ name ++ ".c" },
.target = target,
.optimize = optimize,
});
exe.addCSourceFiles(&.{"test" ++ std.fs.path.sep_str ++ "expect.c"}, &[_][]const u8{});
exe.addIncludePath(.{ .path = "inc" ++ std.fs.path.sep_str ++ "libc" });
exe.addIncludePath(.{ .path = "inc" ++ std.fs.path.sep_str ++ "posix" });
exe.linkLibrary(libc_only_std_static);
exe.linkLibrary(zig_start);
// TODO: should libc_only_std_static and zig_start be able to add library dependencies?
if (target.getOs().tag == .windows) {
exe.linkSystemLibrary("ntdll");
exe.linkSystemLibrary("kernel32");
}
return exe;
}
fn addLibcTest(
b: *std.build.Builder,
target: anytype,
optimize: anytype,
libc_only_std_static: *std.build.LibExeObjStep,
zig_start: *std.build.LibExeObjStep,
libc_only_posix: *std.build.LibExeObjStep,
) void {
const libc_test_repo = GitRepoStep.create(b, .{
.url = "git://nsz.repo.hu:49100/repo/libc-test",
.sha = "b7ec467969a53756258778fa7d9b045f912d1c93",
.branch = null,
.fetch_enabled = true,
});
const libc_test_path = libc_test_repo.path;
const libc_test_step = b.step("libc-test", "run tests from the libc-test project");
// inttypes
inline for (.{ "assert", "ctype", "errno", "main", "stdbool", "stddef", "string" }) |name| {
const lib = b.addObject(.{
.name = "libc-test-api-" ++ name,
.root_source_file = .{ .path = b.pathJoin(&.{ libc_test_path, "src", "api", name ++ ".c" }) },
.target = target,
.optimize = optimize,
});
lib.addIncludePath(.{ .path = "inc" ++ std.fs.path.sep_str ++ "libc" });
lib.step.dependOn(&libc_test_repo.step);
libc_test_step.dependOn(&lib.step);
}
const libc_inc_path = b.pathJoin(&.{ libc_test_path, "src", "common" });
const common_src = &[_][]const u8{
b.pathJoin(&.{ libc_test_path, "src", "common", "print.c" }),
};
// strtol, it seems there might be some disagreement between libc-test/glibc
// about how strtoul interprets negative numbers, so leaving out strtol for now
inline for (.{ "argv", "basename", "clock_gettime", "string" }) |name| {
const exe = b.addExecutable(.{
.name = "libc-test-functional-" ++ name,
.root_source_file = .{ .path = b.pathJoin(&.{ libc_test_path, "src", "functional", name ++ ".c" }) },
.target = target,
.optimize = optimize,
});
exe.addCSourceFiles(common_src, &[_][]const u8{});
exe.step.dependOn(&libc_test_repo.step);
exe.addIncludePath(.{ .path = libc_inc_path });
exe.addIncludePath(.{ .path = "inc" ++ std.fs.path.sep_str ++ "libc" });
exe.addIncludePath(.{ .path = "inc" ++ std.fs.path.sep_str ++ "posix" });
exe.linkLibrary(libc_only_std_static);
exe.linkLibrary(zig_start);
exe.linkLibrary(libc_only_posix);
// TODO: should libc_only_std_static and zig_start be able to add library dependencies?
if (target.getOs().tag == .windows) {
exe.linkSystemLibrary("ntdll");
exe.linkSystemLibrary("kernel32");
}
libc_test_step.dependOn(&b.addRunArtifact(exe).step);
}
}
fn addTinyRegexCTests(
b: *std.build.Builder,
target: anytype,
optimize: anytype,
libc_only_std_static: *std.build.LibExeObjStep,
zig_start: *std.build.LibExeObjStep,
zig_posix: *std.build.LibExeObjStep,
) void {
const repo = GitRepoStep.create(b, .{
.url = "https://github.com/marler8997/tiny-regex-c",
.sha = "95ef2ad35d36783d789b0ade3178b30a942f085c",
.branch = "nocompile",
.fetch_enabled = true,
});
const re_step = b.step("re-tests", "run the tiny-regex-c tests");
inline for (&[_][]const u8{ "test1", "test3" }) |test_name| {
const exe = b.addExecutable(.{
.name = "re" ++ test_name,
.root_source_file = null,
.target = target,
.optimize = optimize,
});
//b.installArtifact(exe);
exe.step.dependOn(&repo.step);
const repo_path = repo.getPath(&exe.step);
var files = std.ArrayList([]const u8).init(b.allocator);
const sources = [_][]const u8{
"re.c", "tests" ++ std.fs.path.sep_str ++ test_name ++ ".c",
};
for (sources) |src| {
files.append(b.pathJoin(&.{ repo_path, src })) catch unreachable;
}
exe.addCSourceFiles(files.toOwnedSlice() catch unreachable, &[_][]const u8{
"-std=c99",
});
exe.addIncludePath(.{ .path = repo_path });
exe.addIncludePath(.{ .path = "inc/libc" });
exe.addIncludePath(.{ .path = "inc/posix" });
exe.linkLibrary(libc_only_std_static);
exe.linkLibrary(zig_start);
exe.linkLibrary(zig_posix);
// TODO: should libc_only_std_static and zig_start be able to add library dependencies?
if (target.getOs().tag == .windows) {
exe.linkSystemLibrary("ntdll");
exe.linkSystemLibrary("kernel32");
}
//const step = b.step("re", "build the re (tiny-regex-c) tool");
//step.dependOn(&exe.install_step.?.step);
const run = b.addRunArtifact(exe);
re_step.dependOn(&run.step);
}
}
fn addLua(
b: *std.build.Builder,
target: anytype,
optimize: anytype,
libc_only_std_static: *std.build.LibExeObjStep,
libc_only_posix: *std.build.LibExeObjStep,
zig_start: *std.build.LibExeObjStep,
) *std.build.LibExeObjStep {
const lua_repo = GitRepoStep.create(b, .{
.url = "https://github.com/lua/lua",
.sha = "5d708c3f9cae12820e415d4f89c9eacbe2ab964b",
.branch = "v5.4.4",
.fetch_enabled = true,
});
const lua_exe = b.addExecutable(.{
.name = "lua",
.target = target,
.optimize = optimize,
});
lua_exe.step.dependOn(&lua_repo.step);
const install = b.addInstallArtifact(lua_exe, .{});
// doesn't compile for windows for some reason
if (target.getOs().tag != .windows) {
b.getInstallStep().dependOn(&install.step);
}
const lua_repo_path = lua_repo.getPath(&lua_exe.step);
var files = std.ArrayList([]const u8).init(b.allocator);
files.append(b.pathJoin(&.{ lua_repo_path, "lua.c" })) catch unreachable;
inline for (luabuild.core_objects) |obj| {
files.append(b.pathJoin(&.{ lua_repo_path, obj ++ ".c" })) catch unreachable;
}
inline for (luabuild.aux_objects) |obj| {
files.append(b.pathJoin(&.{ lua_repo_path, obj ++ ".c" })) catch unreachable;
}
inline for (luabuild.lib_objects) |obj| {
files.append(b.pathJoin(&.{ lua_repo_path, obj ++ ".c" })) catch unreachable;
}
lua_exe.addCSourceFiles(files.toOwnedSlice() catch unreachable, &[_][]const u8{
"-nostdinc",
"-nostdlib",
"-std=c99",
});
lua_exe.addIncludePath(.{ .path = "inc" ++ std.fs.path.sep_str ++ "libc" });
lua_exe.linkLibrary(libc_only_std_static);
lua_exe.linkLibrary(libc_only_posix);
lua_exe.linkLibrary(zig_start);
// TODO: should libc_only_std_static and zig_start be able to add library dependencies?
if (target.getOs().tag == .windows) {
lua_exe.addIncludePath(.{ .path = "inc/win32" });
lua_exe.linkSystemLibrary("ntdll");
lua_exe.linkSystemLibrary("kernel32");
}
const step = b.step("lua", "build/install the LUA interpreter");
step.dependOn(&install.step);
const test_step = b.step("lua-test", "Run the lua tests");
for ([_][]const u8{ "bwcoercion.lua", "tracegc.lua" }) |test_file| {
var run_test = b.addRunArtifact(lua_exe);
run_test.addArg(b.pathJoin(&.{ lua_repo_path, "testes", test_file }));
test_step.dependOn(&run_test.step);
}
return lua_exe;
}
fn addCmph(
b: *std.build.Builder,
target: anytype,
optimize: anytype,
libc_only_std_static: *std.build.LibExeObjStep,
zig_start: *std.build.LibExeObjStep,
zig_posix: *std.build.LibExeObjStep,
) *std.build.LibExeObjStep {
const repo = GitRepoStep.create(b, .{
//.url = "https://git.code.sf.net/p/cmph/git",
.url = "https://github.com/bonitao/cmph",
.sha = "abd5e1e17e4d51b3e24459ab9089dc0522846d0d",
.branch = null,
.fetch_enabled = true,
});
const config_step = b.addWriteFile(
b.pathJoin(&.{ repo.path, "src", "config.h" }),
"#define VERSION \"1.0\"",
);
config_step.step.dependOn(&repo.step);
const exe = b.addExecutable(.{
.name = "cmph",
.target = target,
.optimize = optimize,
});
const install = installArtifact(b, exe);
exe.step.dependOn(&repo.step);
exe.step.dependOn(&config_step.step);
const repo_path = repo.getPath(&exe.step);
var files = std.ArrayList([]const u8).init(b.allocator);
const sources = [_][]const u8{
"main.c", "cmph.c", "hash.c", "chm.c", "bmz.c", "bmz8.c", "brz.c", "fch.c",
"bdz.c", "bdz_ph.c", "chd_ph.c", "chd.c", "jenkins_hash.c", "graph.c", "vqueue.c", "buffer_manager.c",
"fch_buckets.c", "miller_rabin.c", "compressed_seq.c", "compressed_rank.c", "buffer_entry.c", "select.c", "cmph_structs.c",
};
for (sources) |src| {
files.append(b.pathJoin(&.{ repo_path, "src", src })) catch unreachable;
}
exe.addCSourceFiles(files.toOwnedSlice() catch unreachable, &[_][]const u8{
"-std=c11",
});
exe.addIncludePath(.{ .path = "inc/libc" });
exe.addIncludePath(.{ .path = "inc/posix" });
exe.addIncludePath(.{ .path = "inc/gnu" });
exe.linkLibrary(libc_only_std_static);
exe.linkLibrary(zig_start);
exe.linkLibrary(zig_posix);
// TODO: should libc_only_std_static and zig_start be able to add library dependencies?
if (target.getOs().tag == .windows) {
exe.linkSystemLibrary("ntdll");
exe.linkSystemLibrary("kernel32");
}
const step = b.step("cmph", "build the cmph tool");
step.dependOn(&install.step);
return exe;
}
fn addYacc(
b: *std.build.Builder,
target: anytype,
optimize: anytype,
libc_only_std_static: *std.build.LibExeObjStep,
zig_start: *std.build.LibExeObjStep,
zig_posix: *std.build.LibExeObjStep,
) *std.build.LibExeObjStep {
const repo = GitRepoStep.create(b, .{
.url = "https://github.com/ibara/yacc",
.sha = "1a4138ce2385ec676c6d374245fda5a9cd2fbee2",
.branch = null,
.fetch_enabled = true,
});
const config_step = b.addWriteFile(b.pathJoin(&.{ repo.path, "config.h" }),
\\// for simplicity just don't supported __unused
\\#define __unused
\\// for simplicity we're just not supporting noreturn
\\#define __dead
\\//#define HAVE_PROGNAME
\\//#define HAVE_ASPRINTF
\\//#define HAVE_PLEDGE
\\//#define HAVE_REALLOCARRAY
\\#define HAVE_STRLCPY
\\
);
config_step.step.dependOn(&repo.step);
const gen_progname_step = b.addWriteFile(b.pathJoin(&.{ repo.path, "progname.c" }),
\\// workaround __progname not defined, https://github.com/ibara/yacc/pull/1
\\char *__progname;
\\
);
gen_progname_step.step.dependOn(&repo.step);
const exe = b.addExecutable(.{
.name = "yacc",
.target = target,
.optimize = optimize,
});
const install = installArtifact(b, exe);
exe.step.dependOn(&repo.step);
exe.step.dependOn(&config_step.step);
exe.step.dependOn(&gen_progname_step.step);
const repo_path = repo.getPath(&exe.step);
var files = std.ArrayList([]const u8).init(b.allocator);
const sources = [_][]const u8{
"closure.c", "error.c", "lalr.c", "lr0.c", "main.c", "mkpar.c", "output.c", "reader.c",
"skeleton.c", "symtab.c", "verbose.c", "warshall.c", "portable.c", "progname.c",
};
for (sources) |src| {
files.append(b.pathJoin(&.{ repo_path, src })) catch unreachable;
}
exe.addCSourceFiles(files.toOwnedSlice() catch unreachable, &[_][]const u8{
"-std=c90",
});
exe.addIncludePath(.{ .path = "inc/libc" });
exe.addIncludePath(.{ .path = "inc/posix" });
exe.linkLibrary(libc_only_std_static);
exe.linkLibrary(zig_start);
exe.linkLibrary(zig_posix);
// TODO: should libc_only_std_static and zig_start be able to add library dependencies?
if (target.getOs().tag == .windows) {
exe.linkSystemLibrary("ntdll");
exe.linkSystemLibrary("kernel32");
}
const step = b.step("yacc", "build the yacc tool");
step.dependOn(&install.step);
return exe;
}
fn addYabfc(
b: *std.build.Builder,
target: anytype,
optimize: anytype,
libc_only_std_static: *std.build.LibExeObjStep,
zig_start: *std.build.LibExeObjStep,
zig_posix: *std.build.LibExeObjStep,
zig_gnu: *std.build.LibExeObjStep,
) *std.build.LibExeObjStep {
const repo = GitRepoStep.create(b, .{
.url = "https://github.com/julianneswinoga/yabfc",
.sha = "a789be25a0918d330b7a4de12db0d33e0785f244",
.branch = null,
.fetch_enabled = true,
});
const exe = b.addExecutable(.{
.name = "yabfc",
.target = target,
.optimize = optimize,
});
const install = installArtifact(b, exe);
exe.step.dependOn(&repo.step);
const repo_path = repo.getPath(&exe.step);
var files = std.ArrayList([]const u8).init(b.allocator);
const sources = [_][]const u8{
"assembly.c", "elfHelper.c", "helpers.c", "optimize.c", "yabfc.c",
};
for (sources) |src| {
files.append(b.pathJoin(&.{ repo_path, src })) catch unreachable;
}
exe.addCSourceFiles(files.toOwnedSlice() catch unreachable, &[_][]const u8{
"-std=c99",
});
exe.addIncludePath(.{ .path = "inc/libc" });
exe.addIncludePath(.{ .path = "inc/posix" });
exe.addIncludePath(.{ .path = "inc/linux" });
exe.addIncludePath(.{ .path = "inc/gnu" });
exe.linkLibrary(libc_only_std_static);
exe.linkLibrary(zig_start);
exe.linkLibrary(zig_posix);
exe.linkLibrary(zig_gnu);
// TODO: should libc_only_std_static and zig_start be able to add library dependencies?
if (target.getOs().tag == .windows) {
exe.linkSystemLibrary("ntdll");
exe.linkSystemLibrary("kernel32");
}
const step = b.step("yabfc", "build/install the yabfc tool (Yet Another BrainFuck Compiler)");
step.dependOn(&install.step);
return exe;
}
fn addSecretGame(
b: *std.build.Builder,
target: anytype,
optimize: anytype,
libc_only_std_static: *std.build.LibExeObjStep,
zig_start: *std.build.LibExeObjStep,
zig_posix: *std.build.LibExeObjStep,
zig_gnu: *std.build.LibExeObjStep,
) *std.build.LibExeObjStep {
const repo = GitRepoStep.create(b, .{
.url = "https://github.com/ethinethin/Secret",
.sha = "8ec8442f84f8bed2cb3985455e7af4d1ce605401",
.branch = null,
.fetch_enabled = true,
});
const exe = b.addExecutable(.{
.name = "secret",
.target = target,
.optimize = optimize,
});
const install = b.addInstallArtifact(exe, .{});
exe.step.dependOn(&repo.step);
const repo_path = repo.getPath(&exe.step);
var files = std.ArrayList([]const u8).init(b.allocator);
const sources = [_][]const u8{
"main.c", "inter.c", "input.c", "items.c", "rooms.c", "linenoise/linenoise.c",
};
for (sources) |src| {
files.append(b.pathJoin(&.{ repo_path, src })) catch unreachable;
}
exe.addCSourceFiles(files.toOwnedSlice() catch unreachable, &[_][]const u8{
"-std=c90",
});
exe.addIncludePath(.{ .path = "inc/libc" });
exe.addIncludePath(.{ .path = "inc/posix" });
exe.addIncludePath(.{ .path = "inc/linux" });
exe.addIncludePath(.{ .path = "inc/gnu" });
exe.linkLibrary(libc_only_std_static);
exe.linkLibrary(zig_start);
exe.linkLibrary(zig_posix);
exe.linkLibrary(zig_gnu);
// TODO: should libc_only_std_static and zig_start be able to add library dependencies?
if (target.getOs().tag == .windows) {
exe.linkSystemLibrary("ntdll");
exe.linkSystemLibrary("kernel32");
}
const step = b.step("secret", "build/install the secret game");
step.dependOn(&install.step);
return exe;
}