-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
std.Build: add precompiled C header support
- add build-obj syntax to emit pch: `zig build-obj -femit-pch -lc++ -x c++-header test.h` `zig run -lc++ -cflags -include-pch test.pch -- main.cpp` - add a `.pch` kind Build.Step.Compile and Builder.addPrecompiledCHeader() - augment addCSourceFiles() to include an optional precompiled_header
- Loading branch information
Showing
11 changed files
with
247 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const std = @import("std"); | ||
|
||
pub fn build(b: *std.Build) void { | ||
const test_step = b.step("test", "Test it"); | ||
b.default_step = test_step; | ||
|
||
const target = b.standardTargetOptions(.{}); | ||
const optimize = b.standardOptimizeOption(.{}); | ||
|
||
// c-header | ||
{ | ||
const exe = b.addExecutable(.{ | ||
.name = "pchtest", | ||
.target = target, | ||
.optimize = optimize, | ||
.link_libc = true, | ||
}); | ||
|
||
const pch = b.addPrecompiledCHeader(.{ | ||
.name = "pch_c", | ||
.target = target, | ||
.optimize = optimize, | ||
.cpp_header = false, | ||
}, .{ | ||
.file = .{ .path = "include_a.h" }, | ||
.flags = &[_][]const u8{}, | ||
}); | ||
|
||
exe.addCSourceFile(.{ | ||
.file = .{ .path = "test.c" }, | ||
.flags = &[_][]const u8{}, | ||
.precompiled_header = pch, | ||
}); | ||
|
||
test_step.dependOn(&b.addRunArtifact(exe).step); | ||
} | ||
|
||
// c++-header | ||
{ | ||
const exe = b.addExecutable(.{ | ||
.name = "pchtest++", | ||
.target = target, | ||
.optimize = optimize, | ||
.link_libc = true, | ||
}); | ||
exe.linkLibCpp(); | ||
|
||
const pch = b.addPrecompiledCHeader(.{ | ||
.name = "pch_c++", | ||
.target = target, | ||
.optimize = optimize, | ||
.cpp_header = true, | ||
}, .{ | ||
.file = .{ .path = "include_a.h" }, | ||
.flags = &[_][]const u8{}, | ||
}); | ||
|
||
exe.addCSourceFile(.{ | ||
.file = .{ .path = "test.cpp" }, | ||
.flags = &[_][]const u8{}, | ||
.precompiled_header = pch, | ||
}); | ||
|
||
test_step.dependOn(&b.addRunArtifact(exe).step); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
|
||
#include "include_b.h" | ||
|
||
#include <string.h> | ||
#include <stdlib.h> | ||
|
||
#if defined(__cplusplus) | ||
#include <iostream> | ||
#else | ||
#include <stdio.h> | ||
#endif | ||
|
||
#define A_INCLUDED 1 | ||
|
Oops, something went wrong.