Skip to content

Commit

Permalink
hacking around
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylt committed Nov 7, 2024
1 parent 6441472 commit 78b1a65
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/zig/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
zig-out/*
.zig-cache/*
23 changes: 23 additions & 0 deletions examples/zig/build.zig
Original file line number Diff line number Diff line change
@@ -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);
}
18 changes: 18 additions & 0 deletions examples/zig/src/ex01.zig
Original file line number Diff line number Diff line change
@@ -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));
}
5 changes: 5 additions & 0 deletions examples/zig/src/ex02.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const std = @import("std");

pub fn main() void {
std.debug.print("Hello, {s}!\n", .{"Zig Build"});
}

0 comments on commit 78b1a65

Please sign in to comment.