authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-10-21 17:31:06-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-10-21 17:31:06-04:00
log92751d5e2426f5f8151b910156d33709bf5df11b
treedc783e1e0ce1467e05f7091647310d88cab7b09b
parentc1642355f0b05f182c0b6d81d294d12be79ad0a8

self hosted zig: print usage


2 files changed, 122 insertions(+), 0 deletions(-)

build.zig+10
...@@ -2,6 +2,16 @@ const Builder = @import("std").build.Builder;...@@ -2,6 +2,16 @@ const Builder = @import("std").build.Builder;
2const tests = @import("test/tests.zig");2const tests = @import("test/tests.zig");
33
4pub fn build(b: &Builder) {4pub fn build(b: &Builder) {
5 const mode = b.standardReleaseOptions();
6
7 var exe = b.addExecutable("zig", "src-self-hosted/main.zig");
8 exe.setBuildMode(mode);
9 exe.linkSystemLibrary("c");
10 b.default_step.dependOn(&exe.step);
11
12 b.installArtifact(exe);
13
14
5 const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter");15 const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter");
6 const with_lldb = b.option(bool, "with-lldb", "Run tests in LLDB to get a backtrace if one fails") ?? false;16 const with_lldb = b.option(bool, "with-lldb", "Run tests in LLDB to get a backtrace if one fails") ?? false;
7 const test_step = b.step("test", "Run all the tests");17 const test_step = b.step("test", "Run all the tests");
src-self-hosted/main.zig created+112
...@@ -0,0 +1,112 @@
1const io = @import("std").io;
2const os = @import("std").os;
3const heap = @import("std").mem;
4
5// TODO: OutSteam and InStream interface
6// TODO: move allocator to heap namespace
7
8error InvalidArgument;
9error MissingArg0;
10
11pub fn main() -> %void {
12 if (internal_main()) |_| {
13 return;
14 } else |err| {
15 if (err == error.InvalidArgument) {
16 io.stderr.printf("\n") %% return err;
17 printUsage(&io.stderr) %% return err;
18 } else {
19 io.stderr.printf("{}\n", err) %% return err;
20 }
21 return err;
22 }
23}
24
25pub fn internal_main() -> %void {
26 var args_it = os.args();
27
28 var incrementing_allocator = heap.IncrementingAllocator.init(10 * 1024 * 1024) %% |err| {
29 io.stderr.printf("Unable to allocate memory") %% {};
30 return err;
31 };
32 defer incrementing_allocator.deinit();
33
34 const allocator = &incrementing_allocator.allocator;
35
36 const arg0 = %return (args_it.next(allocator) ?? error.MissingArg0);
37 defer allocator.free(arg0);
38
39 %return printUsage(&io.stdout);
40}
41
42fn printUsage(outstream: &io.OutStream) -> %void {
43 %return outstream.write(
44 \\Usage: zig [command] [options]
45 \\Commands:
46 \\ build build project from build.zig
47 \\ build-exe [source] create executable from source or object files
48 \\ build-lib [source] create library from source or object files
49 \\ build-obj [source] create object from source or assembly
50 \\ parsec [source] convert c code to zig code
51 \\ targets list available compilation targets
52 \\ test [source] create and run a test build
53 \\ version print version number and exit
54 \\ zen print zen of zig and exit
55 \\Compile Options:
56 \\ --assembly [source] add assembly file to build
57 \\ --cache-dir [path] override the cache directory
58 \\ --color [auto|off|on] enable or disable colored error messages
59 \\ --enable-timing-info print timing diagnostics
60 \\ --libc-include-dir [path] directory where libc stdlib.h resides
61 \\ --name [name] override output name
62 \\ --output [file] override destination path
63 \\ --output-h [file] override generated header file path
64 \\ --pkg-begin [name] [path] make package available to import and push current pkg
65 \\ --pkg-end pop current pkg
66 \\ --release-fast build with optimizations on and safety off
67 \\ --release-safe build with optimizations on and safety on
68 \\ --static output will be statically linked
69 \\ --strip exclude debug symbols
70 \\ --target-arch [name] specify target architecture
71 \\ --target-environ [name] specify target environment
72 \\ --target-os [name] specify target operating system
73 \\ --verbose turn on compiler debug output
74 \\ --verbose-link turn on compiler debug output for linking only
75 \\ --verbose-ir turn on compiler debug output for IR only
76 \\ --zig-install-prefix [path] override directory where zig thinks it is installed
77 \\ -dirafter [dir] same as -isystem but do it last
78 \\ -isystem [dir] add additional search path for other .h files
79 \\ -mllvm [arg] additional arguments to forward to LLVM's option processing
80 \\Link Options:
81 \\ --ar-path [path] set the path to ar
82 \\ --dynamic-linker [path] set the path to ld.so
83 \\ --each-lib-rpath add rpath for each used dynamic library
84 \\ --libc-lib-dir [path] directory where libc crt1.o resides
85 \\ --libc-static-lib-dir [path] directory where libc crtbegin.o resides
86 \\ --msvc-lib-dir [path] (windows) directory where vcruntime.lib resides
87 \\ --kernel32-lib-dir [path] (windows) directory where kernel32.lib resides
88 \\ --library [lib] link against lib
89 \\ --library-path [dir] add a directory to the library search path
90 \\ --linker-script [path] use a custom linker script
91 \\ --object [obj] add object file to build
92 \\ -L[dir] alias for --library-path
93 \\ -rdynamic add all symbols to the dynamic symbol table
94 \\ -rpath [path] add directory to the runtime library search path
95 \\ -mconsole (windows) --subsystem console to the linker
96 \\ -mwindows (windows) --subsystem windows to the linker
97 \\ -municode (windows) link with unicode
98 \\ -framework [name] (darwin) link against framework
99 \\ -mios-version-min [ver] (darwin) set iOS deployment target
100 \\ -mmacosx-version-min [ver] (darwin) set Mac OS X deployment target
101 \\ --ver-major [ver] dynamic library semver major version
102 \\ --ver-minor [ver] dynamic library semver minor version
103 \\ --ver-patch [ver] dynamic library semver patch version
104 \\Test Options:
105 \\ --test-filter [text] skip tests that do not match filter
106 \\ --test-name-prefix [text] add prefix to all tests
107 \\ --test-cmd [arg] specify test execution command one arg at a time
108 \\ --test-cmd-bin appends test binary path to test cmd args
109 \\
110 );
111 %return outstream.flush();
112}