Skip to content

Commit

Permalink
add ubsan runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
mattnite committed Apr 11, 2024
1 parent bd50686 commit b334a0b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 12 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ const std = @import("std");
const Build = std.Build;
const LazyPath = Build.LazyPath;

const c_flags = &.{};
const c_flags = &.{
"-fno-sanitize-trap=undefined",
};

pub fn init(b: *Build, dependency_name: []const u8) *STLink {
const st = b.allocator.create(STLink) catch @panic("OOM");
Expand All @@ -21,8 +23,13 @@ pub fn build(b: *Build) void {
.target = target,
.optimize = optimize,
});
const ubsan_runtime_dep = b.dependency("ubsan-runtime", .{
.target = target,
.optimize = optimize,
});

const libusb = libusb_dep.artifact("usb");
const ubsan_runtime = ubsan_runtime_dep.artifact("ubsan-runtime");

const version = b.addConfigHeader(.{
.style = .{
Expand Down Expand Up @@ -118,6 +125,7 @@ pub fn build(b: *Build) void {
st_flash.addConfigHeader(version);
st_flash.linkLibrary(stlink);
st_flash.linkLibrary(libusb);
st_flash.linkLibrary(ubsan_runtime);
b.installArtifact(st_flash);

const st_info = b.addExecutable(.{
Expand All @@ -135,6 +143,7 @@ pub fn build(b: *Build) void {
st_info.addConfigHeader(version);
st_info.linkLibrary(stlink);
st_info.linkLibrary(libusb);
st_info.linkLibrary(ubsan_runtime);
b.installArtifact(st_info);

const st_util = b.addExecutable(.{
Expand All @@ -158,6 +167,7 @@ pub fn build(b: *Build) void {
st_util.addConfigHeader(version);
st_util.linkLibrary(stlink);
st_util.linkLibrary(libusb);
st_util.linkLibrary(ubsan_runtime);
b.installArtifact(st_util);

const st_trace = b.addExecutable(.{
Expand All @@ -175,6 +185,7 @@ pub fn build(b: *Build) void {
st_trace.addConfigHeader(version);
st_trace.linkLibrary(stlink);
st_trace.linkLibrary(libusb);
st_trace.linkLibrary(ubsan_runtime);
b.installArtifact(st_trace);
}

Expand Down
4 changes: 4 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@
.url = "https://github.com/ZigEmbeddedGroup/libusb/archive/347fecde82bd953f5cb71aaa7060b38c9e364ed0.tar.gz",
.hash = "1220797b3fae1791cf477f11c2b0a71bc053351053eff7f960873190093398a0581a",
},
.@"ubsan-runtime" = .{
.url = "https://github.com/mattnite/ubsan-runtime/archive/c1e153c89f5ba2796817cce91e031ce5a764debd.tar.gz",
.hash = "1220ceb568e87c13985faef7b388b9422ab0fab42b5a2197f415f67a947641faefd9",
},
},
}

0 comments on commit b334a0b

Please sign in to comment.