Skip to content

Commit 1cceeb7

Browse files
authored
Merge pull request #52 from Techatrix/dev
2 parents 47076c6 + e8b288e commit 1cceeb7

File tree

7 files changed

+1120
-232
lines changed

7 files changed

+1120
-232
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
*.zig text=auto eol=lf
2+
*.zon text=auto eol=lf

.github/workflows/build.yml

+38-16
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,49 @@ name: CI
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [master]
66
pull_request:
7-
branches: [ master ]
7+
branches: [master]
8+
workflow_dispatch:
89

910
jobs:
1011
build:
11-
1212
strategy:
13+
fail-fast: false
1314
matrix:
14-
platform: [ubuntu-latest, macos-latest, windows-latest]
15-
runs-on: ${{ matrix.platform }}
16-
15+
zig-version: [master]
16+
os: [ubuntu-latest, macos-latest, windows-latest]
17+
include:
18+
- zig-version: "0.12.1"
19+
os: ubuntu-latest
20+
- zig-version: "0.13.0"
21+
os: ubuntu-latest
22+
runs-on: ${{ matrix.os }}
1723
steps:
18-
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
19-
- uses: actions/checkout@v2
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
27+
- name: Setup Zig
28+
uses: mlugg/setup-zig@v1
29+
with:
30+
version: master
31+
32+
- name: Run Tests
33+
run: zig build test --summary all
34+
35+
- name: Setup `wasmtime`
36+
if: matrix.os == 'ubuntu-latest'
37+
uses: bytecodealliance/actions/wasmtime/setup@v1
38+
with:
39+
version: "21.0.1" # Wasmtime v22.0.0 has removed support for the "Wasmtime 13-and-prior CLI"
40+
41+
- name: Print wasmtime version
42+
if: matrix.os == 'ubuntu-latest'
43+
run: "wasmtime --version"
2044

21-
- name: Setup Zig
22-
uses: goto-bus-stop/[email protected]
23-
with:
24-
version: master
25-
26-
- name: Run tests
27-
run: |
28-
zig test known-folders.zig
45+
- name: Run Tests (wasm32-wasi)
46+
if: matrix.os == 'ubuntu-latest'
47+
run: zig build test -Dtarget=wasm32-wasi -fwasmtime --summary all
48+
env:
49+
WASMTIME_NEW_CLI: 0
50+
WASMTIME_BACKTRACE_DETAILS: 1

README.md

+26-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Keep to folders that are available on all operating systems
88

99
## API
10+
1011
```zig
1112
pub const KnownFolder = enum {
1213
home,
@@ -36,13 +37,37 @@ pub const KnownFolderConfig = struct {
3637
};
3738
3839
/// Returns a directory handle, or, if the folder does not exist, `null`.
39-
pub fn open(allocator: std.mem.Allocator, folder: KnownFolder, args: std.fs.Dir.OpenDirOptions) (std.fs.Dir.OpenError || Error)!?std.fs.Dir;
40+
pub fn open(allocator: std.mem.Allocator, folder: KnownFolder, args: std.fs.Dir.OpenOptions) (std.fs.Dir.OpenError || Error)!?std.fs.Dir;
4041
4142
/// Returns the path to the folder or, if the folder does not exist, `null`.
4243
pub fn getPath(allocator: std.mem.Allocator, folder: KnownFolder) Error!?[]const u8;
4344
```
4445

46+
## Installation
47+
48+
Initialize a `zig build` project if you haven't already.
49+
50+
```bash
51+
zig init
52+
```
53+
54+
Add the `known-folders` package to your `build.zig.zon`.
55+
56+
```bash
57+
zig fetch --save git+https://github.com/ziglibs/known-folders.git
58+
```
59+
60+
You can then import `known-folders` in your `build.zig` with:
61+
62+
```zig
63+
const known_folders = b.dependency("known-folders", .{}).module("known-folders");
64+
const exe = b.addExecutable(...);
65+
// This adds the known-folders module to the executable which can then be imported with `@import("known-folders")`
66+
exe.root_module.addImport("known-folders", known_folders);
67+
```
68+
4569
## Configuration
70+
4671
In your root file, add something like this to configure known-folders:
4772

4873
```zig

build.zig

+37
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,44 @@
11
const std = @import("std");
2+
const builtin = @import("builtin");
3+
4+
const minimum_zig_version = std.SemanticVersion.parse("0.12.0") catch unreachable;
25

36
pub fn build(b: *std.Build) void {
7+
if (comptime (builtin.zig_version.order(minimum_zig_version) == .lt)) {
8+
@compileError(std.fmt.comptimePrint(
9+
\\Your Zig version does not meet the minimum build requirement:
10+
\\ required Zig version: {[minimum_zig_version]}
11+
\\ actual Zig version: {[current_version]}
12+
\\
13+
, .{
14+
.current_version = builtin.zig_version,
15+
.minimum_zig_version = minimum_zig_version,
16+
}));
17+
}
18+
19+
const target = b.standardTargetOptions(.{});
20+
const optimize = b.standardOptimizeOption(.{});
21+
22+
const strip = b.option(bool, "strip", "Omit debug information");
23+
const test_filters = b.option([]const []const u8, "test-filter", "Skip tests that do not match any filter") orelse &[0][]const u8{};
24+
425
_ = b.addModule("known-folders", .{
526
.root_source_file = b.path("known-folders.zig"),
27+
.target = target,
28+
.optimize = optimize,
29+
.strip = strip,
630
});
31+
32+
const unit_tests = b.addTest(.{
33+
.root_source_file = b.path("known-folders.zig"),
34+
.target = target,
35+
.optimize = optimize,
36+
.strip = strip,
37+
.filters = test_filters,
38+
});
39+
40+
const run_unit_tests = b.addRunArtifact(unit_tests);
41+
42+
const test_step = b.step("test", "Run unit tests");
43+
test_step.dependOn(&run_unit_tests.step);
744
}

build.zig.zon

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.{
2-
.name = "",
2+
.name = "known-folders",
33
.version = "0.0.0",
4+
.minimum_zig_version = "0.12.0",
45
.dependencies = .{},
56
.paths = .{
67
"build.zig",

gyro.zzz

-10
This file was deleted.

0 commit comments

Comments
 (0)