Skip to content

Commit

Permalink
Created an errorable Meta Doc Gen Step function
Browse files Browse the repository at this point in the history
- Added `addCovaDocGenStepOrError()` to `build.zig` which will return an error in cases of Target mismatches f/ CI cross-compilation pipelines.
  • Loading branch information
00JCIV00 committed Aug 30, 2024
1 parent 8fa0d06 commit 5a0783e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ pub fn build(b: *std.Build) void {


/// Add Cova's Meta Doc Generation Step to a project's `build.zig`.
/// Note, the `program_step` must have the same Target as the host machine.
/// Prefer to use `addCovaDocGenStepOrError` if the step will be used in cross-compilation CI pipeline.
pub fn addCovaDocGenStep(
b: *std.Build,
/// The Cova Dependency of the project's `build.zig`.
Expand All @@ -125,6 +127,33 @@ pub fn addCovaDocGenStep(
);
}

/// Add Cova's Meta Doc Generation Step to a project's `build.zig` or return an error if there's a Target mismatch.
/// A Target mismatch happens if the provided `program_step` doesn't have the same Target as the host machine.
/// This function is useful for cross-compilation in CI pipelines to ensure Target mismatches are handled properly.
pub fn addCovaDocGenStepOrError(
b: *std.Build,
/// The Cova Dependency of the project's `build.zig`.
cova_dep: *std.Build.Dependency,
/// The Program Compile Step where the Command Type and Setup Command can be found.
/// This is typically created with `const exe = b.addExecutable(.{...});` or similar
program_step: *std.Build.Step.Compile,
/// The Config for Meta Doc Generation.
doc_gen_config: generate.MetaDocConfig,
) !*std.Build.Step.Run {
const host_triplets = b.graph.host.result.zigTriple(b.allocator) catch @panic("OOM");
defer b.allocator.free(host_triplets);
const program_triplets = program_step.rootModuleTarget().zigTriple(b.allocator) catch @panic("OOM");
defer b.allocator.free(program_triplets);
if (!std.mem.eql(u8, host_triplets, program_triplets)) return error.TargetMismatch;
return createDocGenStep(
b,
cova_dep.module("cova"),
cova_dep.path("src/generator.zig"),
program_step,
doc_gen_config,
);
}

/// Create the Meta Doc Generation Step.
fn createDocGenStep(
b: *std.Build,
Expand Down

0 comments on commit 5a0783e

Please sign in to comment.