-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.c
More file actions
171 lines (143 loc) · 4.62 KB
/
build.c
File metadata and controls
171 lines (143 loc) · 4.62 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
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
#if !defined(_WIN32) && !defined(_POSIX_C_SOURCE)
#define _POSIX_C_SOURCE 200112L
#endif
#include "config.h"
#define AVEN_IMPLEMENTATION
#include "include/aven.h"
#include "include/aven/arena.h"
#include "include/aven/build.h"
#include "include/aven/build/common.h"
#include "include/aven/io.h"
#include "include/aven/str.h"
#include "build.h"
#include <stdlib.h>
#define ARENA_SIZE (4096 * 2000)
int main(int argc, char **argv) {
void *mem = malloc(ARENA_SIZE);
if (mem == NULL) {
aven_panic("malloc failed\n");
}
AvenArena arena = aven_arena_init(mem, ARENA_SIZE);
AvenArgSlice common_args = aven_build_common_args();
AvenArgSlice libaven_args = libaven_build_args();
List(AvenArg) arg_list = aven_arena_create_list(
AvenArg,
&arena,
common_args.len + libaven_args.len
);
for (size_t i = 0; i < common_args.len; i += 1) {
list_push(arg_list) = get(common_args, i);
}
for (size_t i = 0; i < libaven_args.len; i += 1) {
list_push(arg_list) = get(libaven_args, i);
}
AvenArgSlice args = slice_list(arg_list);
AvenArgError arg_error = aven_arg_parse(
args,
argv,
argc,
aven_build_common_overview(),
aven_build_common_usage()
);
if (arg_error != 0) {
if (arg_error != AVEN_ARG_ERROR_HELP) {
return 1;
}
return 0;
}
// Directories
AvenStr root_dir = aven_str(".");
// Build the library
AvenBuildStep out_dir_step = aven_build_step_mkdir(aven_str("build_out"));
AvenBuildCommonOpts opts = aven_build_common_opts(args, &arena);
LibAvenBuildOpts libaven_opts = libaven_build_opts(args, &arena);
AvenBuildStep libaven_step = libaven_build_step(
&opts,
root_dir,
&out_dir_step,
false,
&arena
);
AvenBuildStep root_step = aven_build_step_root();
aven_build_step_add_dep(&root_step, &libaven_step, &arena);
// Build and run tests
AvenStr aven_include = libaven_build_include_path(aven_str("."), &arena);
AvenBuildStep test_dir_step = aven_build_step_mkdir(aven_str("build_test"));
Optional(AvenBuildStep) winutf8_obj_step = { .valid = libaven_opts.winutf8 };
if (winutf8_obj_step.valid) {
winutf8_obj_step.value = libaven_build_step_windres_manifest(
&opts,
root_dir,
&out_dir_step,
&arena
);
}
Optional(AvenBuildStep) winpthreads_obj_step = {
.valid = libaven_opts.winpthreads.local,
};
if (winpthreads_obj_step.valid) {
winpthreads_obj_step.value = libaven_build_step_winpthreads(
&opts,
&libaven_opts,
root_dir,
&out_dir_step,
false,
&arena
);
}
AvenBuildStep *test_obj_step_data[2];
List(AvenBuildStep *) test_obj_list = list_array(test_obj_step_data);
if (winutf8_obj_step.valid) {
list_push(test_obj_list) = &winutf8_obj_step.value;
}
if (winpthreads_obj_step.valid) {
list_push(test_obj_list) = &winpthreads_obj_step.value;
}
AvenBuildStepPtrSlice test_obj_steps = slice_list(test_obj_list);
AvenBuildStep test_step = aven_build_common_step_cc_ld_run_exe_ex(
&opts,
(AvenStrSlice){ .ptr = &aven_include, .len = 1 },
(AvenStrSlice){ 0 },
(AvenStrSlice){ 0 },
test_obj_steps,
aven_str("test.c"),
&test_dir_step,
false,
(AvenStrSlice){ 0 },
&arena
);
AvenBuildStep test_root_step = aven_build_step_root();
aven_build_step_add_dep(&test_root_step, &test_step, &arena);
// Execute the chosen build step
if (opts.clean) {
aven_build_step_clean(&root_step, arena);
aven_build_step_clean(&test_root_step, arena);
} else if (opts.test) {
if (opts.dry_run) {
aven_build_step_dry_run(&test_root_step, arena);
} else {
AvenBuildStepRunError run_error = aven_build_step_run(
&test_root_step,
arena
);
if (run_error != 0) {
aven_io_perrf("TEST FAILED: {}\n", aven_fmt_int(run_error));
return 1;
}
}
} else {
if (opts.dry_run) {
aven_build_step_dry_run(&root_step, arena);
} else {
AvenBuildStepRunError run_error = aven_build_step_run(
&root_step,
arena
);
if (run_error != 0) {
aven_io_perrf("BUILD FAILED: {}\n", aven_fmt_int(run_error));
return 1;
}
}
}
return 0;
}