Skip to content
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
12 changes: 8 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@ jobs:
matrix:
zig-version: [master]
os: [ubuntu-latest, macos-latest, windows-latest]
# include:
# - zig-version: "0.14.0"
# os: ubuntu-latest
include:
- zig-version: "0.14.1"
os: ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Zig
uses: mlugg/setup-zig@v1
uses: mlugg/setup-zig@v2
with:
version: master

- name: Run zig fmt
if: matrix.os == 'ubuntu-latest'
run: zig fmt --check .

- name: Run Tests
run: zig build test --summary all

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn getPath(allocator: std.mem.Allocator, folder: KnownFolder) Error!?[]const
## Installation

> [!NOTE]
> The minimum supported Zig version is `0.14.0-dev.3445+6c3cbb0c8`.
> The minimum supported Zig version is `0.14.0`.

Initialize a `zig build` project if you haven't already.

Expand Down
6 changes: 5 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const std = @import("std");
const builtin = @import("builtin");

const minimum_zig_version = std.SemanticVersion.parse("0.14.0-dev.3445+6c3cbb0c8") catch unreachable;
const minimum_zig_version = std.SemanticVersion.parse("0.14.0") catch unreachable;

pub fn build(b: *std.Build) void {
if (comptime (builtin.zig_version.order(minimum_zig_version) == .lt)) {
Expand All @@ -28,6 +28,10 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
.strip = strip,
});
if (target.result.os.tag == .windows) {
mod.linkSystemLibrary("shell32", .{});
mod.linkSystemLibrary("ole32", .{});
}

const unit_tests = b.addTest(.{
.root_module = mod,
Expand Down
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.{
.name = .known_folders,
.version = "0.0.0",
.minimum_zig_version = "0.14.0-dev.3445+6c3cbb0c8",
.minimum_zig_version = "0.14.0",
.dependencies = .{},
.paths = .{
"build.zig",
Expand Down
17 changes: 3 additions & 14 deletions known-folders.zig
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,8 @@ pub const KnownFolderConfig = struct {
xdg_on_mac: bool = false,
};

const OpenOptions = if (@import("builtin").zig_version.order(std.SemanticVersion.parse("0.14.0-dev.211+0cc42d090") catch unreachable) == .lt)
std.fs.Dir.OpenDirOptions
else
std.fs.Dir.OpenOptions;

/// Returns a directory handle, or, if the folder does not exist, `null`.
pub fn open(allocator: std.mem.Allocator, folder: KnownFolder, args: OpenOptions) (std.fs.Dir.OpenError || Error)!?std.fs.Dir {
pub fn open(allocator: std.mem.Allocator, folder: KnownFolder, args: std.fs.Dir.OpenOptions) (std.fs.Dir.OpenError || Error)!?std.fs.Dir {
const path = try getPath(allocator, folder) orelse return null;
defer allocator.free(path);
return try std.fs.cwd().openDir(path, args);
Expand Down Expand Up @@ -370,12 +365,7 @@ const TestingSystem = struct {

const prefix = std.base64.standard.Encoder.encode(buffer, kv.path);

const writeFile = if (comptime builtin.zig_version.order(std.SemanticVersion.parse("0.13.0-dev.68+b86c4bde6") catch unreachable) == .lt)
std.fs.Dir.writeFile2
else
std.fs.Dir.writeFile;

writeFile(tmp_dir.dir, .{
tmp_dir.dir.writeFile(.{
.sub_path = prefix,
.data = data,
}) catch |err| {
Expand Down Expand Up @@ -423,8 +413,7 @@ fn xdgUserDirLookup(
std.debug.assert(std.mem.endsWith(u8, folder_type, "_DIR"));

const folder_name = folder_type["XDG_".len .. folder_type.len - "_DIR".len];
std.debug.assert( //
std.mem.eql(u8, folder_name, "DESKTOP") or
std.debug.assert(std.mem.eql(u8, folder_name, "DESKTOP") or
std.mem.eql(u8, folder_name, "DOWNLOAD") or
std.mem.eql(u8, folder_name, "TEMPLATES") or
std.mem.eql(u8, folder_name, "PUBLICSHARE") or
Expand Down