Skip to content

Commit

Permalink
Update to zig 0.13.0 (#37)
Browse files Browse the repository at this point in the history
* Update to zig 0.13.0

- Remove zig-sqlite from vendored deps...use build.zig.zon instead
- ansi-term isn't quite up to zig-0.13.0 yet so keep it vendored

* Update GitHub Actions
  • Loading branch information
malcolmstill authored Jun 16, 2024
1 parent 06d23ad commit a345923
Show file tree
Hide file tree
Showing 52 changed files with 223 additions and 276,897 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ jobs:
- uses: actions/checkout@v2
- uses: goto-bus-stop/setup-zig@v1
with:
version: 0.10.0
version: 0.13.0
- run: echo -n $GITHUB_REF_NAME > src/.version
- run: zig build
- run: echo "zig-out/bin" >> $GITHUB_PATH
- uses: charmbracelet/vhs-action@v1
with:
path: 'demo.tape'
path: "demo.tape"
- uses: actions/upload-artifact@v3
with:
name: demo-${{ github.ref_name }}.gif
Expand All @@ -32,16 +32,16 @@ jobs:
- uses: actions/checkout@v2
- uses: goto-bus-stop/setup-zig@v1
with:
version: 0.10.0
version: 0.13.0
- run: echo -n $GITHUB_REF_NAME > src/.version
- run: zig build -Drelease-safe=true -Dtarget=${{ matrix.target }}-${{ matrix.os }}
- uses: actions/upload-artifact@v3
if: ${{ matrix.os != 'windows' }}
if: ${{ matrix.os != 'windows' }}
with:
name: clerk-${{ github.ref_name }}-${{ matrix.target }}-${{ matrix.os }}
path: zig-out/bin/clerk
- uses: actions/upload-artifact@v3
if: ${{ matrix.os == 'windows' }}
if: ${{ matrix.os == 'windows' }}
with:
name: clerk-${{ github.ref_name }}-${{ matrix.target }}-${{ matrix.os }}
path: zig-out/bin/clerk.exe
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ jobs:
- uses: actions/checkout@v2
- uses: goto-bus-stop/setup-zig@v1
with:
version: 0.10.0
version: 0.13.0
- run: zig build -Dtarget=${{ matrix.target }}-${{ matrix.os }}
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: goto-bus-stop/setup-zig@v1
with:
version: 0.10.0
version: 0.13.0
- run: zig fmt --check src/*.zig
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
zig-out
zig-cache
.zig-cache
bin
clerk.db
.clerk.db
Expand Down
84 changes: 55 additions & 29 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,44 +1,70 @@
const std = @import("std");

pub fn build(b: *std.build.Builder) void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const mode = b.standardReleaseOptions();

const sqlite = b.addStaticLibrary("sqlite", null);
sqlite.addCSourceFile("lib/zig-sqlite/c/sqlite3.c", &[_][]const u8{ "-std=c99", "-DSQLITE_ENABLE_FTS5" });
sqlite.setTarget(target);
sqlite.setBuildMode(mode);
sqlite.linkLibC();

const exe = b.addExecutable("clerk", "src/main.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
exe.addPackagePath("ansi-term", "lib/ansi-term/src/main.zig");
exe.linkLibrary(sqlite);
exe.addPackagePath("sqlite", "lib/zig-sqlite/sqlite.zig");
exe.addIncludePath("lib/zig-sqlite/c");
exe.install();

const run_cmd = exe.run();
const sqlite = b.dependency("sqlite", .{
.target = target,
.optimize = optimize,
});

const @"ansi-term" = b.dependency("ansi-term", .{
.target = target,
.optimize = optimize,
});

const exe = b.addExecutable(.{
.name = "clerk",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("sqlite", sqlite.module("sqlite"));
exe.root_module.addImport("ansi-term", @"ansi-term".module("ansi-term"));

// links the bundled sqlite3, so leave this out if you link the system one
exe.linkLibrary(sqlite.artifact("sqlite"));

// This declares intent for the executable to be installed into the
// standard location when the user invokes the "install" step (the default
// step when running `zig build`).
b.installArtifact(exe);

// This *creates* a Run step in the build graph, to be executed when another
// step is evaluated that depends on it. The next line below will establish
// such a dependency.
const run_cmd = b.addRunArtifact(exe);

// By making the run step depend on the install step, it will be run from the
// installation directory rather than directly from within the cache directory.
// This is not necessary, however, if the application depends on other installed
// files, this ensures they will be present and in the expected location.
run_cmd.step.dependOn(b.getInstallStep());

// This allows the user to pass arguments to the application in the build
// command itself, like this: `zig build run -- arg1 arg2 etc`
if (b.args) |args| {
run_cmd.addArgs(args);
}

// This creates a build step. It will be visible in the `zig build --help` menu,
// and can be selected like this: `zig build run`
// This will evaluate the `run` step rather than the default, which is "install".
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);

const exe_tests = b.addTest("src/main.zig");
exe_tests.setTarget(target);
exe_tests.setBuildMode(mode);
const exe_unit_tests = b.addTest(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});

const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);

// Similar to creating the run step earlier, this exposes a `test` step to
// the `zig build --help` menu, providing a way for the user to request
// running the unit tests.
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&exe_tests.step);
test_step.dependOn(&run_exe_unit_tests.step);
}
17 changes: 17 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.{
.name = "clerk",
.version = "0.0.0",
.dependencies = .{
.sqlite = .{
.url = "https://github.com/vrischmann/zig-sqlite/archive/91e5fedd15c5ea3cb42ccceefb3d0f4bb9bad68f.tar.gz",
.hash = "1220ba277845cb3cece7a7a1f929b920c97e9085bb644471c5dc8c72571f1485c75f",
},
.@"ansi-term" = .{
// ansi-term not yet on zig-0.13.0
// .url = "https://github.com/ziglibs/ansi-term/archive/f9ea80dc9769dfffbb4c56a904149940c79168da.tar.gz",
// .hash = "1220c650d57ceb323d3e74945189aaae7a9c0ac74afd023cba5533fb7d5874b2955c",
.path = "lib/ansi-term",
},
},
.paths = .{""},
}
6 changes: 6 additions & 0 deletions lib/ansi-term/.github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
47 changes: 47 additions & 0 deletions lib/ansi-term/.github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Documentation

on:
push:
branches: [master]

# Allow manually starting the workflow.
workflow_dispatch:

# If two concurrent runs are started,
# prefer the latest one.
concurrency:
group: "pages"
cancel-in-progress: true

jobs:

build:
name: Build docs website
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: goto-bus-stop/setup-zig@v2
with:
version: 0.12.0
- name: Build
run: zig build docs
- name: Upload
uses: actions/upload-pages-artifact@v3
with:
path: "zig-out/docs/"

publish:
name: Publish website
runs-on: ubuntu-latest
needs: build # wait for build to finish
permissions:
# Request sufficient permissions to publish the website.
pages: write
id-token: write
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
10 changes: 3 additions & 7 deletions lib/ansi-term/.github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ name: CI

on:
push:
paths:
- '**.zig'
pull_request:
paths:
- '**.zig'
schedule:
- cron: '0 0 * * *'

Expand All @@ -17,11 +13,11 @@ jobs:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: true
- uses: goto-bus-stop/setup-zig@v1
- uses: goto-bus-stop/setup-zig@v2
with:
version: master
version: 0.12.0
- name: Build
run: zig build test
1 change: 1 addition & 0 deletions lib/ansi-term/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
zig-cache/
zig-out/
deps.zig
gyro.lock
8 changes: 8 additions & 0 deletions lib/ansi-term/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ Zig library for dealing with ANSI Terminals (escape codes, styles, etc.)
This was originally code which was extracted from
[lscolors](https://github.com/ziglibs/lscolors) for use in
other zig libraries. More features have been added since.

`ansi-term` is designed to work with Zig 0.12.0.

## Documentation

Automatically generated documentation for the project
can be found at https://ziglibs.github.io/ansi-term/.
Note that autodoc is currently in beta; the website may be broken or incomplete.
31 changes: 24 additions & 7 deletions lib/ansi-term/build.zig
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
const Builder = @import("std").build.Builder;
const Build = @import("std").Build;

pub fn build(b: *Builder) void {
pub fn build(b: *Build) void {
const target = b.standardTargetOptions(.{});
const mode = b.standardReleaseOptions();
const optimize = b.standardOptimizeOption(.{});

var main_tests = b.addTest("src/main.zig");
main_tests.setTarget(target);
main_tests.setBuildMode(mode);
_ = b.addModule("ansi-term", .{
.root_source_file = b.path("src/main.zig"),
});

var main_tests = b.addTest(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});

const run_main_tests = b.addRunArtifact(main_tests);

const test_step = b.step("test", "Run library tests");
test_step.dependOn(&main_tests.step);
test_step.dependOn(&run_main_tests.step);

const install_docs = b.addInstallDirectory(.{
.source_dir = main_tests.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "docs",
});

const docs_step = b.step("docs", "Generate documentation");
docs_step.dependOn(&install_docs.step);
}
9 changes: 9 additions & 0 deletions lib/ansi-term/build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.{
.name = "ansi-term",
.version = "0.0.0",
.paths = .{
"build.zig",
"build.zig.zon",
"src/",
},
}
41 changes: 40 additions & 1 deletion lib/ansi-term/src/cursor.zig
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
const std = @import("std");

const testing = std.testing;
const fixedBufferStream = std.io.fixedBufferStream;
const esc = "\x1B";
const csi = esc ++ "[";

pub const CursorMode = enum(u8) {
blinking_block = 1,
block,
blinking_underscore,
underscore,
blinking_I_beam,
I_beam,
};

pub fn setCursorMode(writer: anytype, mode: CursorMode) !void {
const modeNumber = @intFromEnum(mode);
try writer.print(csi ++ "{d} q", .{modeNumber});
}

pub fn hideCursor(writer: anytype) !void {
try writer.writeAll(csi ++ "?25l");
}
Expand Down Expand Up @@ -62,3 +77,27 @@ pub fn scrollUp(writer: anytype, lines: usize) !void {
pub fn scrollDown(writer: anytype, lines: usize) !void {
try writer.print(csi ++ "{}T", .{lines});
}

test "test cursor mode BLINKING_UNDERSCORE" {
var buf: [1024]u8 = undefined;
var fixed_buf_stream = fixedBufferStream(&buf);

try setCursorMode(fixed_buf_stream.writer(), .blinking_underscore);
// the space is needed
const expected = csi ++ "3 q";
const actual = fixed_buf_stream.getWritten();

try testing.expectEqualSlices(u8, expected, actual);
}

test "test cursor mode BLINKING_I_BEAM" {
var buf: [1024]u8 = undefined;
var fixed_buf_stream = fixedBufferStream(&buf);

try setCursorMode(fixed_buf_stream.writer(), .blinking_I_beam);
// the space is needed
const expected = csi ++ "5 q";
const actual = fixed_buf_stream.getWritten();

try testing.expectEqualSlices(u8, expected, actual);
}
3 changes: 1 addition & 2 deletions lib/ansi-term/src/format.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const csi = esc ++ "[";

const reset = csi ++ "0m";

const font_style_codes = std.ComptimeStringMap([]const u8, .{
const font_style_codes = std.StaticStringMap([]const u8).initComptime(.{
.{ "bold", "1" },
.{ "dim", "2" },
.{ "italic", "3" },
Expand Down Expand Up @@ -302,4 +302,3 @@ test "Grey background color" {

try testing.expectEqualSlices(u8, expected, actual);
}

Loading

0 comments on commit a345923

Please sign in to comment.