Let’s say I have a blank project with the standard build.zig file generated with zig init (copied below with the comments and test cases removed.)
Assume I also have a file called simple.c and I want to call some functions in this from main.zig.
From this almost blank starting point, what is the most simple way I can add to build.zig?
Motivation: If I was working with a library, I’d package it as a dependency and import it via zig.build.zon but this feels unnecessarily complicated in this scenario, so I’m wondering if there’s a simple shortcut.
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const mod = b.addModule("ziginit", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
});
const exe = b.addExecutable(.{
.name = "ziginit",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "ziginit", .module = mod },
},
}),
});
b.installArtifact(exe);
const run_step = b.step("run", "Run the app");
const run_cmd = b.addRunArtifact(exe);
run_step.dependOn(&run_cmd.step);
run_cmd.step.dependOn(b.getInstallStep());
}