Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

give this project some more care #52

Merged
merged 16 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 15 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
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;
ikskuh marked this conversation as resolved.
Show resolved Hide resolved

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);
}
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.{
.name = "",
.name = "known-folders",
.version = "0.0.0",
.dependencies = .{},
.paths = .{
Expand Down
10 changes: 0 additions & 10 deletions gyro.zzz

This file was deleted.

Loading