aboutsummaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-09-30 21:38:04 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-09-30 21:38:04 -0700
commit3eb729b442d6cc69bd9a9d37816e9458190bc30b (patch)
treea412281c18914503c1566e79ab6a6f4eea187bf3 /build.zig
parent1f653b7f8e9e358a5bfe2695a11c01da56f3d5ee (diff)
parentc4cd592f0e1eeff5a4056796610d97010ae4e38c (diff)
downloadzig-3eb729b442d6cc69bd9a9d37816e9458190bc30b.tar.gz
zig-3eb729b442d6cc69bd9a9d37816e9458190bc30b.zip
Merge remote-tracking branch 'origin/master' into llvm13
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig79
1 files changed, 53 insertions, 26 deletions
diff --git a/build.zig b/build.zig
index 8bbf06e83a..acfb43337e 100644
--- a/build.zig
+++ b/build.zig
@@ -18,6 +18,7 @@ pub fn build(b: *Builder) !void {
const mode = b.standardReleaseOptions();
const target = b.standardTargetOptions(.{});
const single_threaded = b.option(bool, "single-threaded", "Build artifacts that run in single threaded mode") orelse false;
+ const use_zig_libcxx = b.option(bool, "use-zig-libcxx", "If libc++ is needed, use zig's bundled version, don't try to integrate with the system") orelse false;
var docgen_exe = b.addExecutable("docgen", "doc/docgen.zig");
docgen_exe.single_threaded = single_threaded;
@@ -125,10 +126,18 @@ pub fn build(b: *Builder) !void {
exe.install();
exe.setBuildMode(mode);
exe.setTarget(target);
- toolchain_step.dependOn(&exe.step);
+ if (!skip_stage2_tests) {
+ toolchain_step.dependOn(&exe.step);
+ }
b.default_step.dependOn(&exe.step);
exe.single_threaded = single_threaded;
+ if (target.isWindows() and target.getAbi() == .gnu) {
+ // LTO is currently broken on mingw, this can be removed when it's fixed.
+ exe.want_lto = false;
+ test_stage2.want_lto = false;
+ }
+
const exe_options = b.addOptions();
exe.addOptions("build_options", exe_options);
@@ -182,8 +191,8 @@ pub fn build(b: *Builder) !void {
b.addSearchPrefix(cfg.cmake_prefix_path);
}
- try addCmakeCfgOptionsToExe(b, cfg, exe);
- try addCmakeCfgOptionsToExe(b, cfg, test_stage2);
+ try addCmakeCfgOptionsToExe(b, cfg, exe, use_zig_libcxx);
+ try addCmakeCfgOptionsToExe(b, cfg, test_stage2, use_zig_libcxx);
} else {
// Here we are -Denable-llvm but no cmake integration.
try addStaticLlvmOptionsToExe(exe);
@@ -260,12 +269,24 @@ pub fn build(b: *Builder) !void {
b.allocator,
&[_][]const u8{ tracy_path, "TracyClient.cpp" },
) catch unreachable;
+
+ // On mingw, we need to opt into windows 7+ to get some features required by tracy.
+ const tracy_c_flags: []const []const u8 = if (target.isWindows() and target.getAbi() == .gnu)
+ &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined", "-D_WIN32_WINNT=0x601" }
+ else
+ &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" };
+
exe.addIncludeDir(tracy_path);
- exe.addCSourceFile(client_cpp, &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" });
+ exe.addCSourceFile(client_cpp, tracy_c_flags);
if (!enable_llvm) {
exe.linkSystemLibraryName("c++");
}
exe.linkLibC();
+
+ if (target.isWindows()) {
+ exe.linkSystemLibrary("dbghelp");
+ exe.linkSystemLibrary("ws2_32");
+ }
}
const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter");
@@ -434,6 +455,7 @@ fn addCmakeCfgOptionsToExe(
b: *Builder,
cfg: CMakeConfig,
exe: *std.build.LibExeObjStep,
+ use_zig_libcxx: bool,
) !void {
exe.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{
cfg.cmake_binary_dir,
@@ -446,28 +468,32 @@ fn addCmakeCfgOptionsToExe(
addCMakeLibraryList(exe, cfg.lld_libraries);
addCMakeLibraryList(exe, cfg.llvm_libraries);
- const need_cpp_includes = true;
-
- // System -lc++ must be used because in this code path we are attempting to link
- // against system-provided LLVM, Clang, LLD.
- if (exe.target.getOsTag() == .linux) {
- // First we try to static link against gcc libstdc++. If that doesn't work,
- // we fall back to -lc++ and cross our fingers.
- addCxxKnownPath(b, cfg, exe, "libstdc++.a", "", need_cpp_includes) catch |err| switch (err) {
- error.RequiredLibraryNotFound => {
- exe.linkSystemLibrary("c++");
- },
- else => |e| return e,
- };
- exe.linkSystemLibrary("unwind");
- } else if (exe.target.isFreeBSD()) {
- try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes);
- exe.linkSystemLibrary("pthread");
- } else if (exe.target.getOsTag() == .openbsd) {
- try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes);
- try addCxxKnownPath(b, cfg, exe, "libc++abi.a", null, need_cpp_includes);
- } else if (exe.target.isDarwin()) {
- exe.linkSystemLibrary("c++");
+ if (use_zig_libcxx) {
+ exe.linkLibCpp();
+ } else {
+ const need_cpp_includes = true;
+
+ // System -lc++ must be used because in this code path we are attempting to link
+ // against system-provided LLVM, Clang, LLD.
+ if (exe.target.getOsTag() == .linux) {
+ // First we try to static link against gcc libstdc++. If that doesn't work,
+ // we fall back to -lc++ and cross our fingers.
+ addCxxKnownPath(b, cfg, exe, "libstdc++.a", "", need_cpp_includes) catch |err| switch (err) {
+ error.RequiredLibraryNotFound => {
+ exe.linkSystemLibrary("c++");
+ },
+ else => |e| return e,
+ };
+ exe.linkSystemLibrary("unwind");
+ } else if (exe.target.isFreeBSD()) {
+ try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes);
+ exe.linkSystemLibrary("pthread");
+ } else if (exe.target.getOsTag() == .openbsd) {
+ try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes);
+ try addCxxKnownPath(b, cfg, exe, "libc++abi.a", null, need_cpp_includes);
+ } else if (exe.target.isDarwin()) {
+ exe.linkSystemLibrary("c++");
+ }
}
if (cfg.dia_guids_lib.len != 0) {
@@ -504,6 +530,7 @@ fn addStaticLlvmOptionsToExe(
if (exe.target.getOs().tag == .windows) {
exe.linkSystemLibrary("version");
exe.linkSystemLibrary("uuid");
+ exe.linkSystemLibrary("ole32");
}
}