mirror of
https://github.com/ziglang/zig.git
synced 2025-12-29 01:23:17 +00:00
wip self hosted code
This commit is contained in:
parent
92751d5e24
commit
4f4da3c10c
@ -1,3 +1,4 @@
|
||||
const builtin = @import("builtin");
|
||||
const io = @import("std").io;
|
||||
const os = @import("std").os;
|
||||
const heap = @import("std").mem;
|
||||
@ -8,6 +9,8 @@ const heap = @import("std").mem;
|
||||
error InvalidArgument;
|
||||
error MissingArg0;
|
||||
|
||||
var arg0: []u8 = undefined;
|
||||
|
||||
pub fn main() -> %void {
|
||||
if (internal_main()) |_| {
|
||||
return;
|
||||
@ -33,15 +36,169 @@ pub fn internal_main() -> %void {
|
||||
|
||||
const allocator = &incrementing_allocator.allocator;
|
||||
|
||||
const arg0 = %return (args_it.next(allocator) ?? error.MissingArg0);
|
||||
arg0 = %return (args_it.next(allocator) ?? error.MissingArg0);
|
||||
defer allocator.free(arg0);
|
||||
|
||||
%return printUsage(&io.stdout);
|
||||
var build_mode = builtin.Mode.Debug;
|
||||
var strip = false;
|
||||
var is_static = false;
|
||||
var verbose = false;
|
||||
var verbose_link = false;
|
||||
var verbose_ir = false;
|
||||
var mwindows = false;
|
||||
var mconsole = false;
|
||||
|
||||
while (args_it.next()) |arg_or_err| {
|
||||
const arg = %return arg_or_err;
|
||||
|
||||
if (arg[0] == '-') {
|
||||
if (strcmp(arg, "--release-fast") == 0) {
|
||||
build_mode = builtin.Mode.ReleaseFast;
|
||||
} else if (strcmp(arg, "--release-safe") == 0) {
|
||||
build_mode = builtin.Mode.ReleaseSafe;
|
||||
} else if (strcmp(arg, "--strip") == 0) {
|
||||
strip = true;
|
||||
} else if (strcmp(arg, "--static") == 0) {
|
||||
is_static = true;
|
||||
} else if (strcmp(arg, "--verbose") == 0) {
|
||||
verbose = true;
|
||||
} else if (strcmp(arg, "--verbose-link") == 0) {
|
||||
verbose_link = true;
|
||||
} else if (strcmp(arg, "--verbose-ir") == 0) {
|
||||
verbose_ir = true;
|
||||
} else if (strcmp(arg, "-mwindows") == 0) {
|
||||
mwindows = true;
|
||||
} else if (strcmp(arg, "-mconsole") == 0) {
|
||||
mconsole = true;
|
||||
} else if (strcmp(arg, "-municode") == 0) {
|
||||
municode = true;
|
||||
} else if (strcmp(arg, "-rdynamic") == 0) {
|
||||
rdynamic = true;
|
||||
} else if (strcmp(arg, "--each-lib-rpath") == 0) {
|
||||
each_lib_rpath = true;
|
||||
} else if (strcmp(arg, "--enable-timing-info") == 0) {
|
||||
timing_info = true;
|
||||
} else if (strcmp(arg, "--test-cmd-bin") == 0) {
|
||||
test_exec_args.append(nullptr);
|
||||
} else if (arg[1] == 'L' && arg[2] != 0) {
|
||||
// alias for --library-path
|
||||
lib_dirs.append(&arg[2]);
|
||||
} else if (strcmp(arg, "--pkg-begin") == 0) {
|
||||
if (i + 2 >= argc) {
|
||||
fprintf(stderr, "Expected 2 arguments after --pkg-begin\n");
|
||||
return usage(arg0);
|
||||
}
|
||||
CliPkg *new_cur_pkg = allocate<CliPkg>(1);
|
||||
i += 1;
|
||||
new_cur_pkg->name = argv[i];
|
||||
i += 1;
|
||||
new_cur_pkg->path = argv[i];
|
||||
new_cur_pkg->parent = cur_pkg;
|
||||
cur_pkg->children.append(new_cur_pkg);
|
||||
cur_pkg = new_cur_pkg;
|
||||
} else if (strcmp(arg, "--pkg-end") == 0) {
|
||||
if (cur_pkg->parent == nullptr) {
|
||||
fprintf(stderr, "Encountered --pkg-end with no matching --pkg-begin\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
cur_pkg = cur_pkg->parent;
|
||||
} else if (i + 1 >= argc) {
|
||||
fprintf(stderr, "Expected another argument after %s\n", arg);
|
||||
return usage(arg0);
|
||||
} else {
|
||||
i += 1;
|
||||
if (strcmp(arg, "--output") == 0) {
|
||||
out_file = argv[i];
|
||||
} else if (strcmp(arg, "--output-h") == 0) {
|
||||
out_file_h = argv[i];
|
||||
} else if (strcmp(arg, "--color") == 0) {
|
||||
if (strcmp(argv[i], "auto") == 0) {
|
||||
color = ErrColorAuto;
|
||||
} else if (strcmp(argv[i], "on") == 0) {
|
||||
color = ErrColorOn;
|
||||
} else if (strcmp(argv[i], "off") == 0) {
|
||||
color = ErrColorOff;
|
||||
} else {
|
||||
fprintf(stderr, "--color options are 'auto', 'on', or 'off'\n");
|
||||
return usage(arg0);
|
||||
}
|
||||
} else if (strcmp(arg, "--name") == 0) {
|
||||
out_name = argv[i];
|
||||
} else if (strcmp(arg, "--libc-lib-dir") == 0) {
|
||||
libc_lib_dir = argv[i];
|
||||
} else if (strcmp(arg, "--libc-static-lib-dir") == 0) {
|
||||
libc_static_lib_dir = argv[i];
|
||||
} else if (strcmp(arg, "--libc-include-dir") == 0) {
|
||||
libc_include_dir = argv[i];
|
||||
} else if (strcmp(arg, "--msvc-lib-dir") == 0) {
|
||||
msvc_lib_dir = argv[i];
|
||||
} else if (strcmp(arg, "--kernel32-lib-dir") == 0) {
|
||||
kernel32_lib_dir = argv[i];
|
||||
} else if (strcmp(arg, "--zig-install-prefix") == 0) {
|
||||
zig_install_prefix = argv[i];
|
||||
} else if (strcmp(arg, "--dynamic-linker") == 0) {
|
||||
dynamic_linker = argv[i];
|
||||
} else if (strcmp(arg, "-isystem") == 0) {
|
||||
clang_argv.append("-isystem");
|
||||
clang_argv.append(argv[i]);
|
||||
} else if (strcmp(arg, "-dirafter") == 0) {
|
||||
clang_argv.append("-dirafter");
|
||||
clang_argv.append(argv[i]);
|
||||
} else if (strcmp(arg, "-mllvm") == 0) {
|
||||
clang_argv.append("-mllvm");
|
||||
clang_argv.append(argv[i]);
|
||||
|
||||
llvm_argv.append(argv[i]);
|
||||
} else if (strcmp(arg, "--library-path") == 0 || strcmp(arg, "-L") == 0) {
|
||||
lib_dirs.append(argv[i]);
|
||||
} else if (strcmp(arg, "--library") == 0) {
|
||||
link_libs.append(argv[i]);
|
||||
} else if (strcmp(arg, "--object") == 0) {
|
||||
objects.append(argv[i]);
|
||||
} else if (strcmp(arg, "--assembly") == 0) {
|
||||
asm_files.append(argv[i]);
|
||||
} else if (strcmp(arg, "--cache-dir") == 0) {
|
||||
cache_dir = argv[i];
|
||||
} else if (strcmp(arg, "--target-arch") == 0) {
|
||||
target_arch = argv[i];
|
||||
} else if (strcmp(arg, "--target-os") == 0) {
|
||||
target_os = argv[i];
|
||||
} else if (strcmp(arg, "--target-environ") == 0) {
|
||||
target_environ = argv[i];
|
||||
} else if (strcmp(arg, "-mmacosx-version-min") == 0) {
|
||||
mmacosx_version_min = argv[i];
|
||||
} else if (strcmp(arg, "-mios-version-min") == 0) {
|
||||
mios_version_min = argv[i];
|
||||
} else if (strcmp(arg, "-framework") == 0) {
|
||||
frameworks.append(argv[i]);
|
||||
} else if (strcmp(arg, "--linker-script") == 0) {
|
||||
linker_script = argv[i];
|
||||
} else if (strcmp(arg, "-rpath") == 0) {
|
||||
rpath_list.append(argv[i]);
|
||||
} else if (strcmp(arg, "--test-filter") == 0) {
|
||||
test_filter = argv[i];
|
||||
} else if (strcmp(arg, "--test-name-prefix") == 0) {
|
||||
test_name_prefix = argv[i];
|
||||
} else if (strcmp(arg, "--ver-major") == 0) {
|
||||
ver_major = atoi(argv[i]);
|
||||
} else if (strcmp(arg, "--ver-minor") == 0) {
|
||||
ver_minor = atoi(argv[i]);
|
||||
} else if (strcmp(arg, "--ver-patch") == 0) {
|
||||
ver_patch = atoi(argv[i]);
|
||||
} else if (strcmp(arg, "--test-cmd") == 0) {
|
||||
test_exec_args.append(argv[i]);
|
||||
} else {
|
||||
fprintf(stderr, "Invalid argument: %s\n", arg);
|
||||
return usage(arg0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn printUsage(outstream: &io.OutStream) -> %void {
|
||||
%return outstream.print("Usage: {} [command] [options]\n", arg0);
|
||||
%return outstream.write(
|
||||
\\Usage: zig [command] [options]
|
||||
\\Commands:
|
||||
\\ build build project from build.zig
|
||||
\\ build-exe [source] create executable from source or object files
|
||||
@ -110,3 +267,18 @@ fn printUsage(outstream: &io.OutStream) -> %void {
|
||||
);
|
||||
%return outstream.flush();
|
||||
}
|
||||
|
||||
const ZIG_ZEN =
|
||||
\\ * Communicate intent precisely.
|
||||
\\ * Edge cases matter.
|
||||
\\ * Favor reading code over writing code.
|
||||
\\ * Only one obvious way to do things.
|
||||
\\ * Runtime crashes are better than bugs.
|
||||
\\ * Compile errors are better than runtime crashes.
|
||||
\\ * Incremental improvements.
|
||||
\\ * Avoid local maximums.
|
||||
\\ * Reduce the amount one must remember.
|
||||
\\ * Minimize energy spent on coding style.
|
||||
\\ * Together we serve end users.
|
||||
\\
|
||||
;
|
||||
|
||||
@ -1488,7 +1488,6 @@ struct CodeGen {
|
||||
Buf *root_out_name;
|
||||
bool windows_subsystem_windows;
|
||||
bool windows_subsystem_console;
|
||||
bool windows_linker_unicode;
|
||||
Buf *mmacosx_version_min;
|
||||
Buf *mios_version_min;
|
||||
bool linker_rdynamic;
|
||||
|
||||
@ -265,10 +265,6 @@ void codegen_set_windows_subsystem(CodeGen *g, bool mwindows, bool mconsole) {
|
||||
g->windows_subsystem_console = mconsole;
|
||||
}
|
||||
|
||||
void codegen_set_windows_unicode(CodeGen *g, bool municode) {
|
||||
g->windows_linker_unicode = municode;
|
||||
}
|
||||
|
||||
void codegen_set_mmacosx_version_min(CodeGen *g, Buf *mmacosx_version_min) {
|
||||
g->mmacosx_version_min = mmacosx_version_min;
|
||||
}
|
||||
|
||||
@ -35,7 +35,6 @@ void codegen_set_msvc_lib_dir(CodeGen *codegen, Buf *msvc_lib_dir);
|
||||
void codegen_set_kernel32_lib_dir(CodeGen *codegen, Buf *kernel32_lib_dir);
|
||||
void codegen_set_dynamic_linker(CodeGen *g, Buf *dynamic_linker);
|
||||
void codegen_set_windows_subsystem(CodeGen *g, bool mwindows, bool mconsole);
|
||||
void codegen_set_windows_unicode(CodeGen *g, bool municode);
|
||||
void codegen_add_lib_dir(CodeGen *codegen, const char *dir);
|
||||
LinkLib *codegen_add_link_lib(CodeGen *codegen, Buf *lib);
|
||||
void codegen_add_framework(CodeGen *codegen, const char *name);
|
||||
|
||||
@ -70,7 +70,6 @@ static int usage(const char *arg0) {
|
||||
" -rpath [path] add directory to the runtime library search path\n"
|
||||
" -mconsole (windows) --subsystem console to the linker\n"
|
||||
" -mwindows (windows) --subsystem windows to the linker\n"
|
||||
" -municode (windows) link with unicode\n"
|
||||
" -framework [name] (darwin) link against framework\n"
|
||||
" -mios-version-min [ver] (darwin) set iOS deployment target\n"
|
||||
" -mmacosx-version-min [ver] (darwin) set Mac OS X deployment target\n"
|
||||
@ -296,7 +295,6 @@ int main(int argc, char **argv) {
|
||||
const char *target_environ = nullptr;
|
||||
bool mwindows = false;
|
||||
bool mconsole = false;
|
||||
bool municode = false;
|
||||
bool rdynamic = false;
|
||||
const char *mmacosx_version_min = nullptr;
|
||||
const char *mios_version_min = nullptr;
|
||||
@ -462,8 +460,6 @@ int main(int argc, char **argv) {
|
||||
mwindows = true;
|
||||
} else if (strcmp(arg, "-mconsole") == 0) {
|
||||
mconsole = true;
|
||||
} else if (strcmp(arg, "-municode") == 0) {
|
||||
municode = true;
|
||||
} else if (strcmp(arg, "-rdynamic") == 0) {
|
||||
rdynamic = true;
|
||||
} else if (strcmp(arg, "--each-lib-rpath") == 0) {
|
||||
@ -762,7 +758,6 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
codegen_set_windows_subsystem(g, mwindows, mconsole);
|
||||
codegen_set_windows_unicode(g, municode);
|
||||
codegen_set_rdynamic(g, rdynamic);
|
||||
if (mmacosx_version_min && mios_version_min) {
|
||||
fprintf(stderr, "-mmacosx-version-min and -mios-version-min options not allowed together\n");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user