| ... | ... | @@ -92,19 +92,6 @@ pub fn build(b: *Builder) !void { |
| 92 | 92 | if (enable_llvm) { |
| 93 | 93 | const cmake_cfg = if (static_llvm) null else findAndParseConfigH(b, config_h_path_option); |
| 94 | 94 | |
| 95 | | const exe_cflags = [_][]const u8{ |
| 96 | | "-std=c++14", |
| 97 | | "-D__STDC_CONSTANT_MACROS", |
| 98 | | "-D__STDC_FORMAT_MACROS", |
| 99 | | "-D__STDC_LIMIT_MACROS", |
| 100 | | "-D_GNU_SOURCE", |
| 101 | | "-fvisibility-inlines-hidden", |
| 102 | | "-fno-exceptions", |
| 103 | | "-fno-rtti", |
| 104 | | "-Werror=type-limits", |
| 105 | | "-Wno-missing-braces", |
| 106 | | "-Wno-comment", |
| 107 | | }; |
| 108 | 95 | if (is_stage1) { |
| 109 | 96 | exe.addIncludeDir("src"); |
| 110 | 97 | exe.addIncludeDir("deps/SoftFloat-3e/source/include"); |
| ... | ... | @@ -133,88 +120,14 @@ pub fn build(b: *Builder) !void { |
| 133 | 120 | if (cfg.cmake_prefix_path.len > 0) { |
| 134 | 121 | b.addSearchPrefix(cfg.cmake_prefix_path); |
| 135 | 122 | } |
| 136 | | exe.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{ |
| 137 | | cfg.cmake_binary_dir, |
| 138 | | "zigcpp", |
| 139 | | b.fmt("{s}{s}{s}", .{ exe.target.libPrefix(), "zigcpp", exe.target.staticLibSuffix() }), |
| 140 | | }) catch unreachable); |
| 141 | | assert(cfg.lld_include_dir.len != 0); |
| 142 | | exe.addIncludeDir(cfg.lld_include_dir); |
| 143 | | addCMakeLibraryList(exe, cfg.clang_libraries); |
| 144 | | addCMakeLibraryList(exe, cfg.lld_libraries); |
| 145 | | addCMakeLibraryList(exe, cfg.llvm_libraries); |
| 146 | | |
| 147 | | const need_cpp_includes = tracy != null; |
| 148 | | |
| 149 | | // System -lc++ must be used because in this code path we are attempting to link |
| 150 | | // against system-provided LLVM, Clang, LLD. |
| 151 | | if (exe.target.getOsTag() == .linux) { |
| 152 | | // First we try to static link against gcc libstdc++. If that doesn't work, |
| 153 | | // we fall back to -lc++ and cross our fingers. |
| 154 | | addCxxKnownPath(b, cfg, exe, "libstdc++.a", "", need_cpp_includes) catch |err| switch (err) { |
| 155 | | error.RequiredLibraryNotFound => { |
| 156 | | exe.linkSystemLibrary("c++"); |
| 157 | | }, |
| 158 | | else => |e| return e, |
| 159 | | }; |
| 160 | | |
| 161 | | exe.linkSystemLibrary("pthread"); |
| 162 | | } else if (exe.target.isFreeBSD()) { |
| 163 | | try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes); |
| 164 | | exe.linkSystemLibrary("pthread"); |
| 165 | | } else if (exe.target.getOsTag() == .openbsd) { |
| 166 | | try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes); |
| 167 | | try addCxxKnownPath(b, cfg, exe, "libc++abi.a", null, need_cpp_includes); |
| 168 | | } else if (exe.target.isDarwin()) { |
| 169 | | if (addCxxKnownPath(b, cfg, exe, "libgcc_eh.a", "", need_cpp_includes)) { |
| 170 | | // Compiler is GCC. |
| 171 | | try addCxxKnownPath(b, cfg, exe, "libstdc++.a", null, need_cpp_includes); |
| 172 | | exe.linkSystemLibrary("pthread"); |
| 173 | | // TODO LLD cannot perform this link. |
| 174 | | // Set ZIG_SYSTEM_LINKER_HACK env var to use system linker ld instead. |
| 175 | | // See https://github.com/ziglang/zig/issues/1535 |
| 176 | | } else |err| switch (err) { |
| 177 | | error.RequiredLibraryNotFound => { |
| 178 | | // System compiler, not gcc. |
| 179 | | exe.linkSystemLibrary("c++"); |
| 180 | | }, |
| 181 | | else => |e| return e, |
| 182 | | } |
| 183 | | } |
| 184 | 123 | |
| 185 | | if (cfg.dia_guids_lib.len != 0) { |
| 186 | | exe.addObjectFile(cfg.dia_guids_lib); |
| 187 | | } |
| 124 | try addCmakeCfgOptionsToExe(b, cfg, tracy, exe); |
| 125 | try addCmakeCfgOptionsToExe(b, cfg, tracy, test_stage2); |
| 188 | 126 | } else { |
| 189 | 127 | // Here we are -Denable-llvm but no cmake integration. |
| 190 | 128 | |
| 191 | | // Adds the Zig C++ sources which both stage1 and stage2 need. |
| 192 | | // |
| 193 | | // We need this because otherwise zig_clang_cc1_main.cpp ends up pulling |
| 194 | | // in a dependency on llvm::cfg::Update<llvm::BasicBlock*>::dump() which is |
| 195 | | // unavailable when LLVM is compiled in Release mode. |
| 196 | | const zig_cpp_cflags = exe_cflags ++ [_][]const u8{"-DNDEBUG=1"}; |
| 197 | | exe.addCSourceFiles(&zig_cpp_sources, &zig_cpp_cflags); |
| 198 | | |
| 199 | | for (clang_libs) |lib_name| { |
| 200 | | exe.linkSystemLibrary(lib_name); |
| 201 | | } |
| 202 | | |
| 203 | | for (lld_libs) |lib_name| { |
| 204 | | exe.linkSystemLibrary(lib_name); |
| 205 | | } |
| 206 | | |
| 207 | | for (llvm_libs) |lib_name| { |
| 208 | | exe.linkSystemLibrary(lib_name); |
| 209 | | } |
| 210 | | |
| 211 | | // This means we rely on clang-or-zig-built LLVM, Clang, LLD libraries. |
| 212 | | exe.linkSystemLibrary("c++"); |
| 213 | | |
| 214 | | if (target.getOs().tag == .windows) { |
| 215 | | exe.linkSystemLibrary("version"); |
| 216 | | exe.linkSystemLibrary("uuid"); |
| 217 | | } |
| 129 | try addStaticLlvmOptionsToExe(exe); |
| 130 | try addStaticLlvmOptionsToExe(test_stage2); |
| 218 | 131 | } |
| 219 | 132 | } |
| 220 | 133 | if (link_libc) { |
| ... | ... | @@ -360,6 +273,112 @@ pub fn build(b: *Builder) !void { |
| 360 | 273 | test_step.dependOn(docs_step); |
| 361 | 274 | } |
| 362 | 275 | |
| 276 | const exe_cflags = [_][]const u8{ |
| 277 | "-std=c++14", |
| 278 | "-D__STDC_CONSTANT_MACROS", |
| 279 | "-D__STDC_FORMAT_MACROS", |
| 280 | "-D__STDC_LIMIT_MACROS", |
| 281 | "-D_GNU_SOURCE", |
| 282 | "-fvisibility-inlines-hidden", |
| 283 | "-fno-exceptions", |
| 284 | "-fno-rtti", |
| 285 | "-Werror=type-limits", |
| 286 | "-Wno-missing-braces", |
| 287 | "-Wno-comment", |
| 288 | }; |
| 289 | |
| 290 | fn addCmakeCfgOptionsToExe( |
| 291 | b: *Builder, |
| 292 | cfg: CMakeConfig, |
| 293 | tracy: ?[]const u8, |
| 294 | exe: *std.build.LibExeObjStep, |
| 295 | ) !void { |
| 296 | exe.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{ |
| 297 | cfg.cmake_binary_dir, |
| 298 | "zigcpp", |
| 299 | b.fmt("{s}{s}{s}", .{ exe.target.libPrefix(), "zigcpp", exe.target.staticLibSuffix() }), |
| 300 | }) catch unreachable); |
| 301 | assert(cfg.lld_include_dir.len != 0); |
| 302 | exe.addIncludeDir(cfg.lld_include_dir); |
| 303 | addCMakeLibraryList(exe, cfg.clang_libraries); |
| 304 | addCMakeLibraryList(exe, cfg.lld_libraries); |
| 305 | addCMakeLibraryList(exe, cfg.llvm_libraries); |
| 306 | |
| 307 | const need_cpp_includes = tracy != null; |
| 308 | |
| 309 | // System -lc++ must be used because in this code path we are attempting to link |
| 310 | // against system-provided LLVM, Clang, LLD. |
| 311 | if (exe.target.getOsTag() == .linux) { |
| 312 | // First we try to static link against gcc libstdc++. If that doesn't work, |
| 313 | // we fall back to -lc++ and cross our fingers. |
| 314 | addCxxKnownPath(b, cfg, exe, "libstdc++.a", "", need_cpp_includes) catch |err| switch (err) { |
| 315 | error.RequiredLibraryNotFound => { |
| 316 | exe.linkSystemLibrary("c++"); |
| 317 | }, |
| 318 | else => |e| return e, |
| 319 | }; |
| 320 | |
| 321 | exe.linkSystemLibrary("pthread"); |
| 322 | } else if (exe.target.isFreeBSD()) { |
| 323 | try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes); |
| 324 | exe.linkSystemLibrary("pthread"); |
| 325 | } else if (exe.target.getOsTag() == .openbsd) { |
| 326 | try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes); |
| 327 | try addCxxKnownPath(b, cfg, exe, "libc++abi.a", null, need_cpp_includes); |
| 328 | } else if (exe.target.isDarwin()) { |
| 329 | if (addCxxKnownPath(b, cfg, exe, "libgcc_eh.a", "", need_cpp_includes)) { |
| 330 | // Compiler is GCC. |
| 331 | try addCxxKnownPath(b, cfg, exe, "libstdc++.a", null, need_cpp_includes); |
| 332 | exe.linkSystemLibrary("pthread"); |
| 333 | // TODO LLD cannot perform this link. |
| 334 | // Set ZIG_SYSTEM_LINKER_HACK env var to use system linker ld instead. |
| 335 | // See https://github.com/ziglang/zig/issues/1535 |
| 336 | } else |err| switch (err) { |
| 337 | error.RequiredLibraryNotFound => { |
| 338 | // System compiler, not gcc. |
| 339 | exe.linkSystemLibrary("c++"); |
| 340 | }, |
| 341 | else => |e| return e, |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | if (cfg.dia_guids_lib.len != 0) { |
| 346 | exe.addObjectFile(cfg.dia_guids_lib); |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | fn addStaticLlvmOptionsToExe( |
| 351 | exe: *std.build.LibExeObjStep, |
| 352 | ) !void { |
| 353 | // Adds the Zig C++ sources which both stage1 and stage2 need. |
| 354 | // |
| 355 | // We need this because otherwise zig_clang_cc1_main.cpp ends up pulling |
| 356 | // in a dependency on llvm::cfg::Update<llvm::BasicBlock*>::dump() which is |
| 357 | // unavailable when LLVM is compiled in Release mode. |
| 358 | const zig_cpp_cflags = exe_cflags ++ [_][]const u8{"-DNDEBUG=1"}; |
| 359 | exe.addCSourceFiles(&zig_cpp_sources, &zig_cpp_cflags); |
| 360 | |
| 361 | for (clang_libs) |lib_name| { |
| 362 | exe.linkSystemLibrary(lib_name); |
| 363 | } |
| 364 | |
| 365 | for (lld_libs) |lib_name| { |
| 366 | exe.linkSystemLibrary(lib_name); |
| 367 | } |
| 368 | |
| 369 | for (llvm_libs) |lib_name| { |
| 370 | exe.linkSystemLibrary(lib_name); |
| 371 | } |
| 372 | |
| 373 | // This means we rely on clang-or-zig-built LLVM, Clang, LLD libraries. |
| 374 | exe.linkSystemLibrary("c++"); |
| 375 | |
| 376 | if (exe.target.getOs().tag == .windows) { |
| 377 | exe.linkSystemLibrary("version"); |
| 378 | exe.linkSystemLibrary("uuid"); |
| 379 | } |
| 380 | } |
| 381 | |
| 363 | 382 | fn addCxxKnownPath( |
| 364 | 383 | b: *Builder, |
| 365 | 384 | ctx: CMakeConfig, |