Skip to content

Commit

Permalink
Merge pull request #52 from Techatrix/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Techatrix authored Jul 31, 2024
2 parents 47076c6 + e8b288e commit 1cceeb7
Show file tree
Hide file tree
Showing 7 changed files with 1,120 additions and 232 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.zig text=auto eol=lf
*.zon text=auto eol=lf
54 changes: 38 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,49 @@ name: CI

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]
workflow_dispatch:

jobs:
build:

strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}

zig-version: [master]
os: [ubuntu-latest, macos-latest, windows-latest]
include:
- zig-version: "0.12.1"
os: ubuntu-latest
- zig-version: "0.13.0"
os: ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v4

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

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

- name: Setup `wasmtime`
if: matrix.os == 'ubuntu-latest'
uses: bytecodealliance/actions/wasmtime/setup@v1
with:
version: "21.0.1" # Wasmtime v22.0.0 has removed support for the "Wasmtime 13-and-prior CLI"

- name: Print wasmtime version
if: matrix.os == 'ubuntu-latest'
run: "wasmtime --version"

- name: Setup Zig
uses: goto-bus-stop/[email protected]
with:
version: master

- name: Run tests
run: |
zig test known-folders.zig
- name: Run Tests (wasm32-wasi)
if: matrix.os == 'ubuntu-latest'
run: zig build test -Dtarget=wasm32-wasi -fwasmtime --summary all
env:
WASMTIME_NEW_CLI: 0
WASMTIME_BACKTRACE_DETAILS: 1
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Keep to folders that are available on all operating systems

## API

```zig
pub const KnownFolder = enum {
home,
Expand Down Expand Up @@ -36,13 +37,37 @@ pub const KnownFolderConfig = struct {
};
/// Returns a directory handle, or, if the folder does not exist, `null`.
pub fn open(allocator: std.mem.Allocator, folder: KnownFolder, args: std.fs.Dir.OpenDirOptions) (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;
/// Returns the path to the folder or, if the folder does not exist, `null`.
pub fn getPath(allocator: std.mem.Allocator, folder: KnownFolder) Error!?[]const u8;
```

## Installation

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

```bash
zig init
```

Add the `known-folders` package to your `build.zig.zon`.

```bash
zig fetch --save git+https://github.com/ziglibs/known-folders.git
```

You can then import `known-folders` in your `build.zig` with:

```zig
const known_folders = b.dependency("known-folders", .{}).module("known-folders");
const exe = b.addExecutable(...);
// This adds the known-folders module to the executable which can then be imported with `@import("known-folders")`
exe.root_module.addImport("known-folders", known_folders);
```

## Configuration

In your root file, add something like this to configure known-folders:

```zig
Expand Down
37 changes: 37 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,44 @@
const std = @import("std");
const builtin = @import("builtin");

const minimum_zig_version = std.SemanticVersion.parse("0.12.0") catch unreachable;

pub fn build(b: *std.Build) void {
if (comptime (builtin.zig_version.order(minimum_zig_version) == .lt)) {
@compileError(std.fmt.comptimePrint(
\\Your Zig version does not meet the minimum build requirement:
\\ required Zig version: {[minimum_zig_version]}
\\ actual Zig version: {[current_version]}
\\
, .{
.current_version = builtin.zig_version,
.minimum_zig_version = minimum_zig_version,
}));
}

const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

const strip = b.option(bool, "strip", "Omit debug information");
const test_filters = b.option([]const []const u8, "test-filter", "Skip tests that do not match any filter") orelse &[0][]const u8{};

_ = b.addModule("known-folders", .{
.root_source_file = b.path("known-folders.zig"),
.target = target,
.optimize = optimize,
.strip = strip,
});

const unit_tests = b.addTest(.{
.root_source_file = b.path("known-folders.zig"),
.target = target,
.optimize = optimize,
.strip = strip,
.filters = test_filters,
});

const run_unit_tests = b.addRunArtifact(unit_tests);

const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_unit_tests.step);
}
3 changes: 2 additions & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.{
.name = "",
.name = "known-folders",
.version = "0.0.0",
.minimum_zig_version = "0.12.0",
.dependencies = .{},
.paths = .{
"build.zig",
Expand Down
10 changes: 0 additions & 10 deletions gyro.zzz

This file was deleted.

Loading

0 comments on commit 1cceeb7

Please sign in to comment.