aboutsummaryrefslogtreecommitdiff
path: root/std/build.zig
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/build.zig
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/build.zig')
-rw-r--r--std/build.zig17
1 files changed, 17 insertions, 0 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| {