| author | |
| committer | |
| log | 36ff26609b1d81a253053e7d7785392fae240dab |
| tree | 5226307e3861ac8d9c944ffa611a84f6205a55a6 |
| parent | 6281a511e130aeb4f7c777de9b90c60d7c8c6f34 |
8 files changed, 54 insertions(+), 21 deletions(-)
build.zig+31-12| ... | @@ -36,23 +36,33 @@ pub fn build(b: &Builder) { | ... | @@ -36,23 +36,33 @@ pub fn build(b: &Builder) { |
| 36 | if (findLLVM(b)) |llvm| { | 36 | if (findLLVM(b)) |llvm| { |
| 37 | // find the stage0 build artifacts because we're going to re-use config.h and zig_cpp library | 37 | // find the stage0 build artifacts because we're going to re-use config.h and zig_cpp library |
| 38 | const build_info = b.exec([][]const u8{b.zig_exe, "BUILD_INFO"}); | 38 | const build_info = b.exec([][]const u8{b.zig_exe, "BUILD_INFO"}); |
| 39 | var build_info_it = mem.split(build_info, "\n"); | 39 | var index: usize = 0; |
| 40 | const cmake_binary_dir = ??build_info_it.next(); | 40 | const cmake_binary_dir = nextValue(&index, build_info); |
| 41 | const cxx_compiler = ??build_info_it.next(); | 41 | const cxx_compiler = nextValue(&index, build_info); |
| 42 | const lld_include_dir = nextValue(&index, build_info); | ||
| 43 | const lld_libraries = nextValue(&index, build_info); | ||
| 42 | 44 | ||
| 43 | var exe = b.addExecutable("zig", "src-self-hosted/main.zig"); | 45 | var exe = b.addExecutable("zig", "src-self-hosted/main.zig"); |
| 44 | exe.setBuildMode(mode); | 46 | exe.setBuildMode(mode); |
| 45 | exe.addIncludeDir("src"); | 47 | exe.addIncludeDir("src"); |
| 46 | exe.addIncludeDir(cmake_binary_dir); | 48 | exe.addIncludeDir(cmake_binary_dir); |
| 47 | addCppLib(b, exe, cmake_binary_dir, "libzig_cpp"); | 49 | addCppLib(b, exe, cmake_binary_dir, "zig_cpp"); |
| 48 | addCppLib(b, exe, cmake_binary_dir, "libembedded_lld_elf"); | 50 | if (lld_include_dir.len != 0) { |
| 49 | addCppLib(b, exe, cmake_binary_dir, "libembedded_lld_coff"); | 51 | exe.addIncludeDir(lld_include_dir); |
| 50 | addCppLib(b, exe, cmake_binary_dir, "libembedded_lld_lib"); | 52 | var it = mem.split(lld_libraries, ";"); |
| 53 | while (it.next()) |lib| { | ||
| 54 | exe.addObjectFile(lib); | ||
| 55 | } | ||
| 56 | } else { | ||
| 57 | addCppLib(b, exe, cmake_binary_dir, "embedded_lld_elf"); | ||
| 58 | addCppLib(b, exe, cmake_binary_dir, "embedded_lld_coff"); | ||
| 59 | addCppLib(b, exe, cmake_binary_dir, "embedded_lld_lib"); | ||
| 60 | } | ||
| 51 | dependOnLib(exe, llvm); | 61 | dependOnLib(exe, llvm); |
| 52 | 62 | ||
| 53 | if (!exe.target.isWindows()) { | 63 | if (!exe.target.isWindows()) { |
| 54 | const libstdcxx_path_padded = b.exec([][]const u8{cxx_compiler, "-print-file-name=libstdc++.a"}); | 64 | const libstdcxx_path_padded = b.exec([][]const u8{cxx_compiler, "-print-file-name=libstdc++.a"}); |
| 55 | const libstdcxx_path = ??mem.split(libstdcxx_path_padded, "\n").next(); | 65 | const libstdcxx_path = ??mem.split(libstdcxx_path_padded, "\r\n").next(); |
| 56 | exe.addObjectFile(libstdcxx_path); | 66 | exe.addObjectFile(libstdcxx_path); |
| 57 | 67 | ||
| 58 | exe.linkSystemLibrary("pthread"); | 68 | exe.linkSystemLibrary("pthread"); |
| ... | @@ -114,8 +124,9 @@ fn dependOnLib(lib_exe_obj: &std.build.LibExeObjStep, dep: &const LibraryDep) { | ... | @@ -114,8 +124,9 @@ fn dependOnLib(lib_exe_obj: &std.build.LibExeObjStep, dep: &const LibraryDep) { |
| 114 | } | 124 | } |
| 115 | 125 | ||
| 116 | fn addCppLib(b: &Builder, lib_exe_obj: &std.build.LibExeObjStep, cmake_binary_dir: []const u8, lib_name: []const u8) { | 126 | fn addCppLib(b: &Builder, lib_exe_obj: &std.build.LibExeObjStep, cmake_binary_dir: []const u8, lib_name: []const u8) { |
| 127 | const lib_prefix = if (lib_exe_obj.target.isWindows()) "" else "lib"; | ||
| 117 | lib_exe_obj.addObjectFile(%%os.path.join(b.allocator, cmake_binary_dir, "zig_cpp", | 128 | lib_exe_obj.addObjectFile(%%os.path.join(b.allocator, cmake_binary_dir, "zig_cpp", |
| 118 | b.fmt("{}{}", lib_name, lib_exe_obj.target.libFileExt()))); | 129 | b.fmt("{}{}{}", lib_prefix, lib_name, lib_exe_obj.target.libFileExt()))); |
| 119 | } | 130 | } |
| 120 | 131 | ||
| 121 | const LibraryDep = struct { | 132 | const LibraryDep = struct { |
| ... | @@ -150,7 +161,7 @@ fn findLLVM(b: &Builder) -> ?LibraryDep { | ... | @@ -150,7 +161,7 @@ fn findLLVM(b: &Builder) -> ?LibraryDep { |
| 150 | .libdirs = ArrayList([]const u8).init(b.allocator), | 161 | .libdirs = ArrayList([]const u8).init(b.allocator), |
| 151 | }; | 162 | }; |
| 152 | { | 163 | { |
| 153 | var it = mem.split(libs_output, " \n"); | 164 | var it = mem.split(libs_output, " \r\n"); |
| 154 | while (it.next()) |lib_arg| { | 165 | while (it.next()) |lib_arg| { |
| 155 | if (mem.startsWith(u8, lib_arg, "-l")) { | 166 | if (mem.startsWith(u8, lib_arg, "-l")) { |
| 156 | %%result.system_libs.append(lib_arg[2..]); | 167 | %%result.system_libs.append(lib_arg[2..]); |
| ... | @@ -164,7 +175,7 @@ fn findLLVM(b: &Builder) -> ?LibraryDep { | ... | @@ -164,7 +175,7 @@ fn findLLVM(b: &Builder) -> ?LibraryDep { |
| 164 | } | 175 | } |
| 165 | } | 176 | } |
| 166 | { | 177 | { |
| 167 | var it = mem.split(includes_output, " \n"); | 178 | var it = mem.split(includes_output, " \r\n"); |
| 168 | while (it.next()) |include_arg| { | 179 | while (it.next()) |include_arg| { |
| 169 | if (mem.startsWith(u8, include_arg, "-I")) { | 180 | if (mem.startsWith(u8, include_arg, "-I")) { |
| 170 | %%result.includes.append(include_arg[2..]); | 181 | %%result.includes.append(include_arg[2..]); |
| ... | @@ -174,7 +185,7 @@ fn findLLVM(b: &Builder) -> ?LibraryDep { | ... | @@ -174,7 +185,7 @@ fn findLLVM(b: &Builder) -> ?LibraryDep { |
| 174 | } | 185 | } |
| 175 | } | 186 | } |
| 176 | { | 187 | { |
| 177 | var it = mem.split(libdir_output, " \n"); | 188 | var it = mem.split(libdir_output, " \r\n"); |
| 178 | while (it.next()) |libdir| { | 189 | while (it.next()) |libdir| { |
| 179 | if (mem.startsWith(u8, libdir, "-L")) { | 190 | if (mem.startsWith(u8, libdir, "-L")) { |
| 180 | %%result.libdirs.append(libdir[2..]); | 191 | %%result.libdirs.append(libdir[2..]); |
| ... | @@ -310,3 +321,11 @@ pub fn installStdLib(b: &Builder) { | ... | @@ -310,3 +321,11 @@ pub fn installStdLib(b: &Builder) { |
| 310 | b.installFile(src_path, dest_path); | 321 | b.installFile(src_path, dest_path); |
| 311 | } | 322 | } |
| 312 | } | 323 | } |
| 324 | |||
| 325 | fn nextValue(index: &usize, build_info: []const u8) -> []const u8 { | ||
| 326 | const start = *index; | ||
| 327 | while (build_info[*index] != '\n' and build_info[*index] != '\r') : (*index += 1) { } | ||
| 328 | const result = build_info[start..*index]; | ||
| 329 | *index += 1; | ||
| 330 | return result; | ||
| 331 | } |
src-self-hosted/c.zig+1| ... | @@ -1,4 +1,5 @@ | ... | @@ -1,4 +1,5 @@ |
| 1 | pub use @cImport({ | 1 | pub use @cImport({ |
| 2 | @cInclude("inttypes.h"); | ||
| 2 | @cInclude("config.h"); | 3 | @cInclude("config.h"); |
| 3 | @cInclude("zig_llvm.h"); | 4 | @cInclude("zig_llvm.h"); |
| 4 | }); | 5 | }); |
src/config.h.in+2| ... | @@ -27,5 +27,7 @@ | ... | @@ -27,5 +27,7 @@ |
| 27 | // Used for communicating build information to self hosted build. | 27 | // Used for communicating build information to self hosted build. |
| 28 | #define ZIG_CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@" | 28 | #define ZIG_CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@" |
| 29 | #define ZIG_CXX_COMPILER "@CMAKE_CXX_COMPILER@" | 29 | #define ZIG_CXX_COMPILER "@CMAKE_CXX_COMPILER@" |
| 30 | #define ZIG_LLD_INCLUDE_PATH "@LLD_INCLUDE_DIRS@" | ||
| 31 | #define ZIG_LLD_LIBRARIES "@LLD_LIBRARIES@" | ||
| 30 | 32 | ||
| 31 | #endif | 33 | #endif |
src/link.cpp+4-2| ... | @@ -426,8 +426,7 @@ static void construct_linker_job_coff(LinkJob *lj) { | ... | @@ -426,8 +426,7 @@ static void construct_linker_job_coff(LinkJob *lj) { |
| 426 | if (g->is_static) { | 426 | if (g->is_static) { |
| 427 | Buf *cmt_lib_name = buf_sprintf("libcmt%s.lib", d_str); | 427 | Buf *cmt_lib_name = buf_sprintf("libcmt%s.lib", d_str); |
| 428 | lj->args.append(buf_ptr(cmt_lib_name)); | 428 | lj->args.append(buf_ptr(cmt_lib_name)); |
| 429 | } | 429 | } else { |
| 430 | else { | ||
| 431 | Buf *msvcrt_lib_name = buf_sprintf("msvcrt%s.lib", d_str); | 430 | Buf *msvcrt_lib_name = buf_sprintf("msvcrt%s.lib", d_str); |
| 432 | lj->args.append(buf_ptr(msvcrt_lib_name)); | 431 | lj->args.append(buf_ptr(msvcrt_lib_name)); |
| 433 | } | 432 | } |
| ... | @@ -452,6 +451,9 @@ static void construct_linker_job_coff(LinkJob *lj) { | ... | @@ -452,6 +451,9 @@ static void construct_linker_job_coff(LinkJob *lj) { |
| 452 | // } | 451 | // } |
| 453 | //} | 452 | //} |
| 454 | //lj->args.append(get_libc_static_file(g, "crtbegin.o")); | 453 | //lj->args.append(get_libc_static_file(g, "crtbegin.o")); |
| 454 | |||
| 455 | // msvcrt depends on kernel32 | ||
| 456 | lj->args.append("kernel32.lib"); | ||
| 455 | } else { | 457 | } else { |
| 456 | lj->args.append("-NODEFAULTLIB"); | 458 | lj->args.append("-NODEFAULTLIB"); |
| 457 | if (!is_library) { | 459 | if (!is_library) { |
src/main.cpp+1-1| ... | @@ -267,7 +267,7 @@ static void add_package(CodeGen *g, CliPkg *cli_pkg, PackageTableEntry *pkg) { | ... | @@ -267,7 +267,7 @@ static void add_package(CodeGen *g, CliPkg *cli_pkg, PackageTableEntry *pkg) { |
| 267 | 267 | ||
| 268 | int main(int argc, char **argv) { | 268 | int main(int argc, char **argv) { |
| 269 | if (argc == 2 && strcmp(argv[1], "BUILD_INFO") == 0) { | 269 | if (argc == 2 && strcmp(argv[1], "BUILD_INFO") == 0) { |
| 270 | printf("%s\n%s\n", ZIG_CMAKE_BINARY_DIR, ZIG_CXX_COMPILER); | 270 | printf("%s\n%s\n%s\n%s\n", ZIG_CMAKE_BINARY_DIR, ZIG_CXX_COMPILER, ZIG_LLD_INCLUDE_PATH, ZIG_LLD_LIBRARIES); |
| 271 | return 0; | 271 | return 0; |
| 272 | } | 272 | } |
| 273 | 273 |
std/buffer.zig+5-4| ... | @@ -112,11 +112,12 @@ pub const Buffer = struct { | ... | @@ -112,11 +112,12 @@ pub const Buffer = struct { |
| 112 | // TODO: remove, use OutStream for this | 112 | // TODO: remove, use OutStream for this |
| 113 | pub fn appendByteNTimes(self: &Buffer, byte: u8, count: usize) -> %void { | 113 | pub fn appendByteNTimes(self: &Buffer, byte: u8, count: usize) -> %void { |
| 114 | var prev_size: usize = self.len(); | 114 | var prev_size: usize = self.len(); |
| 115 | %return self.resize(prev_size + count); | 115 | const new_size = prev_size + count; |
| 116 | %return self.resize(new_size); | ||
| 116 | 117 | ||
| 117 | var i: usize = 0; | 118 | var i: usize = prev_size; |
| 118 | while (i < count) : (i += 1) { | 119 | while (i < new_size) : (i += 1) { |
| 119 | self.list.items[prev_size + i] = byte; | 120 | self.list.items[i] = byte; |
| 120 | } | 121 | } |
| 121 | } | 122 | } |
| 122 | 123 |
std/os/index.zig+2-2| ... | @@ -851,7 +851,7 @@ pub fn makePath(allocator: &Allocator, full_path: []const u8) -> %void { | ... | @@ -851,7 +851,7 @@ pub fn makePath(allocator: &Allocator, full_path: []const u8) -> %void { |
| 851 | // march end_index backward until next path component | 851 | // march end_index backward until next path component |
| 852 | while (true) { | 852 | while (true) { |
| 853 | end_index -= 1; | 853 | end_index -= 1; |
| 854 | if (resolved_path[end_index] == '/') | 854 | if (os.path.isSep(resolved_path[end_index])) |
| 855 | break; | 855 | break; |
| 856 | } | 856 | } |
| 857 | continue; | 857 | continue; |
| ... | @@ -864,7 +864,7 @@ pub fn makePath(allocator: &Allocator, full_path: []const u8) -> %void { | ... | @@ -864,7 +864,7 @@ pub fn makePath(allocator: &Allocator, full_path: []const u8) -> %void { |
| 864 | // march end_index forward until next path component | 864 | // march end_index forward until next path component |
| 865 | while (true) { | 865 | while (true) { |
| 866 | end_index += 1; | 866 | end_index += 1; |
| 867 | if (end_index == resolved_path.len or resolved_path[end_index] == '/') | 867 | if (end_index == resolved_path.len or os.path.isSep(resolved_path[end_index])) |
| 868 | break; | 868 | break; |
| 869 | } | 869 | } |
| 870 | } | 870 | } |
std/os/path.zig+8| ... | @@ -22,6 +22,14 @@ pub const delimiter = if (is_windows) delimiter_windows else delimiter_posix; | ... | @@ -22,6 +22,14 @@ pub const delimiter = if (is_windows) delimiter_windows else delimiter_posix; |
| 22 | 22 | ||
| 23 | const is_windows = builtin.os == builtin.Os.windows; | 23 | const is_windows = builtin.os == builtin.Os.windows; |
| 24 | 24 | ||
| 25 | pub fn isSep(byte: u8) -> bool { | ||
| 26 | if (is_windows) { | ||
| 27 | return byte == '/' or byte == '\\'; | ||
| 28 | } else { | ||
| 29 | return byte == '/'; | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 25 | /// Naively combines a series of paths with the native path seperator. | 33 | /// Naively combines a series of paths with the native path seperator. |
| 26 | /// Allocates memory for the result, which must be freed by the caller. | 34 | /// Allocates memory for the result, which must be freed by the caller. |
| 27 | pub fn join(allocator: &Allocator, paths: ...) -> %[]u8 { | 35 | pub fn join(allocator: &Allocator, paths: ...) -> %[]u8 { |