-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy path_zig
331 lines (313 loc) · 17.1 KB
/
_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
#compdef zig
local -a __zig_commands
__zig_commands=(
'build:Build project from build.zig'
'fetch:Copy a package into global cache and print its hash'
'init:Initialize a Zig package in the current directory'
'build-exe:Create executable from source or object files'
'build-lib:Create library from source or object files'
'build-obj:Create object from source or object files'
'run:Create executable and run immediately'
'test:Create and run a test build'
'ast-check:Look for simple compile errors in any set of files'
'fmt:Reformat Zig source into canonical form'
'reduce:Minimize a bug report'
'translate-c:Convert C code to Zig code'
'ar:Use Zig as a drop-in archiver'
'cc:Use Zig as a drop-in C compiler'
'c++:Use Zig as a drop-in C++ compiler'
'dlltool:Use Zig as a drop-in dlltool.exe'
'lib:Use Zig as a drop-in lib.exe'
'ranlib:Use Zig as a drop-in ranlib'
'env:Print lib path, std path, cache directory, and version'
'help:Print this help and exit'
'std:View standard library documentation in a browser'
'libc:Display native libc paths file or validate one'
'targets:List available compilation targets'
'version:Print version number and exit'
'zen:Print Zen of Zig and exit'
)
__zig_general_options=(
'--watch[Enable compiler REPL]'
'--color[Enable or disable colored error messages]: :(on off auto)'
'-femit-bin=[(default) Output machine code]:path:_files -/'
'-fno-emit-bin[Do not output machine code]:'
'-femit-asm[Output .s (assembly code)]:path:_files -/'
'-fno-emit-asm[(default) Do not output .s (assembly code)]:'
'-femit-llvm-ir[Produce a .ll file with LLVM IR (requires LLVM extensions)]:path:_files -/'
'-fno-emit-llvm-ir[(default) Do not produce a .ll file with LLVM IR]:'
'-femit-llvm-bc[Produce a LLVM module as a .bc file (requires LLVM extensions)]:path:_files -/'
'-fno-emit-llvm-bc[(default) Do not produce a LLVM module as a .bc file]'
'-femit-h[Generate a C header file (.h)]:path:_files -/'
'-fno-emit-h[(default) Do not generate a C header file (.h)]:'
'-femit-docs[Create a docs/ dir with html documentation]:path:_files -/'
'-fno-emit-docs[(default) Do not produce docs/ dir with html documentation]:'
'-femit-analysis[Write analysis JSON file with type information]:path:_files -/'
'-fno-emit-analysis[(default) Do not write analysis JSON file with type information]:'
'-femit-implib[(default) Produce an import .lib when building a Windows DLL]:path:_files -/'
'-fno-emit-implib[Do not produce an import .lib when building a Windows DLL]:'
'--show-builtin[Output the source of @import("builtin") then exit]:'
'--cache-dir[Override the local cache directory]:path:_files -/'
'--global-cache-dir[Override the global cache directory]:path:_files -/'
'--zig-lib-dir[Override path to Zig installation lib directory]:path:_files -/'
'--enable-cache[Output to cache directory; print path to stdout]'
)
__zig_compile_options=(
'-target[<arch><sub>-<os>-<abi> see the targets command]:target'
'-mcpu[Specify target CPU and feature set]:cpu'
'-mcmodel=[Limit range of code and data virtual addresses]:model:(default tiny small kernel medium large)'
'-mred-zone[Force-enable the "red-zone"]'
'-mno-red-zone[Force-disable the "red-zone"]'
'-fomit-frame-pointer[Omit the stack frame pointer]'
'-fno-omit-frame-pointer[Store the stack frame pointer]'
'-mexec-model=[(WASI) Execution model]:mode:(command reactor)'
'--name[Override root name (not a file path)]:name'
'-O-[Choose what to optimize for]:mode:((
Debug\:"(default) Optimizations off, safety on"
ReleaseFast\:"Optimizations on, safety off"
ReleaseSafe\:"Optimizations on, safety on"
ReleaseSmall\:"Optimize for small binary, safety off"
))'
'--pkg-begin:[Make pkg available to import and push current pkg]:string'
'--pkg-end[Pop current pkg]'
'--main-pkg-path[Set the directory of the root package]'
'-fPIC[Force-enable Position Independent Code]'
'-fno-PIC[Force-disable Position Independent Code]'
'-fPIE[Force-enable Position Independent Executable]'
'-fno-PIE[Force-disable Position Independent Executable]'
'-flto[Force-enable Link Time Optimization (requires LLVM extensions)]'
'-fno-lto[Force-disable Link Time Optimization]'
'-fstack-check[Enable stack probing in unsafe builds]'
'-fno-stack-check[Disable stack probing in safe builds]'
'-fstack-protector[Enable stack protection in unsafe builds]'
'-fno-stack-protector[Disable stack protection in safe builds]'
'-fsanitize-c[Enable C undefined behavior detection in unsafe builds]'
'-fno-sanitize-c[Disable C undefined behavior detection in safe builds]'
'-fvalgrind[Include valgrind client requests in release builds]'
'-fno-valgrind[Omit valgrind client requests in debug builds]'
'-fsanitize-thread[Enable Thread Sanitizer]'
'-fno-sanitize-thread[Disable Thread Sanitizer]'
'-fdll-export-fns[Mark exported functions as DLL exports (Windows)]'
'-fno-dll-export-fns[Force-disable marking exported functions as DLL exports]'
'-fno-dll-export-fns[Force-disable marking exported functions as DLL exports]'
'-funwind-tables[Always produce unwind table entries for all functions]'
'-fno-unwind-tables[Never produce unwind table entries]'
'-fLLVM[Force using LLVM as the codegen backend]'
'-fno-LLVM[Prevent using LLVM as a codegen backend]'
'-fClang[Force using Clang as the C/C++ compilation backend]'
'-fstage1[Force using bootstrap compiler as the codegen backend]'
'-fno-stage1[Prevent using bootstrap compiler as the codegen backend]'
'-freference-trace[How many lines of reference trace should be shown per compile error]:int'
'-fno-reference-trace[Disable reference trace]'
'-fsingle-threaded[Code assumes there is only one thread]'
'-fno-single-threaded[Code may not assume there is only one thread]'
'-fbuiltin[Enable implicit builtin knowledge of functions]'
'-fno-builtin[Disable implicit builtin knowledge of functions]'
'-ffunction-sections[Places each function in a separate section]'
'-fno-function-sections[All functions go into same section]'
'-fstrip[Omit debug symbols]'
'-fno-strip[Keep debug symbols]'
'-ofmt=[Override target object format]:mode:((
elf\:"Executable and Linking Format"
c\:"Compile to C source code" wasm\:"WebAssembly"
pe\:"Portable Executable (Windows)"
coff\:"Common Object File Format (Windows)"
macho\:"macOS relocatables"
hex\:"Intel IHEX (planned)"
raw\:"Dump machine code directly (planned)"
))'
'-dirafter[Add directory to AFTER include search path]:dir:_files -/'
'-isystem[Add directory to SYSTEM include search path]:dir:_files -/'
'-I-[Add directory to include search path]:dir:_files -/'
'-D[Define C \[macro\] to \[value\] (1 if \[value\] omitted)]:string'
'--libc[Provide a file which specifies libc paths]:dir:_files'
'-cflags[Set extra flags for the next positional C source files]:[flags]'
)
__zig_link_options=(
'-l-[Link against system library (only if actually used)]:library:__zig_library'
'-needed-l-[Link against system library (even if unused)]:library:__zig_library'
'-L-[Add a directory to the library search path]:d:_files -/'
'-T-[Use a custom linker script]:script:_files'
'--library[Link against system library (only if actually used)]:library:__zig_library'
'--needed-library[Link against system library (even if unused)]:library:__zig_library'
'--library-directory[Add a directory to the library search path]:d:_files -/'
'--version-script[Provide a version .map file]:path:_files -/'
'--dynamic-linker[Set the dynamic interpreter path (usually ld.so)]:path:_files -/'
'--sysroot[Set the system root directory (usually /)]:path:_files -/'
'--version[Dynamic library semver]:string'
'--entry[Set the entrypoint symbol name]:string'
'-fsoname=[Override the default SONAME value]:name'
'-fno-soname[Disable emitting a SONAME]'
'-fLLD[Force using LLD as the linker]'
'-fno-LLD[Prevent using LLD as the linker]'
'-fcompiler-rt[Always include compiler-rt symbols in output]'
'-fno-compiler-rt[Prevent including compiler-rt symbols in output]'
'-rdynamic[Add all symbols to the dynamic symbol table]'
'-rpath[Add directory to the runtime library search path]:path:_files -/'
'-feach-lib-rpath[Ensure adding rpath for each used dynamic library]'
'-fno-each-lib-rpath[Prevent adding rpath for each used dynamic library]'
'-fallow-shlib-undefined[Allows undefined symbols in shared libraries]'
'-fno-allow-shlib-undefined[Disallows undefined symbols in shared libraries]'
'-fbuild-id[Helps coordinate stripped binaries with debug symbols]'
'-fno-build-id[(default) Saves a bit of time linking]'
'--eh-frame-hdr[Enable C++ exception handling by passing --eh-frame-hdr to linker]'
'--emit-relocs[Enable output of relocation sections for post build tools]'
'-z[Set linker extension flags]: :((
nodelete\:"Indicate that the object cannot be deleted from a process"
notext\:"Permit read-only relocations in read-only segments"
defs\:"Force a fatal error if any undefined symbols remain"
origin\:"Indicate that the object must have its origin processed"
nocopyreloc\:"Disable the creation of copy relocations"
now\:"(default) Force all relocations to be processed on load"
lazy\:"Do not force all relocations to be processed on load"
relro\:"(default) Force all relocations to be read-only after processing"
norelro\:"Do not force all relocations to be read-only after processing"
))'
'-dynamic[Force output to be dynamically linked]'
'-static[Force output to be statically linked]'
'-Bsymbolic[Bind global references locally]'
'--compress-debug-sections=[Debug section compression settings]: :((
none\:"No compression"
zlib\:"Compression with deflate/inflate"
))'
'--gc-sections[Force removal of functions and data that are unreachable by the entry point or exported symbols]'
'--no-gc-sections[Do not force removal of unreachable functions and data]'
'--subsystem[(Windows) /SUBSYSTEM:<subsystem> to the linker]:subsystem'
'--stack[Override default stack size]:int'
'--image-base[Set base address for executable image]:int'
'-weak-l-[(Darwin) link against system library and mark it and all referenced symbols as weak]:library:__zig_library'
'-framework[(Darwin) link against framework]:framework'
'-needed_framework[(Darwin) link against framework (even if unused)]:framework'
'-weak_framework[(Darwin) link against framework and mark it and all referenced symbols as weak]:framework'
'-F[(Darwin) add search path for frameworks]:dir:_files -/'
'-install_name=[(Darwin) add dylibs install name]:string'
'--entitlements[(Darwin) add path to entitlements file for embedding in code signature]:path:_files -/'
'-pagezero_size[(Darwin) size of the __PAGEZERO segment in hexadecimal notation]:int'
'-search_paths_first[(Darwin) search each dir in library search paths for `libx.dylib` then `libx.a`]'
'-search_dylibs_first[(Darwin) search `libx.dylib` in each dir in library search paths, then `libx.a`]'
'-headerpad[(Darwin) set minimum space for future expansion of the load commands in hexadecimal notation]:int'
'-headerpad_max_install_names[(Darwin) set enough space as if all paths were MAXPATHLEN]'
'-dead_strip[(Darwin) remove functions and data that are unreachable by the entry point or exported symbols]'
'-dead_strip_dylibs[(Darwin) remove dylibs that are unreachable by the entry point or exported symbols]'
'--import-memory[(WebAssembly) import memory from the environment]'
'--import-table[(WebAssembly) import function table from the host environment]'
'--export-table[(WebAssembly) export function table to the host environment]'
'--initial-memory=[(WebAssembly) initial size of the linear memory]:int'
'--max-memory=[(WebAssembly) maximum size of the linear memory]:int'
'--shared-memory[(WebAssembly) use shared linear memory]'
'--global-base=[(WebAssembly) where to start to place global data]:int'
'--export=[(WebAssembly) Force a symbol to be exported]:string'
)
__zig_debug_options=(
'-ftime-report[Print timing diagnostics]'
'-fstack-report[Print stack size diagnostics]'
'--verbose-link[Display linker invocations]'
'--verbose-cc[Display C compiler invocations]'
'--verbose-air[Enable compiler debug output for Zig AIR]'
'--verbose-llvm-ir[Enable compiler debug output for LLVM IR]'
'--verbose-cimport[Enable compiler debug output for C imports]'
'--verbose-llvm-cpu-features[Enable compiler debug output for LLVM CPU features]'
'--debug-log[Enable printing debug/info log messages for scope]:string'
'--debug-compile-errors[Crash with helpful diagnostics at the first compile error]'
'--debug-link-snapshot[Enable dumping of the linkers state in JSON format]'
'*:files:__zig_files'
)
__zig_test_options=(
'--test-filter[Skip tests that do not match filter]:string'
'--test-name-prefix[Add prefix to all tests]:string'
'--test-cmd[Specify test execution command one arg at a time]:string'
'--test-cmd-bin[Appends test binary path to test cmd args]'
'--test-evented-io[Runs the test in evented I/O mode]'
'--test-no-exec[Compiles test binary without running it]'
)
__zig_files() {
_files -g "*.{zig,zir,o,o,obj,lib,a,so,dll,dylib,tbd,s,S,c,cpp,C,cc,cxx}"
}
__zig_library() {
_wanted libraries expl library \
compadd - \
${^=LD_LIBRARY_PATH:-/usr/lib /usr/local/lib}/lib*.(a|so*)(:t:fr:s/lib//)
}
__zig_build() {
steps=()
args=(
'-p-[Override default install prefix]:path:_files -/'
'--prefix[Override default install prefix]:path:_files -/'
'--prefix-lib-dir[Override default library directory path]:path:_files -/'
'--prefix-exe-dir[Override default executable directory path]:path:_files -/'
'--prefix-include-dir[Override default include directory path]:path:_files -/'
'--sysroot[Set the system root directory (usually /)]:path:_files -/'
'--search-prefix[Add a path to look for binaries, libraries, headers]:path:_files -/'
'--libc[Provide a file which specifies libc paths]:dir:_files'
'-fdarling[Enable integration with system-installed Darling to execute macOS programs on Linux hosts]'
'-fno-darling[(default) Disable integration with system-installed Darling to execute macOS programs on Linux hosts]'
'-fqemu[Enable integration with system-installed QEMU to execute foreign-architecture programs on Linux hosts]'
'-fno-qemu[(default) Disable integration with system-installed QEMU to execute foreign-architecture programs on Linux hosts]'
'--glibc-runtimes[Enhances QEMU integration by providing glibc built for multiple foreign architectures, allowing execution of non-native programs that link with glibc]:dir:_files'
'-frosetta[Rely on Rosetta to execute x86_64 programs on ARM64 macOS hosts]'
'-fno-rosetta[(default) Do not rely on Rosetta to execute x86_64 programs on ARM64 macOS hosts]'
'-fwasmtime[Enable integration with system-installed wasmtime to execute WASI binaries]'
'-fno-wasmtime[(default) disable integration with system-installed wasmtime to execute WASI binaries]'
'-fwine[Enable integration with system-installed Wine to execute Windows programs on Linux hosts]'
'-fno-wine[(default) disable integration with system-installed Wine to execute Windows programs on Linux hosts]'
'--verbose[Print commands before executing them]'
'--color[Enable or disable colored error messages]: :(on off auto)'
'--prominent-compile-errors[Output compile errors formatted for a human to read]'
)
in_options=false
in_project_options=false
help=$($__zig_exe build --help 2> /dev/null | tail -n +4)
while IFS= read -r line ; do
if [ "$in_options" = "false" ]; then
if [ -z "$line" ]; then
in_options=true
continue
fi
# step (default) description -> step:(default) description
steps+=("$(sed -r 's/^ *([^ ]+)( \(default\))? +(.*) *$/\1:\3\2/' <<<"$line")")
elif [ "$in_project_options" = "false" ]; then
if [ "$line" = "Project-Specific Options:" ]; then
in_project_options=true
continue
fi
else
if [ -n "$(grep ' -' <<<"$line")" ]; then
# -Dflag=[arg] description -> -Dflag=[description]:arg
args+=("$(sed -r 's/^ *([^\[ ]+) ?(\[([^]]*)\])? *(.+) *$/\1[\4]:\3/' <<<"$line")")
fi
fi
done <<< $help
if [ -z "$(grep "^-" <<<$words[$CURRENT])" ]; then
_describe 'step' steps
else
_arguments ${args[@]}
fi
}
__zig_exe=$words[1]
_arguments \
"1: :{_describe 'command' __zig_commands}" \
"*:: :->args"
case $state in
args)
case $words[1] in
build-exe | build-lib | build-obj | run | translate-c)
_arguments $__zig_general_options $__zig_compile_options $__zig_link_options $__zig_debug_options
;;
test)
_arguments $__zig_general_options $__zig_compile_options $__zig_link_options $__zig_debug_options $__zig_test_options
;;
fmt)
_arguments \
'--stdin[Format code from stdin; output to stdout]:' \
'--color[Enable or disable colored error messages]: :(on off auto)' \
'--check[List non-conforming files and exit with an error if the list is non-empty]' \
'--ast-check[Run zig ast-check on every file]' \
'--exclude[Exclude file or directory from formatting]:path:_files -/' \
'*:files:_files -g "*.zig"'
;;
build)
__zig_build
;;
esac
;;
esac