aboutsummaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-04-16 16:47:47 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-04-16 19:12:20 -0400
commit89763c9a0d9a838439bcc6cd996c0ff2d3d0daca (patch)
treec29a0a77f248a33d02c7146488d130eae9d81bd6 /std
parent4c03746926562e4e9650eec7c4361836fabba5af (diff)
downloadzig-89763c9a0d9a838439bcc6cd996c0ff2d3d0daca.tar.gz
zig-89763c9a0d9a838439bcc6cd996c0ff2d3d0daca.zip
stage1 is now a hybrid of C++ and Zig
This modifies the build process of Zig to put all of the source files into libcompiler.a, except main.cpp and userland.cpp. Next, the build process links main.cpp, userland.cpp, and libcompiler.a into zig1. userland.cpp is a shim for functions that will later be replaced with self-hosted implementations. Next, the build process uses zig1 to build src-self-hosted/stage1.zig into libuserland.a, which does not depend on any of the things that are shimmed in userland.cpp, such as translate-c. Finally, the build process re-links main.cpp and libcompiler.a, except with libuserland.a instead of userland.cpp. Now the shims are replaced with .zig code. This provides all of the Zig standard library to the stage1 C++ compiler, and enables us to move certain things to userland, such as translate-c. As a proof of concept I have made the `zig zen` command use text defined in userland. I added `zig translate-c-2` which is a work-in-progress reimplementation of translate-c in userland, which currently calls `std.debug.panic("unimplemented")` and you can see the stack trace makes it all the way back into the C++ main() function (Thanks LemonBoy for improving that!). This could potentially let us move other things into userland, such as hashing algorithms, the entire cache system, .d file parsing, pretty much anything that libuserland.a itself doesn't need to depend on. This can also let us have `zig fmt` in stage1 without the overhead of child process execution, and without the initial compilation delay before it gets cached. See #1964
Diffstat (limited to 'std')
-rw-r--r--std/build.zig17
-rw-r--r--std/special/build_runner.zig30
2 files changed, 38 insertions, 9 deletions
diff --git a/std/build.zig b/std/build.zig
index 2bd4a9b08f..4d6c915438 100644
--- a/std/build.zig
+++ b/std/build.zig
@@ -50,6 +50,8 @@ pub const Builder = struct {
build_root: []const u8,
cache_root: []const u8,
release_mode: ?builtin.Mode,
+ override_std_dir: ?[]const u8,
+ override_lib_dir: ?[]const u8,
pub const CStd = enum {
C89,
@@ -133,6 +135,8 @@ pub const Builder = struct {
},
.have_install_step = false,
.release_mode = null,
+ .override_std_dir = null,
+ .override_lib_dir = null,
};
self.detectNativeSystemPaths();
self.default_step = self.step("default", "Build the project");
@@ -939,6 +943,7 @@ pub const LibExeObjStep = struct {
disable_gen_h: bool,
c_std: Builder.CStd,
override_std_dir: ?[]const u8,
+ override_lib_dir: ?[]const u8,
main_pkg_path: ?[]const u8,
exec_cmd_args: ?[]const ?[]const u8,
name_prefix: []const u8,
@@ -1039,6 +1044,7 @@ pub const LibExeObjStep = struct {
.c_std = Builder.CStd.C99,
.system_linker_hack = false,
.override_std_dir = null,
+ .override_lib_dir = null,
.main_pkg_path = null,
.exec_cmd_args = null,
.name_prefix = "",
@@ -1528,6 +1534,17 @@ pub const LibExeObjStep = struct {
if (self.override_std_dir) |dir| {
try zig_args.append("--override-std-dir");
try zig_args.append(builder.pathFromRoot(dir));
+ } else if (self.builder.override_std_dir) |dir| {
+ try zig_args.append("--override-std-dir");
+ try zig_args.append(builder.pathFromRoot(dir));
+ }
+
+ if (self.override_lib_dir) |dir| {
+ try zig_args.append("--override-lib-dir");
+ try zig_args.append(builder.pathFromRoot(dir));
+ } else if (self.builder.override_lib_dir) |dir| {
+ try zig_args.append("--override-lib-dir");
+ try zig_args.append(builder.pathFromRoot(dir));
}
if (self.main_pkg_path) |dir| {
diff --git a/std/special/build_runner.zig b/std/special/build_runner.zig
index 56cfe3bcb5..dfc3838577 100644
--- a/std/special/build_runner.zig
+++ b/std/special/build_runner.zig
@@ -94,6 +94,16 @@ pub fn main() !void {
return usageAndErr(&builder, false, try stderr_stream);
});
builder.addSearchPrefix(search_prefix);
+ } else if (mem.eql(u8, arg, "--override-std-dir")) {
+ builder.override_std_dir = try unwrapArg(arg_it.next(allocator) orelse {
+ warn("Expected argument after --override-std-dir\n\n");
+ return usageAndErr(&builder, false, try stderr_stream);
+ });
+ } else if (mem.eql(u8, arg, "--override-lib-dir")) {
+ builder.override_lib_dir = try unwrapArg(arg_it.next(allocator) orelse {
+ warn("Expected argument after --override-lib-dir\n\n");
+ return usageAndErr(&builder, false, try stderr_stream);
+ });
} else if (mem.eql(u8, arg, "--verbose-tokenize")) {
builder.verbose_tokenize = true;
} else if (mem.eql(u8, arg, "--verbose-ast")) {
@@ -187,15 +197,17 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void {
try out_stream.write(
\\
\\Advanced Options:
- \\ --build-file [file] Override path to build.zig
- \\ --cache-dir [path] Override path to zig cache directory
- \\ --verbose-tokenize Enable compiler debug output for tokenization
- \\ --verbose-ast Enable compiler debug output for parsing into an AST
- \\ --verbose-link Enable compiler debug output for linking
- \\ --verbose-ir Enable compiler debug output for Zig IR
- \\ --verbose-llvm-ir Enable compiler debug output for LLVM IR
- \\ --verbose-cimport Enable compiler debug output for C imports
- \\ --verbose-cc Enable compiler debug output for C compilation
+ \\ --build-file [file] Override path to build.zig
+ \\ --cache-dir [path] Override path to zig cache directory
+ \\ --override-std-dir [arg] Override path to Zig standard library
+ \\ --override-lib-dir [arg] Override path to Zig lib directory
+ \\ --verbose-tokenize Enable compiler debug output for tokenization
+ \\ --verbose-ast Enable compiler debug output for parsing into an AST
+ \\ --verbose-link Enable compiler debug output for linking
+ \\ --verbose-ir Enable compiler debug output for Zig IR
+ \\ --verbose-llvm-ir Enable compiler debug output for LLVM IR
+ \\ --verbose-cimport Enable compiler debug output for C imports
+ \\ --verbose-cc Enable compiler debug output for C compilation
\\
);
}