From 78b1a65f2aed4903c2f73da827e9e7431d49c4e9 Mon Sep 17 00:00:00 2001 From: Jeremy L Thompson Date: Thu, 7 Nov 2024 16:58:57 -0700 Subject: [PATCH] hacking around --- examples/zig/.gitignore | 2 ++ examples/zig/build.zig | 23 +++++++++++++++++++++++ examples/zig/src/ex01.zig | 18 ++++++++++++++++++ examples/zig/src/ex02.zig | 5 +++++ 4 files changed, 48 insertions(+) create mode 100644 examples/zig/.gitignore create mode 100644 examples/zig/build.zig create mode 100644 examples/zig/src/ex01.zig create mode 100644 examples/zig/src/ex02.zig diff --git a/examples/zig/.gitignore b/examples/zig/.gitignore new file mode 100644 index 0000000000..8073ae36c5 --- /dev/null +++ b/examples/zig/.gitignore @@ -0,0 +1,2 @@ +zig-out/* +.zig-cache/* diff --git a/examples/zig/build.zig b/examples/zig/build.zig new file mode 100644 index 0000000000..a46ab5f013 --- /dev/null +++ b/examples/zig/build.zig @@ -0,0 +1,23 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) void { + const exe_name = b.option( + []const u8, + "exe_name", + "Name of the executable", + ) orelse "ex01"; + var buffer = [_]u8{undefined} ** 16; + const exe_path = std.fmt.bufPrint(&buffer, "src/{s}.zig", .{exe_name}) catch |err| std.debug.panic("Error: {any}", .{err}); + const exe = b.addExecutable(.{ + .name = exe_name, + .root_source_file = b.path(exe_path), + .target = b.standardTargetOptions(.{}), + .optimize = b.standardOptimizeOption(.{}), + }); + exe.addIncludePath(b.path("../../include")); + exe.addLibraryPath(b.path("../../lib")); + exe.linkSystemLibrary("ceed"); + exe.linkLibC(); + + b.installArtifact(exe); +} diff --git a/examples/zig/src/ex01.zig b/examples/zig/src/ex01.zig new file mode 100644 index 0000000000..2fc2e814ae --- /dev/null +++ b/examples/zig/src/ex01.zig @@ -0,0 +1,18 @@ +const std = @import("std"); +const libceed = @cImport({ + @cInclude("ceed/ceed.h"); +}); + +fn ceed_call(err: c_int) void { + if (err != libceed.CEED_ERROR_SUCCESS) { + std.debug.panic("libCEED Error: {s}", .{libceed.CeedErrorTypes[@intCast(err)]}); + } +} + +pub fn main() void { + var ceed: libceed.Ceed = undefined; + + ceed_call(libceed.CeedInit("/cpu/self", &ceed)); + ceed_call(libceed.CeedView(ceed, libceed.stdout)); + ceed_call(libceed.CeedDestroy(&ceed)); +} diff --git a/examples/zig/src/ex02.zig b/examples/zig/src/ex02.zig new file mode 100644 index 0000000000..c12d570e93 --- /dev/null +++ b/examples/zig/src/ex02.zig @@ -0,0 +1,5 @@ +const std = @import("std"); + +pub fn main() void { + std.debug.print("Hello, {s}!\n", .{"Zig Build"}); +}