Skip to content

Commit

Permalink
update to zig 0.13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimschmidt557 committed Jul 23, 2024
1 parent b658382 commit be7659b
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ jobs:
submodules: true
- uses: goto-bus-stop/setup-zig@v2
with:
version: 0.11.0
version: 0.13.0
- name: Build
run: zig build test
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
zig-cache/
.zig-cache/
zig-out/
example.o
example
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
![CI](https://github.com/ziglibs/zig-lscolors/workflows/CI/badge.svg)

A zig library for colorizing paths according to the `LS_COLORS`
environment variable. Designed to work with Zig 0.11.0.
environment variable. Designed to work with Zig 0.13.0.

## Quick Example

Expand Down
16 changes: 8 additions & 8 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
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 optimize = b.standardOptimizeOption(.{});

const ansi_term = b.dependency("ansi-term", .{}).module("ansi-term");

const module = b.addModule("lscolors", .{
.source_file = .{ .path = "src/main.zig" },
.dependencies = &.{
.root_source_file = b.path("src/main.zig"),
.imports = &.{
.{ .name = "ansi-term", .module = ansi_term },
},
});

const main_tests = b.addTest(.{
.name = "main test suite",
.root_source_file = .{ .path = "src/main.zig" },
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
main_tests.addModule("ansi-term", ansi_term);
main_tests.root_module.addImport("ansi-term", ansi_term);

const run_main_tests = b.addRunArtifact(main_tests);

Expand All @@ -28,11 +28,11 @@ pub fn build(b: *Builder) void {

const exe = b.addExecutable(.{
.name = "example",
.root_source_file = .{ .path = "example.zig" },
.root_source_file = b.path("example.zig"),
.target = target,
.optimize = optimize,
});
exe.addModule("lscolors", module);
exe.root_module.addImport("lscolors", module);

const run_cmd = b.addRunArtifact(exe);
if (b.args) |args| {
Expand Down
10 changes: 7 additions & 3 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
.{
.name = "lscolors",
.version = "0.1.0",

.dependencies = .{
.@"ansi-term" = .{
.url = "https://github.com/ziglibs/ansi-term/archive/0989cddc6978de9d62f2cad0fd649930b6d741a1.tar.gz",
.hash = "122007dd6e7962e41d23e76dc04fae86a8022b61da53549bca27d84165143a9b50b6",
.url = "https://github.com/ziglibs/ansi-term/archive/0bb62115db6749044765fdb37c9791388e7970f2.tar.gz",
.hash = "12200719196e0abd325efa248fb03882c8fa2c7130e3ae1d57dbff72afc846b28495",
},
},
.paths = .{
"build.zig",
"build.zig.zon",
"src/",
},
}
2 changes: 1 addition & 1 deletion example.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn main() !void {
var lsc = try LsColors.fromEnv(allocator);
defer lsc.deinit();

var dir = try std.fs.cwd().openIterableDir(".", .{});
var dir = try std.fs.cwd().openDir(".", .{.iterate = true});
defer dir.close();

var iterator = dir.iterate();
Expand Down
32 changes: 16 additions & 16 deletions src/entry_types.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");
const os = std.os;
const ComptimeStringMap = std.ComptimeStringMap;
const StaticStringMap = std.StaticStringMap;
const File = std.fs.File;
const expectEqual = std.testing.expectEqual;

Expand Down Expand Up @@ -81,7 +81,7 @@ pub const EntryType = enum {

pub const len = std.meta.fields(Self).len;

const str_type_map = ComptimeStringMap(Self, .{
const str_type_map = StaticStringMap(Self).initComptime(.{
.{ "no", .Normal },
.{ "fi", .RegularFile },
.{ "di", .Directory },
Expand Down Expand Up @@ -120,35 +120,35 @@ pub const EntryType = enum {

const mode = @as(u32, @intCast(try file.mode()));

if (os.S.ISBLK(mode)) {
if (os.linux.S.ISBLK(mode)) {
return EntryType.BlockDevice;
} else if (os.S.ISCHR(mode)) {
} else if (os.linux.S.ISCHR(mode)) {
return EntryType.CharacterDevice;
} else if (os.S.ISDIR(mode)) {
} else if (os.linux.S.ISDIR(mode)) {
return EntryType.Directory;
} else if (os.S.ISFIFO(mode)) {
} else if (os.linux.S.ISFIFO(mode)) {
return EntryType.FIFO;
} else if (os.S.ISSOCK(mode)) {
} else if (os.linux.S.ISSOCK(mode)) {
return EntryType.Socket;
} else if (mode & os.S.ISUID != 0) {
} else if (mode & os.linux.S.ISUID != 0) {
return EntryType.Setuid;
} else if (mode & os.S.ISGID != 0) {
} else if (mode & os.linux.S.ISGID != 0) {
return EntryType.Setgid;
} else if (mode & os.S.ISVTX != 0) {
} else if (mode & os.linux.S.ISVTX != 0) {
return EntryType.Sticky;
} else if (os.S.ISREG(mode)) {
if (mode & os.S.IXUSR != 0) {
} else if (os.linux.S.ISREG(mode)) {
if (mode & os.linux.S.IXUSR != 0) {
return EntryType.ExecutableFile;
} else if (mode & os.S.IXGRP != 0) {
} else if (mode & os.linux.S.IXGRP != 0) {
return EntryType.ExecutableFile;
} else if (mode & os.S.IXOTH != 0) {
} else if (mode & os.linux.S.IXOTH != 0) {
return EntryType.ExecutableFile;
}

return EntryType.RegularFile;
} else if (os.S.ISLNK(mode)) {
} else if (os.linux.S.ISLNK(mode)) {
var path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
const target = try os.readlink(path, &path_buf);
const target = try std.fs.cwd().readLink(path, &path_buf);

var target_file = std.fs.cwd().openFile(target, .{}) catch return EntryType.OrphanedSymbolicLink;
target_file.close();
Expand Down
8 changes: 4 additions & 4 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ pub const LsColors = struct {
/// If the environment variable does not exist, falls back
/// to the default set of LSCOLORS rules
pub fn fromEnv(alloc: Allocator) !Self {
if (std.os.getenv("LSCOLORS")) |env| {
if (std.process.getEnvVarOwned(alloc, "LSCOLORS")) |env| {
return Self.parseStr(alloc, env);
} else {
} else |_| {
return Self.default(alloc);
}
}
Expand All @@ -127,7 +127,7 @@ pub const LsColors = struct {
self.pattern_mapping.deinit(self.allocator);
}

pub const StyleForPathError = error{TooManySymlinks} || std.fs.File.OpenError || os.ReadLinkError || std.fs.File.ModeError;
pub const StyleForPathError = error{TooManySymlinks} || std.fs.File.OpenError || std.fs.Dir.ReadLinkError || std.fs.File.ModeError;

/// Queries the style for this particular path.
/// Does not take ownership of the path. Requires no allocations.
Expand All @@ -144,7 +144,7 @@ pub const LsColors = struct {

if (style_for_type) |sty| {
if (entry_type == .SymbolicLink and self.ln_target) {
path = try os.readlink(path, &path_buf);
path = try std.fs.cwd().readLink(path, &path_buf);
continue;
}

Expand Down

0 comments on commit be7659b

Please sign in to comment.