Skip to content

Commit

Permalink
Merge pull request #3 from kassane/0.11.0
Browse files Browse the repository at this point in the history
0.11.0 w/ debug tracing
  • Loading branch information
alvarorichard committed Aug 4, 2023
2 parents cee4eac + 09e70b2 commit 1fa038a
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 20 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
fail-fast: false
matrix:
runs-on: [ubuntu-latest, macos-latest, windows-latest]
runs-on: [ubuntu-latest]
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v3
Expand All @@ -16,7 +16,7 @@ jobs:
fetch-depth: 0
- uses: goto-bus-stop/setup-zig@v2
with:
version: 0.10.1
version: 0.11.0

- name: Build Summary
run: zig build -freference-trace
run: zig build --summary all -freference-trace
44 changes: 28 additions & 16 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
const Builder = @import("std").build.Builder;
const Builder = @import("std").Build;

pub fn build(b: *Builder) void {
const target = b.standardTargetOptions(.{});
const mode = b.standardReleaseOptions(); //-Drelease-safe|release-fast|release-small
const optimize = b.standardOptimizeOption(.{});

const lib = b.addSharedLibrary("function_parameter", "src/function_parameter.zig", .unversioned);
lib.setBuildMode(mode);
lib.setTarget(target);
const lib = b.addSharedLibrary(.{
.name = "function_parameter",
.target = target,
.optimize = optimize,
.root_source_file = .{ .path = "src/function_parameter.zig" },
});
lib.linkLibC(); // next function need libc
lib.install();

const exe = b.addExecutable("CortexC", null);
exe.addCSourceFile("src/main.c", &.{
"-Wall",
"-Wextra",
// "-Werror",
b.installArtifact(lib);

const exe = b.addExecutable(.{
.name = "CortexC",
.target = target,
.optimize = optimize,
});
exe.setBuildMode(mode);
exe.setTarget(target);
exe.addIncludePath("src");
exe.addCSourceFile(.{
.file = .{ .path = "src/main.c" },
.flags = &.{
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
},
});
exe.omit_frame_pointer = false;
exe.addIncludePath(.{ .path = "src" });
exe.linkLibrary(lib);
exe.linkLibC();
exe.install();

const run_cmd = exe.run();
b.installArtifact(exe);

const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
Expand Down
13 changes: 13 additions & 0 deletions src/function_parameter.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
#pragma once

#ifdef __cplusplus
extern "C" {
#endif
int function_parameter();
void function_body();

#if defined(__linux__) || defined(__APPLE__)
void setup_debug_handlers();
#endif

#ifdef __cplusplus
}
#endif
14 changes: 14 additions & 0 deletions src/function_parameter.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
const std = @import("std");

/// zig Debugtrace
// ref: https://gist.github.com/andrewrk/752a1f4db1a3327ee21f684cc87026e7
export fn setup_debug_handlers() void {
std.debug.maybeEnableSegfaultHandler();
}

export fn dump_stack_trace() void {
std.debug.dumpCurrentStackTrace(@returnAddress());
}

/// Communicate to zig that C main() will be provided elsewhere.
pub const _start = {};
//

extern fn next() callconv(.C) void;

const Token = enum {
Expand Down
6 changes: 5 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,11 @@ int main(int argc, char *argv[])
{



#ifdef _DEBUG
#if defined(__linux__) || defined(__APPLE__)
setup_debug_handlers();
#endif
#endif

int i, fd;

Expand Down

0 comments on commit 1fa038a

Please sign in to comment.