Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor cleanup zig #7588

Merged
merged 3 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci_manager.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ jobs:
- 'src/**'
- 'build.zig'
- 'build.zig.zon'
- '.github/workflows/ci_zig.yml'
other_than_zig:
- '**/*'
- '!src/**'
- '!build.zig'
- '!build.zig.zon'
- '!.github/workflows/ci_zig.yml'
call-zig-workflow:
needs: check-changes
Expand Down
9 changes: 2 additions & 7 deletions .github/workflows/ci_zig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,8 @@ jobs:
run: |
zig-out\bin\roc.exe -h | findstr "Usage:"
- name: zig tests (Unix)
if: runner.os != 'Windows'
run: ./zig-out/bin/test

- name: zig tests (Windows)
if: runner.os == 'Windows'
run: zig-out\bin\test.exe
- name: zig tests
run: zig build test

- name: check if statically linked (ubuntu)
if: startsWith(matrix.os, 'ubuntu')
Expand Down
17 changes: 8 additions & 9 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
const std = @import("std");
const builtin = @import("builtin");
const afl = @import("zig-afl-kit");
const LazyPath = std.Build.LazyPath;
const ResolvedTarget = std.Build.ResolvedTarget;
const OptimizeMode = std.builtin.OptimizeMode;
const Import = std.Build.Module.Import;

pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const target = b.standardTargetOptions(.{ .default_target = .{
.abi = if (builtin.target.os.tag == .linux) .musl else null,
} });
const optimize = b.standardOptimizeOption(.{});

// Zig unicode library - https://codeberg.org/atman/zg
Expand All @@ -17,13 +20,12 @@ pub fn build(b: *std.Build) void {
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
exe.root_module.addImport("GenCatData", zg.module("GenCatData"));

b.installArtifact(exe);

const run_cmd = b.addRunArtifact(exe);

run_cmd.step.dependOn(b.getInstallStep());

if (b.args) |args| {
Expand All @@ -37,6 +39,7 @@ pub fn build(b: *std.Build) void {
.root_source_file = b.path("src/test.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
all_tests.root_module.addImport("GenCatData", zg.module("GenCatData"));

Expand All @@ -47,9 +50,7 @@ pub fn build(b: *std.Build) void {
b.installArtifact(all_tests);

const run_tests = b.addRunArtifact(all_tests);

const test_step = b.step("test", "Run all tests included in src/tests.zig");

test_step.dependOn(&run_tests.step);

// Fuzz targets
Expand All @@ -62,7 +63,6 @@ pub fn build(b: *std.Build) void {
b,
fuzz,
target,
optimize,
"cli",
b.path("src/fuzz/cli.zig"),
&[_]Import{
Expand All @@ -75,7 +75,6 @@ fn add_fuzz_target(
b: *std.Build,
fuzz: *std.Build.Step,
target: ResolvedTarget,
optimize: OptimizeMode,
name: []const u8,
root_source_file: LazyPath,
imports: []const Import,
Expand All @@ -96,7 +95,7 @@ fn add_fuzz_target(
.name = name_obj.items,
.root_source_file = root_source_file,
.target = target,
.optimize = .Debug,
.optimize = .ReleaseSafe,
});

for (imports) |import| {
Expand All @@ -108,7 +107,7 @@ fn add_fuzz_target(
fuzz_obj.root_module.stack_check = false; // not linking with compiler-rt
fuzz_obj.root_module.link_libc = true; // afl runtime depends on libc

const fuzz_exe = afl.addInstrumentedExe(b, target, optimize, fuzz_obj);
const fuzz_exe = afl.addInstrumentedExe(b, target, .ReleaseSafe, fuzz_obj);
const fuzz_step = b.step(name_exe.items, step_msg.items);
fuzz_step.dependOn(&b.addInstallBinFile(fuzz_exe, name_exe.items).step);

Expand Down
2 changes: 2 additions & 0 deletions src/fuzz/cli.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/// This is just a silly fuzz test to start getting the infra setup.
/// It shows the basic that other fuzz tests likely should build off of.
///
/// Note: Compiling the fuzz tests requires llvm and does not currently work in our nix shell on all systems.
///
/// To run:
/// 1. zig build fuzz-cli
/// 2. ./zig-out/AFLplusplus/bin/afl-fuzz -i src/fuzz/cli-corpus/ -o /tmp/cli-out/ zig-out/bin/fuzz-cli
Expand Down
6 changes: 1 addition & 5 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ pub fn fatal(comptime format: []const u8, args: anytype) noreturn {
}

pub fn main() !void {
var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){};
defer {
_ = general_purpose_allocator.deinit();
}
const gpa = general_purpose_allocator.allocator();
const gpa = std.heap.c_allocator;

var arena_instance = std.heap.ArenaAllocator.init(gpa);
defer arena_instance.deinit();
Expand Down