@shd101wyy/yo 0.1.11 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -1
- package/out/cjs/index.cjs +579 -573
- package/out/cjs/yo-cli.cjs +1413 -592
- package/out/esm/index.mjs +437 -431
- package/out/types/src/build-runner.d.ts +1 -1
- package/out/types/src/doc/builder.d.ts +21 -0
- package/out/types/src/doc/builder.test.d.ts +1 -0
- package/out/types/src/doc/extractor.d.ts +27 -0
- package/out/types/src/doc/extractor.test.d.ts +1 -0
- package/out/types/src/doc/model.d.ts +87 -0
- package/out/types/src/doc/render-html.d.ts +23 -0
- package/out/types/src/doc/render-html.test.d.ts +1 -0
- package/out/types/src/doc/render-json.d.ts +7 -0
- package/out/types/src/doc/render-json.test.d.ts +1 -0
- package/out/types/src/doc/render-markdown.d.ts +13 -0
- package/out/types/src/doc/render-markdown.test.d.ts +1 -0
- package/out/types/src/doc/sections.d.ts +7 -0
- package/out/types/src/doc/sections.test.d.ts +1 -0
- package/out/types/src/doc-command.d.ts +10 -0
- package/out/types/src/env.d.ts +1 -0
- package/out/types/src/evaluator/builtins/build.d.ts +17 -0
- package/out/types/src/evaluator/context.d.ts +1 -0
- package/out/types/src/evaluator/exprs/import.d.ts +2 -0
- package/out/types/src/expr.d.ts +2 -1
- package/out/types/src/tests/import-path.test.d.ts +1 -0
- package/out/types/src/token.d.ts +4 -0
- package/out/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -1
- package/scripts/build-site.ts +461 -0
- package/std/alg/hash.yo +12 -24
- package/std/allocator.yo +21 -29
- package/std/async.yo +4 -2
- package/std/build.yo +188 -42
- package/std/cli/arg_parser.yo +37 -1
- package/std/collections/array_list.yo +8 -20
- package/std/collections/btree_map.yo +15 -20
- package/std/collections/deque.yo +13 -15
- package/std/collections/hash_map.yo +15 -54
- package/std/collections/hash_set.yo +14 -50
- package/std/collections/linked_list.yo +6 -23
- package/std/collections/priority_queue.yo +15 -17
- package/std/crypto/md5.yo +10 -9
- package/std/crypto/random.yo +14 -12
- package/std/crypto/sha256.yo +9 -8
- package/std/encoding/base64.yo +13 -15
- package/std/encoding/hex.yo +14 -10
- package/std/encoding/html.yo +14 -11
- package/std/encoding/html_char_utils.yo +14 -11
- package/std/encoding/html_entities.yo +7 -8
- package/std/encoding/json.yo +36 -19
- package/std/encoding/punycode.yo +21 -18
- package/std/encoding/toml.yo +23 -9
- package/std/encoding/utf16.yo +16 -9
- package/std/error.yo +10 -23
- package/std/fmt/display.yo +15 -17
- package/std/fmt/index.yo +6 -27
- package/std/fmt/to_string.yo +4 -10
- package/std/fmt/writer.yo +33 -34
- package/std/fs/dir.yo +37 -30
- package/std/fs/file.yo +77 -75
- package/std/fs/metadata.yo +25 -25
- package/std/fs/temp.yo +21 -27
- package/std/fs/types.yo +20 -23
- package/std/fs/walker.yo +26 -31
- package/std/gc.yo +5 -0
- package/std/glob/index.yo +3 -0
- package/std/http/client.yo +25 -11
- package/std/http/http.yo +20 -0
- package/std/http/index.yo +1 -0
- package/std/io/reader.yo +4 -8
- package/std/io/writer.yo +4 -7
- package/std/libc/assert.yo +2 -2
- package/std/libc/ctype.yo +1 -2
- package/std/libc/dirent.yo +1 -2
- package/std/libc/errno.yo +1 -2
- package/std/libc/fcntl.yo +2 -2
- package/std/libc/float.yo +1 -2
- package/std/libc/limits.yo +1 -2
- package/std/libc/math.yo +2 -0
- package/std/libc/signal.yo +1 -2
- package/std/libc/stdatomic.yo +1 -2
- package/std/libc/stdint.yo +4 -3
- package/std/libc/stdio.yo +2 -0
- package/std/libc/stdlib.yo +2 -0
- package/std/libc/string.yo +2 -0
- package/std/libc/sys/stat.yo +1 -2
- package/std/libc/time.yo +2 -2
- package/std/libc/unistd.yo +2 -0
- package/std/libc/wctype.yo +1 -2
- package/std/libc/windows.yo +2 -2
- package/std/log/index.yo +11 -26
- package/std/net/addr.yo +18 -11
- package/std/net/dns.yo +3 -2
- package/std/net/errors.yo +16 -2
- package/std/net/tcp.yo +25 -22
- package/std/net/udp.yo +14 -12
- package/std/os/env.yo +23 -18
- package/std/os/signal.yo +31 -19
- package/std/path.yo +23 -74
- package/std/prelude.yo +284 -113
- package/std/process.yo +23 -37
- package/std/regex/compiler.yo +3 -5
- package/std/regex/flags.yo +11 -11
- package/std/regex/index.yo +2 -13
- package/std/regex/match.yo +3 -5
- package/std/regex/node.yo +6 -6
- package/std/regex/parser.yo +2 -4
- package/std/regex/unicode.yo +5 -5
- package/std/regex/vm.yo +5 -5
- package/std/string/index.yo +2 -1
- package/std/string/rune.yo +25 -1
- package/std/string/string.yo +31 -19
- package/std/string/unicode.yo +14 -15
- package/std/sync/channel.yo +18 -28
- package/std/sync/cond.yo +4 -0
- package/std/sync/mutex.yo +4 -1
- package/std/sync/once.yo +17 -19
- package/std/sync/rwlock.yo +19 -22
- package/std/sync/waitgroup.yo +21 -23
- package/std/sys/advise.yo +4 -4
- package/std/sys/bufio/buf_reader.yo +19 -16
- package/std/sys/bufio/buf_writer.yo +14 -11
- package/std/sys/clock.yo +4 -4
- package/std/sys/constants.yo +5 -5
- package/std/sys/copy.yo +9 -8
- package/std/sys/dir.yo +9 -8
- package/std/sys/dns.yo +8 -8
- package/std/sys/errors.yo +35 -6
- package/std/sys/events.yo +3 -3
- package/std/sys/externs.yo +3 -3
- package/std/sys/fallocate.yo +4 -4
- package/std/sys/fcntl.yo +8 -6
- package/std/sys/file.yo +7 -8
- package/std/sys/future.yo +1 -3
- package/std/sys/iov.yo +4 -4
- package/std/sys/lock.yo +7 -7
- package/std/sys/mmap.yo +7 -8
- package/std/sys/path.yo +4 -7
- package/std/sys/perm.yo +8 -8
- package/std/sys/pipe.yo +9 -8
- package/std/sys/process.yo +8 -8
- package/std/sys/seek.yo +4 -4
- package/std/sys/signal.yo +4 -4
- package/std/sys/signals.yo +4 -4
- package/std/sys/socket.yo +4 -4
- package/std/sys/socketpair.yo +4 -4
- package/std/sys/sockinfo.yo +4 -4
- package/std/sys/statfs.yo +8 -8
- package/std/sys/statx.yo +4 -4
- package/std/sys/sysinfo.yo +4 -4
- package/std/sys/tcp.yo +8 -8
- package/std/sys/temp.yo +9 -8
- package/std/sys/time.yo +8 -8
- package/std/sys/timer.yo +7 -8
- package/std/sys/tty.yo +13 -10
- package/std/sys/udp.yo +8 -8
- package/std/sys/umask.yo +4 -4
- package/std/sys/unix.yo +5 -5
- package/std/testing/bench.yo +21 -10
- package/std/thread.yo +18 -9
- package/std/time/datetime.yo +12 -14
- package/std/time/duration.yo +12 -14
- package/std/time/instant.yo +13 -16
- package/std/time/sleep.yo +9 -8
- package/std/url/index.yo +3 -19
- package/std/worker.yo +10 -18
package/std/build.yo
CHANGED
|
@@ -1,45 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
//! Declarative build API for Yo projects.
|
|
2
|
+
//!
|
|
3
|
+
//! All functions are compile-time only — they register build artifacts
|
|
4
|
+
//! and steps that the build runner uses to orchestrate compilation.
|
|
5
|
+
//!
|
|
6
|
+
//! # Example
|
|
7
|
+
//!
|
|
8
|
+
//! ```rust
|
|
9
|
+
//! build :: import "std/build";
|
|
10
|
+
//!
|
|
11
|
+
//! mod :: build.module({ name: "my-lib", root: "./src/lib.yo" });
|
|
12
|
+
//! exe :: build.executable({ name: "my-app", root: "./src/main.yo" });
|
|
13
|
+
//! install :: build.step("install", "Build all artifacts");
|
|
14
|
+
//! install.depend_on(exe);
|
|
15
|
+
//! ```
|
|
13
16
|
|
|
14
17
|
// ── Optimization levels ──────────────────────────────────────────────
|
|
15
18
|
|
|
19
|
+
/// Optimization level for compiled artifacts.
|
|
16
20
|
Optimize :: enum(
|
|
21
|
+
/// No optimizations, full debug info.
|
|
17
22
|
Debug,
|
|
23
|
+
/// Optimized with safety checks.
|
|
18
24
|
ReleaseSafe,
|
|
25
|
+
/// Maximum speed optimizations.
|
|
19
26
|
ReleaseFast,
|
|
27
|
+
/// Optimize for binary size.
|
|
20
28
|
ReleaseSmall
|
|
21
29
|
);
|
|
22
30
|
export Optimize;
|
|
23
31
|
|
|
24
32
|
// ── Memory allocators ────────────────────────────────────────────────
|
|
25
33
|
|
|
34
|
+
/// Memory allocator to use in the compiled artifact.
|
|
26
35
|
Allocator :: enum(
|
|
36
|
+
/// High-performance allocator (mimalloc).
|
|
27
37
|
Mimalloc,
|
|
38
|
+
/// Standard C library malloc.
|
|
28
39
|
Libc
|
|
29
40
|
);
|
|
30
41
|
export Allocator;
|
|
31
42
|
|
|
32
43
|
// ── Sanitizers ───────────────────────────────────────────────────────
|
|
33
44
|
|
|
45
|
+
/// Runtime sanitizer to enable.
|
|
34
46
|
Sanitize :: enum(
|
|
47
|
+
/// No sanitizer.
|
|
35
48
|
None,
|
|
49
|
+
/// AddressSanitizer — detects memory errors and leaks.
|
|
36
50
|
Address,
|
|
51
|
+
/// LeakSanitizer — detects memory leaks only.
|
|
37
52
|
Leak
|
|
38
53
|
);
|
|
39
54
|
export Sanitize;
|
|
40
55
|
|
|
41
56
|
// ── Step kinds ───────────────────────────────────────────────────────
|
|
42
57
|
|
|
58
|
+
/// Kind of build step.
|
|
43
59
|
StepKind :: enum(
|
|
44
60
|
Executable,
|
|
45
61
|
StaticLibrary,
|
|
@@ -47,7 +63,8 @@ StepKind :: enum(
|
|
|
47
63
|
SystemLibrary,
|
|
48
64
|
TestSuite,
|
|
49
65
|
Run,
|
|
50
|
-
Custom
|
|
66
|
+
Custom,
|
|
67
|
+
Documentation
|
|
51
68
|
);
|
|
52
69
|
export StepKind;
|
|
53
70
|
|
|
@@ -68,89 +85,118 @@ export CompilationTarget;
|
|
|
68
85
|
|
|
69
86
|
// ── Target utilities ─────────────────────────────────────────────────
|
|
70
87
|
|
|
88
|
+
/// Host compilation target string.
|
|
71
89
|
target_host :: __yo_build_target_host();
|
|
72
90
|
export target_host;
|
|
73
91
|
|
|
74
92
|
// ── Config struct types ──────────────────────────────────────────────
|
|
75
|
-
// Struct types with defaults, like Zig's options structs.
|
|
76
|
-
// Usage: build.executable({ name: "app", root: "./src/main.yo" })
|
|
77
|
-
// Unspecified fields get their default values.
|
|
78
93
|
|
|
94
|
+
/// Configuration for building an executable.
|
|
79
95
|
Executable :: struct(
|
|
96
|
+
/// Artifact name.
|
|
80
97
|
name : comptime_string,
|
|
98
|
+
/// Root source file.
|
|
81
99
|
root : comptime_string,
|
|
100
|
+
/// Compilation target triple (defaults to host).
|
|
82
101
|
(target : comptime_string) ?= __yo_build_target_host(),
|
|
102
|
+
/// Optimization level.
|
|
83
103
|
(optimize : Optimize) ?= Optimize.Debug,
|
|
104
|
+
/// Memory allocator.
|
|
84
105
|
(allocator : Allocator) ?= Allocator.Libc,
|
|
106
|
+
/// Runtime sanitizer.
|
|
85
107
|
(sanitize : Sanitize) ?= Sanitize.None
|
|
86
108
|
);
|
|
87
109
|
export Executable;
|
|
88
110
|
|
|
111
|
+
/// Configuration for building a static library.
|
|
89
112
|
StaticLibrary :: struct(
|
|
113
|
+
/// Artifact name.
|
|
90
114
|
name : comptime_string,
|
|
115
|
+
/// Root source file.
|
|
91
116
|
root : comptime_string,
|
|
117
|
+
/// Compilation target triple (defaults to host).
|
|
92
118
|
(target : comptime_string) ?= __yo_build_target_host(),
|
|
119
|
+
/// Optimization level.
|
|
93
120
|
(optimize : Optimize) ?= Optimize.Debug
|
|
94
121
|
);
|
|
95
122
|
export StaticLibrary;
|
|
96
123
|
|
|
124
|
+
/// Configuration for building a shared/dynamic library.
|
|
97
125
|
SharedLibrary :: struct(
|
|
126
|
+
/// Artifact name.
|
|
98
127
|
name : comptime_string,
|
|
128
|
+
/// Root source file.
|
|
99
129
|
root : comptime_string,
|
|
130
|
+
/// Compilation target triple (defaults to host).
|
|
100
131
|
(target : comptime_string) ?= __yo_build_target_host(),
|
|
132
|
+
/// Optimization level.
|
|
101
133
|
(optimize : Optimize) ?= Optimize.Debug
|
|
102
134
|
);
|
|
103
135
|
export SharedLibrary;
|
|
104
136
|
|
|
137
|
+
/// Configuration for a test suite.
|
|
105
138
|
TestSuite :: struct(
|
|
139
|
+
/// Suite name.
|
|
106
140
|
name : comptime_string,
|
|
141
|
+
/// Root test file.
|
|
107
142
|
root : comptime_string,
|
|
143
|
+
/// Compilation target triple (defaults to host).
|
|
108
144
|
(target : comptime_string) ?= __yo_build_target_host()
|
|
109
145
|
);
|
|
110
146
|
export TestSuite;
|
|
111
147
|
|
|
112
148
|
// ── Build module type ────────────────────────────────────────────────
|
|
113
|
-
// Represents a named source module that declares system library requirements.
|
|
114
|
-
// Modules are the unit of reuse across Yo dependencies.
|
|
115
149
|
|
|
150
|
+
/// Represents a named source module that declares system library requirements.
|
|
151
|
+
/// Modules are the unit of reuse across Yo dependencies.
|
|
116
152
|
BuildModule :: struct(
|
|
153
|
+
/// Module name.
|
|
117
154
|
name : comptime_string,
|
|
155
|
+
/// Root source file.
|
|
118
156
|
root : comptime_string,
|
|
119
|
-
_dep : comptime_string
|
|
157
|
+
_dep : comptime_string
|
|
120
158
|
);
|
|
121
159
|
export BuildModule;
|
|
122
160
|
|
|
123
161
|
// ── Import entry type ────────────────────────────────────────────────
|
|
124
|
-
// Pairs an import name with a module for use with add_import/add_import_list.
|
|
125
162
|
|
|
163
|
+
/// Pairs an import name with a module for use with `add_import`/`add_import_list`.
|
|
126
164
|
ImportEntry :: struct(
|
|
165
|
+
/// Import alias used in source code.
|
|
127
166
|
name : comptime_string,
|
|
167
|
+
/// The module to import.
|
|
128
168
|
module : BuildModule
|
|
129
169
|
);
|
|
130
170
|
export ImportEntry;
|
|
131
171
|
|
|
132
172
|
// ── Step type ────────────────────────────────────────────────────────
|
|
133
|
-
// Returned by all build functions. Used to wire dependencies between steps.
|
|
134
173
|
|
|
174
|
+
/// A build step returned by all registration functions.
|
|
175
|
+
/// Use `step.depend_on(dep)` to wire dependencies between steps.
|
|
135
176
|
Step :: struct(
|
|
177
|
+
/// Step name.
|
|
136
178
|
name : comptime_string,
|
|
179
|
+
/// Kind of step.
|
|
137
180
|
kind : StepKind
|
|
138
181
|
);
|
|
139
182
|
export Step;
|
|
140
183
|
|
|
141
184
|
// ── Step methods ─────────────────────────────────────────────────────
|
|
142
|
-
// Methods on Step for Zig-like API: step.depend_on(other), exe.link(lib).
|
|
143
185
|
|
|
144
186
|
impl(Step,
|
|
187
|
+
/// Add a dependency — `dep` must complete before this step runs.
|
|
145
188
|
depend_on : (fn(comptime(self) : Self, comptime(dep) : Step) -> comptime(unit))({
|
|
146
189
|
__yo_build_step_depend_on(self.name, dep.name, dep.kind);
|
|
147
190
|
}),
|
|
191
|
+
/// Link a library step into this step.
|
|
148
192
|
link : (fn(comptime(self) : Self, comptime(library) : Step) -> comptime(unit))({
|
|
149
193
|
__yo_build_link(self.name, library.name);
|
|
150
194
|
}),
|
|
195
|
+
/// Add a single module import to this step.
|
|
151
196
|
add_import : (fn(comptime(self) : Self, comptime(entry) : ImportEntry) -> comptime(unit))({
|
|
152
197
|
__yo_build_add_import(self.name, entry.name, entry.module.name, entry.module._dep);
|
|
153
198
|
}),
|
|
199
|
+
/// Add a list of module imports to this step.
|
|
154
200
|
add_import_list : (fn(comptime(self) : Self, comptime(entries) : ComptimeList(ImportEntry)) -> comptime(unit))({
|
|
155
201
|
cond(
|
|
156
202
|
(entries.len() == usize(0)) => (),
|
|
@@ -160,6 +206,7 @@ impl(Step,
|
|
|
160
206
|
}
|
|
161
207
|
)
|
|
162
208
|
}),
|
|
209
|
+
/// Add extra C compiler flags to this step.
|
|
163
210
|
add_c_flags : (fn(comptime(self) : Self, comptime(flags) : comptime_string) -> comptime(unit))({
|
|
164
211
|
__yo_build_add_cflags(self.name, flags);
|
|
165
212
|
})
|
|
@@ -168,6 +215,7 @@ impl(Step,
|
|
|
168
215
|
// ── Build module methods ─────────────────────────────────────────────
|
|
169
216
|
|
|
170
217
|
impl(BuildModule,
|
|
218
|
+
/// Link a system library into this module.
|
|
171
219
|
link : (fn(comptime(self) : Self, comptime(library) : Step) -> comptime(unit))({
|
|
172
220
|
__yo_build_module_link(self.name, library.name);
|
|
173
221
|
})
|
|
@@ -177,34 +225,52 @@ impl(BuildModule,
|
|
|
177
225
|
// Like Zig's b.option(), declare user-configurable options.
|
|
178
226
|
// CLI usage: yo build -Dname=value
|
|
179
227
|
|
|
228
|
+
/// User-configurable build option (declared in `build.yo`, set via `yo build -Dname=value`).
|
|
180
229
|
BuildOption :: struct(
|
|
230
|
+
/// Option name (used with `-D`).
|
|
181
231
|
name : comptime_string,
|
|
232
|
+
/// Human-readable description.
|
|
182
233
|
description : comptime_string,
|
|
234
|
+
/// Default value if not provided.
|
|
183
235
|
(default : comptime_string) ?= ""
|
|
184
236
|
);
|
|
185
237
|
export BuildOption;
|
|
186
238
|
|
|
187
239
|
// ── Dependency config types ──────────────────────────────────────────
|
|
188
240
|
|
|
241
|
+
/// Git-hosted dependency configuration.
|
|
189
242
|
GitDependency :: struct(
|
|
243
|
+
/// Dependency name.
|
|
190
244
|
name : comptime_string,
|
|
245
|
+
/// Git repository URL.
|
|
191
246
|
url : comptime_string,
|
|
247
|
+
/// Git ref (tag, branch, or commit SHA). Defaults to `"HEAD"`.
|
|
192
248
|
(ref : comptime_string) ?= "HEAD",
|
|
249
|
+
/// Subdirectory within the repository.
|
|
193
250
|
(path : comptime_string) ?= ""
|
|
194
251
|
);
|
|
195
252
|
export GitDependency;
|
|
196
253
|
|
|
254
|
+
/// Local path dependency configuration.
|
|
197
255
|
PathDependency :: struct(
|
|
256
|
+
/// Dependency name.
|
|
198
257
|
name : comptime_string,
|
|
258
|
+
/// Filesystem path to the dependency root.
|
|
199
259
|
path : comptime_string
|
|
200
260
|
);
|
|
201
261
|
export PathDependency;
|
|
202
262
|
|
|
263
|
+
/// System C library discovered via `pkg-config`.
|
|
203
264
|
SystemLibrary :: struct(
|
|
265
|
+
/// Library name (passed to `pkg-config`).
|
|
204
266
|
name : comptime_string,
|
|
267
|
+
/// Fallback include path if pkg-config fails.
|
|
205
268
|
(fallback_include : comptime_string) ?= "",
|
|
269
|
+
/// Fallback library path.
|
|
206
270
|
(fallback_lib : comptime_string) ?= "",
|
|
271
|
+
/// Fallback link flags.
|
|
207
272
|
(fallback_link : comptime_string) ?= "",
|
|
273
|
+
/// Extra C preprocessor defines.
|
|
208
274
|
(defines : comptime_string) ?= ""
|
|
209
275
|
);
|
|
210
276
|
export SystemLibrary;
|
|
@@ -213,20 +279,21 @@ export SystemLibrary;
|
|
|
213
279
|
// Returned by build.dependency() and build.path_dependency().
|
|
214
280
|
// Provides access to artifacts defined in the dependency's build.yo.
|
|
215
281
|
|
|
282
|
+
/// Handle to a registered dependency. Use `.artifact()` or `.module()` to access its exports.
|
|
216
283
|
Dependency :: struct(
|
|
217
284
|
name : comptime_string
|
|
218
285
|
);
|
|
219
286
|
export Dependency;
|
|
220
287
|
|
|
221
288
|
impl(Dependency,
|
|
222
|
-
|
|
223
|
-
|
|
289
|
+
/// Access a named artifact from the dependency's `build.yo`.
|
|
290
|
+
/// Returns a `Step` that can be linked to the consumer's artifacts.
|
|
224
291
|
artifact : (fn(comptime(self) : Self, comptime(artifact_name) : comptime_string) -> comptime(Step))({
|
|
225
292
|
__yo_build_dep_artifact(self.name, artifact_name);
|
|
226
293
|
Step(name: artifact_name, kind: StepKind.StaticLibrary)
|
|
227
294
|
}),
|
|
228
|
-
|
|
229
|
-
|
|
295
|
+
/// Get a module from the dependency's `build.yo`.
|
|
296
|
+
/// Empty `module_name` defaults to the sole module if exactly one exists.
|
|
230
297
|
module : (fn(comptime(self) : Self, (comptime(module_name) : comptime_string) ?= "") -> comptime(BuildModule))({
|
|
231
298
|
_encoded :: __yo_build_dep_module(self.name, module_name);
|
|
232
299
|
BuildModule(name: module_name, root: "", _dep: self.name)
|
|
@@ -237,7 +304,7 @@ impl(Dependency,
|
|
|
237
304
|
// All registration functions return a Step value, allowing steps to be
|
|
238
305
|
// wired together as dependencies via step.depend_on(dep).
|
|
239
306
|
|
|
240
|
-
|
|
307
|
+
/// Register an executable artifact. Returns a `Step` for dependency wiring.
|
|
241
308
|
executable :: (fn(comptime(config) : Executable) -> comptime(Step)) {
|
|
242
309
|
opt_str :: match(config.optimize,
|
|
243
310
|
.Debug => "debug",
|
|
@@ -259,7 +326,7 @@ executable :: (fn(comptime(config) : Executable) -> comptime(Step)) {
|
|
|
259
326
|
};
|
|
260
327
|
export executable;
|
|
261
328
|
|
|
262
|
-
|
|
329
|
+
/// Register a static library artifact. Returns a `Step` for dependency wiring.
|
|
263
330
|
static_library :: (fn(comptime(config) : StaticLibrary) -> comptime(Step)) {
|
|
264
331
|
opt_str :: match(config.optimize,
|
|
265
332
|
.Debug => "debug",
|
|
@@ -272,7 +339,7 @@ static_library :: (fn(comptime(config) : StaticLibrary) -> comptime(Step)) {
|
|
|
272
339
|
};
|
|
273
340
|
export static_library;
|
|
274
341
|
|
|
275
|
-
|
|
342
|
+
/// Register a shared/dynamic library artifact. Returns a `Step` for dependency wiring.
|
|
276
343
|
shared_library :: (fn(comptime(config) : SharedLibrary) -> comptime(Step)) {
|
|
277
344
|
opt_str :: match(config.optimize,
|
|
278
345
|
.Debug => "debug",
|
|
@@ -285,21 +352,21 @@ shared_library :: (fn(comptime(config) : SharedLibrary) -> comptime(Step)) {
|
|
|
285
352
|
};
|
|
286
353
|
export shared_library;
|
|
287
354
|
|
|
288
|
-
|
|
355
|
+
/// Register a test-suite artifact. Returns a `Step` for dependency wiring.
|
|
289
356
|
test :: (fn(comptime(config) : TestSuite) -> comptime(Step)) {
|
|
290
357
|
__yo_build_test(config.name, config.root, config.target);
|
|
291
358
|
Step(name: config.name, kind: StepKind.TestSuite)
|
|
292
359
|
};
|
|
293
360
|
export test;
|
|
294
361
|
|
|
295
|
-
|
|
362
|
+
/// Create a run step (compile + execute an artifact). Returns a `Step`.
|
|
296
363
|
run :: (fn(comptime(artifact) : Step) -> comptime(Step)) {
|
|
297
364
|
__yo_build_run(artifact.name);
|
|
298
365
|
Step(name: artifact.name, kind: StepKind.Run)
|
|
299
366
|
};
|
|
300
367
|
export run;
|
|
301
368
|
|
|
302
|
-
|
|
369
|
+
/// Register a named build step. Use `step.depend_on(dep)` to add dependencies.
|
|
303
370
|
step :: (fn(
|
|
304
371
|
comptime(name) : comptime_string,
|
|
305
372
|
comptime(description) : comptime_string
|
|
@@ -309,47 +376,126 @@ step :: (fn(
|
|
|
309
376
|
};
|
|
310
377
|
export step;
|
|
311
378
|
|
|
312
|
-
|
|
379
|
+
/// Register a git-hosted dependency. Returns a `Dependency` handle for accessing artifacts.
|
|
313
380
|
dependency :: (fn(comptime(config) : GitDependency) -> comptime(Dependency)) {
|
|
314
381
|
__yo_build_dependency(config.name, config.url, config.ref, config.path);
|
|
315
382
|
Dependency(name: config.name)
|
|
316
383
|
};
|
|
317
384
|
export dependency;
|
|
318
385
|
|
|
319
|
-
|
|
386
|
+
/// Register a local path dependency. Returns a `Dependency` handle for accessing artifacts.
|
|
320
387
|
path_dependency :: (fn(comptime(config) : PathDependency) -> comptime(Dependency)) {
|
|
321
388
|
__yo_build_path_dependency(config.name, config.path);
|
|
322
389
|
Dependency(name: config.name)
|
|
323
390
|
};
|
|
324
391
|
export path_dependency;
|
|
325
392
|
|
|
326
|
-
|
|
393
|
+
/// Register a system C library discovered via `pkg-config`. Returns a `Step` for linking.
|
|
327
394
|
system_library :: (fn(comptime(config) : SystemLibrary) -> comptime(Step)) {
|
|
328
395
|
__yo_build_system_library(config.name, config.fallback_include, config.fallback_lib, config.fallback_link, config.defines);
|
|
329
396
|
Step(name: config.name, kind: StepKind.SystemLibrary)
|
|
330
397
|
};
|
|
331
398
|
export system_library;
|
|
332
399
|
|
|
333
|
-
|
|
334
|
-
|
|
400
|
+
/// Module configuration for shared compilation units.
|
|
335
401
|
ModuleConfig :: struct(
|
|
402
|
+
/// Module name.
|
|
336
403
|
name : comptime_string,
|
|
404
|
+
/// Root source file for the module.
|
|
337
405
|
root : comptime_string
|
|
338
406
|
);
|
|
339
407
|
export ModuleConfig;
|
|
340
408
|
|
|
341
|
-
|
|
342
|
-
|
|
409
|
+
/// Register a named module. Returns a `BuildModule` for linking system libraries
|
|
410
|
+
/// and importing into executables/libraries.
|
|
343
411
|
_module :: (fn(comptime(config) : ModuleConfig) -> comptime(BuildModule)) {
|
|
344
412
|
__yo_build_module(config.name, config.root);
|
|
345
413
|
BuildModule(name: config.name, root: config.root, _dep: "")
|
|
346
414
|
};
|
|
347
415
|
export module : _module;
|
|
348
416
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
417
|
+
/// Declare a user-configurable build option.
|
|
418
|
+
/// Returns the option value (from CLI `-Dname=value`, or the default).
|
|
419
|
+
///
|
|
420
|
+
/// # Example
|
|
421
|
+
/// ```rust
|
|
422
|
+
/// strip :: build.option({
|
|
423
|
+
/// name: "strip",
|
|
424
|
+
/// description: "Strip debug symbols",
|
|
425
|
+
/// default: "false"
|
|
426
|
+
/// });
|
|
427
|
+
/// ```
|
|
352
428
|
option :: (fn(comptime(config) : BuildOption) -> comptime(str))(
|
|
353
429
|
__yo_build_option(config.name, config.description, config.default)
|
|
354
430
|
);
|
|
355
431
|
export option;
|
|
432
|
+
|
|
433
|
+
// ── Documentation generation ─────────────────────────────────────────
|
|
434
|
+
|
|
435
|
+
/// Output format for documentation generation.
|
|
436
|
+
DocFormat :: enum(
|
|
437
|
+
Html,
|
|
438
|
+
Markdown,
|
|
439
|
+
Json
|
|
440
|
+
);
|
|
441
|
+
export DocFormat;
|
|
442
|
+
|
|
443
|
+
/// Configuration for documentation generation.
|
|
444
|
+
DocConfig :: struct(
|
|
445
|
+
/// Step name (e.g., "doc").
|
|
446
|
+
name : comptime_string,
|
|
447
|
+
/// Root source file or directory to document.
|
|
448
|
+
root : comptime_string,
|
|
449
|
+
/// Output directory (default: "yo-out/doc").
|
|
450
|
+
(output : comptime_string) ?= "yo-out/doc",
|
|
451
|
+
/// Output format (default: Html).
|
|
452
|
+
(format : DocFormat) ?= DocFormat.Html,
|
|
453
|
+
/// Document non-exported (private) items.
|
|
454
|
+
(include_private : bool) ?= false,
|
|
455
|
+
/// Document dependencies too.
|
|
456
|
+
(include_deps : bool) ?= false,
|
|
457
|
+
/// Custom site title (default: project name).
|
|
458
|
+
(title : comptime_string) ?= "",
|
|
459
|
+
/// Path to logo image.
|
|
460
|
+
(logo : comptime_string) ?= "",
|
|
461
|
+
/// Path to favicon.
|
|
462
|
+
(favicon : comptime_string) ?= ""
|
|
463
|
+
);
|
|
464
|
+
export DocConfig;
|
|
465
|
+
|
|
466
|
+
/// Register a documentation generation step. Returns a Step for dependency wiring.
|
|
467
|
+
///
|
|
468
|
+
/// # Examples
|
|
469
|
+
///
|
|
470
|
+
/// ```rust
|
|
471
|
+
/// build :: import "std/build";
|
|
472
|
+
///
|
|
473
|
+
/// // Minimal — just works with defaults
|
|
474
|
+
/// doc_step :: build.doc({ name: "doc", root: "./src/lib.yo" });
|
|
475
|
+
///
|
|
476
|
+
/// // Full customization
|
|
477
|
+
/// doc_step :: build.doc({
|
|
478
|
+
/// name: "doc",
|
|
479
|
+
/// root: "./src",
|
|
480
|
+
/// output: "docs/api",
|
|
481
|
+
/// format: DocFormat.Markdown,
|
|
482
|
+
/// title: "My Library API"
|
|
483
|
+
/// });
|
|
484
|
+
///
|
|
485
|
+
/// install :: build.step("install", "Build all artifacts");
|
|
486
|
+
/// install.depend_on(doc_step);
|
|
487
|
+
/// ```
|
|
488
|
+
doc :: (fn(comptime(config) : DocConfig) -> comptime(Step)) {
|
|
489
|
+
fmt_str :: match(config.format,
|
|
490
|
+
.Html => "html",
|
|
491
|
+
.Markdown => "markdown",
|
|
492
|
+
.Json => "json"
|
|
493
|
+
);
|
|
494
|
+
__yo_build_doc(
|
|
495
|
+
config.name, config.root, config.output, fmt_str,
|
|
496
|
+
config.include_private, config.include_deps,
|
|
497
|
+
config.title, config.logo, config.favicon
|
|
498
|
+
);
|
|
499
|
+
Step(name: config.name, kind: StepKind.Documentation)
|
|
500
|
+
};
|
|
501
|
+
export doc;
|
package/std/cli/arg_parser.yo
CHANGED
|
@@ -1,17 +1,49 @@
|
|
|
1
|
+
//! Command-line argument parsing.
|
|
2
|
+
//!
|
|
3
|
+
//! Supports flags (`--verbose`), options (`--output file`), short aliases (`-v`),
|
|
4
|
+
//! and positional arguments. Automatically generates help text.
|
|
5
|
+
//!
|
|
6
|
+
//! # Example
|
|
7
|
+
//!
|
|
8
|
+
//! ```rust
|
|
9
|
+
//! { ArgParser } :: import "std/cli/arg_parser";
|
|
10
|
+
//!
|
|
11
|
+
//! parser := ArgParser.new(`myapp`, `A sample CLI tool`);
|
|
12
|
+
//! parser.flag(`verbose`, `v`, `Enable verbose output`);
|
|
13
|
+
//! parser.option(`output`, `o`, `Output file`, `out.txt`);
|
|
14
|
+
//! args := parser.parse();
|
|
15
|
+
//! ```
|
|
16
|
+
|
|
1
17
|
open import "../collections/array_list";
|
|
2
18
|
open import "../string";
|
|
3
19
|
|
|
4
|
-
|
|
20
|
+
/// Kind of command-line argument.
|
|
21
|
+
ArgKind :: enum(
|
|
22
|
+
/// Boolean flag (e.g. `--verbose`).
|
|
23
|
+
Flag,
|
|
24
|
+
/// Key-value option (e.g. `--output file`).
|
|
25
|
+
Opt,
|
|
26
|
+
/// Positional argument.
|
|
27
|
+
Positional
|
|
28
|
+
);
|
|
5
29
|
|
|
30
|
+
/// Definition of a single command-line argument.
|
|
6
31
|
ArgDef :: object(
|
|
32
|
+
/// Long name (e.g. `"verbose"` for `--verbose`).
|
|
7
33
|
_long_name : String,
|
|
34
|
+
/// Short name (e.g. `"v"` for `-v`).
|
|
8
35
|
_short_name : String,
|
|
36
|
+
/// Human-readable description for help text.
|
|
9
37
|
_description : String,
|
|
38
|
+
/// Kind of argument (flag, option, or positional).
|
|
10
39
|
_kind : ArgKind,
|
|
40
|
+
/// Default value for options.
|
|
11
41
|
_default_value : String,
|
|
42
|
+
/// Whether this argument is required.
|
|
12
43
|
_required : bool
|
|
13
44
|
);
|
|
14
45
|
|
|
46
|
+
/// Result of parsing command-line arguments.
|
|
15
47
|
ParsedArgs :: object(
|
|
16
48
|
_set_flags : ArrayList(String),
|
|
17
49
|
_option_names : ArrayList(String),
|
|
@@ -20,9 +52,13 @@ ParsedArgs :: object(
|
|
|
20
52
|
_positional_names : ArrayList(String)
|
|
21
53
|
);
|
|
22
54
|
|
|
55
|
+
/// Command-line argument parser.
|
|
23
56
|
ArgParser :: object(
|
|
57
|
+
/// Application name shown in help text.
|
|
24
58
|
_name : String,
|
|
59
|
+
/// Application description shown in help text.
|
|
25
60
|
_description : String,
|
|
61
|
+
/// Registered argument definitions.
|
|
26
62
|
_args : ArrayList(ArgDef)
|
|
27
63
|
);
|
|
28
64
|
|
|
@@ -1,33 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* Similar to Rust's Vec<T> and Zig's ArrayList, this ArrayList provides:
|
|
5
|
-
* - Dynamic resizing
|
|
6
|
-
* - ~~Memory management via custom allocator~~
|
|
7
|
-
* - Type safety
|
|
8
|
-
* - RAII for automatic cleanup
|
|
9
|
-
*/
|
|
1
|
+
//! Dynamic array (vector) with amortized O(1) push and O(1) indexed access.
|
|
2
|
+
|
|
10
3
|
{ GlobalAllocator, AllocError } :: import "../allocator.yo";
|
|
11
4
|
{ memmove, memcpy, memset } :: import "../libc/string.yo";
|
|
12
5
|
{ malloc, calloc, realloc, free, aligned_alloc } :: GlobalAllocator;
|
|
13
6
|
|
|
14
|
-
|
|
15
|
-
* ArrayList error types
|
|
16
|
-
*/
|
|
7
|
+
/// Error variants for ArrayList operations.
|
|
17
8
|
ArrayListError :: enum(
|
|
9
|
+
/// Memory allocation failed.
|
|
18
10
|
AllocError(error : AllocError),
|
|
11
|
+
/// Index is out of bounds for the current length.
|
|
19
12
|
IndexOutOfBounds(index: usize, length: usize),
|
|
13
|
+
/// Attempted to access an element from an empty list.
|
|
20
14
|
EmptyList
|
|
21
15
|
);
|
|
22
16
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
*
|
|
26
|
-
* Memory layout:
|
|
27
|
-
* - ptr: pointer to the heap-allocated buffer
|
|
28
|
-
* - _length: current number of elements
|
|
29
|
-
* - _capacity: total capacity of the buffer
|
|
30
|
-
*/
|
|
17
|
+
/// Generic growable array similar to Rust's `Vec<T>`.
|
|
18
|
+
/// Heap-allocated with automatic resizing and reference-counted cleanup.
|
|
31
19
|
ArrayList :: (fn(comptime(T): Type) -> comptime(Type))(
|
|
32
20
|
object(
|
|
33
21
|
_ptr : ?*(T),
|
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
//
|
|
12
|
-
|
|
1
|
+
//! Sorted map backed by a sorted array with O(log n) lookup via binary search.
|
|
2
|
+
//!
|
|
3
|
+
//! # Example
|
|
4
|
+
//!
|
|
5
|
+
//! ```rust
|
|
6
|
+
//! { BTreeMap } :: import "std/collections/btree_map";
|
|
7
|
+
//!
|
|
8
|
+
//! m := BTreeMap(String, i32).new();
|
|
9
|
+
//! m.set(String.from("b"), 2);
|
|
10
|
+
//! m.set(String.from("a"), 1);
|
|
11
|
+
//! // Iteration order: a, b
|
|
12
|
+
//! ```
|
|
13
13
|
|
|
14
14
|
{ ArrayList } :: import "./array_list";
|
|
15
15
|
open import "../string";
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
// BTreeEntry - key/value pair
|
|
19
|
-
// ============================================================================
|
|
20
|
-
|
|
17
|
+
/// Key-value pair entry stored in a BTreeMap.
|
|
21
18
|
BTreeEntry :: (fn(comptime(K) : Type, comptime(V) : Type) -> comptime(Type))(
|
|
22
19
|
struct(key: K, value: V)
|
|
23
20
|
);
|
|
@@ -27,10 +24,8 @@ export BTreeEntry;
|
|
|
27
24
|
// Internal result from binary search.
|
|
28
25
|
_FindResult :: struct(idx: usize, found: bool);
|
|
29
26
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
// ============================================================================
|
|
33
|
-
|
|
27
|
+
/// Sorted map maintaining entries in key order.
|
|
28
|
+
/// Provides ordered iteration and O(log n) lookup via binary search. Insert is O(n).
|
|
34
29
|
BTreeMap :: (fn(comptime(K) : Type, comptime(V) : Type) -> comptime(Type))(
|
|
35
30
|
object(
|
|
36
31
|
_entries : ArrayList(BTreeEntry(K, V))
|