| ... | ... | @@ -36,23 +36,33 @@ pub fn build(b: &Builder) { |
| 36 | 36 | if (findLLVM(b)) |llvm| { |
| 37 | 37 | // find the stage0 build artifacts because we're going to re-use config.h and zig_cpp library |
| 38 | 38 | const build_info = b.exec([][]const u8{b.zig_exe, "BUILD_INFO"}); |
| 39 | | var build_info_it = mem.split(build_info, "\n"); |
| 40 | | const cmake_binary_dir = ??build_info_it.next(); |
| 41 | | const cxx_compiler = ??build_info_it.next(); |
| 39 | var index: usize = 0; |
| 40 | const cmake_binary_dir = nextValue(&index, build_info); |
| 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 | 45 | var exe = b.addExecutable("zig", "src-self-hosted/main.zig"); |
| 44 | 46 | exe.setBuildMode(mode); |
| 45 | 47 | exe.addIncludeDir("src"); |
| 46 | 48 | exe.addIncludeDir(cmake_binary_dir); |
| 47 | | addCppLib(b, exe, cmake_binary_dir, "libzig_cpp"); |
| 48 | | addCppLib(b, exe, cmake_binary_dir, "libembedded_lld_elf"); |
| 49 | | addCppLib(b, exe, cmake_binary_dir, "libembedded_lld_coff"); |
| 50 | | addCppLib(b, exe, cmake_binary_dir, "libembedded_lld_lib"); |
| 49 | addCppLib(b, exe, cmake_binary_dir, "zig_cpp"); |
| 50 | if (lld_include_dir.len != 0) { |
| 51 | exe.addIncludeDir(lld_include_dir); |
| 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 | 61 | dependOnLib(exe, llvm); |
| 52 | 62 | |
| 53 | 63 | if (!exe.target.isWindows()) { |
| 54 | 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 | 66 | exe.addObjectFile(libstdcxx_path); |
| 57 | 67 | |
| 58 | 68 | exe.linkSystemLibrary("pthread"); |
| ... | ... | @@ -114,8 +124,9 @@ fn dependOnLib(lib_exe_obj: &std.build.LibExeObjStep, dep: &const LibraryDep) { |
| 114 | 124 | } |
| 115 | 125 | |
| 116 | 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 | 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 | 132 | const LibraryDep = struct { |
| ... | ... | @@ -150,7 +161,7 @@ fn findLLVM(b: &Builder) -> ?LibraryDep { |
| 150 | 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 | 165 | while (it.next()) |lib_arg| { |
| 155 | 166 | if (mem.startsWith(u8, lib_arg, "-l")) { |
| 156 | 167 | %%result.system_libs.append(lib_arg[2..]); |
| ... | ... | @@ -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 | 179 | while (it.next()) |include_arg| { |
| 169 | 180 | if (mem.startsWith(u8, include_arg, "-I")) { |
| 170 | 181 | %%result.includes.append(include_arg[2..]); |
| ... | ... | @@ -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 | 189 | while (it.next()) |libdir| { |
| 179 | 190 | if (mem.startsWith(u8, libdir, "-L")) { |
| 180 | 191 | %%result.libdirs.append(libdir[2..]); |
| ... | ... | @@ -310,3 +321,11 @@ pub fn installStdLib(b: &Builder) { |
| 310 | 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 | } |