Skip to content

Instantly share code, notes, and snippets.

@lachlanm-git
Created December 29, 2023 10:41
Show Gist options
  • Save lachlanm-git/1bb71b376ad96ac0628e2cc0aa40cff9 to your computer and use it in GitHub Desktop.
Save lachlanm-git/1bb71b376ad96ac0628e2cc0aa40cff9 to your computer and use it in GitHub Desktop.
[WINDOWS] build.zig > clang_rt.profile-x86_64.lib
/// Placed in the `compiler-rt/` folder of llvm-project: https://github.com/llvm/llvm-project
/// This builds the clang_rt.profile (for Windows) so that it can be linked with zig `--coverage`
/// to produce successful linking and .gcda files.
///
/// It should be pretty straightforward to make this more cross-platform.
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const lib = b.addStaticLibrary(.{
.name = "clang_rt.profile-x86_64",
.target = target,
.optimize = optimize,
});
lib.linkLibC();
lib.addIncludePath(.{ .path = "include" });
lib.addIncludePath(.{ .path = "lib/profile" });
lib.addCSourceFiles(&.{
"lib/profile/GCDAProfiling.c",
"lib/profile/InstrProfiling.c",
"lib/profile/InstrProfilingInternal.c",
"lib/profile/InstrProfilingValue.c",
"lib/profile/InstrProfilingBuffer.c",
"lib/profile/InstrProfilingFile.c",
"lib/profile/InstrProfilingMerge.c",
"lib/profile/InstrProfilingMergeFile.c",
"lib/profile/InstrProfilingNameVar.c",
"lib/profile/InstrProfilingVersionVar.c",
"lib/profile/InstrProfilingWriter.c",
"lib/profile/InstrProfilingPlatformDarwin.c",
"lib/profile/InstrProfilingPlatformFuchsia.c",
"lib/profile/InstrProfilingPlatformLinux.c",
"lib/profile/InstrProfilingPlatformOther.c",
"lib/profile/InstrProfilingPlatformWindows.c",
"lib/profile/InstrProfilingRuntime.cpp",
"lib/profile/InstrProfilingUtil.c",
// Windows
"lib/profile/WindowsMMap.c",
}, &.{
"-D_WIN32",
});
b.installArtifact(lib);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment