Skip to content

Commit ee49a2b

Browse files
committed
initial commit
0 parents  commit ee49a2b

File tree

7 files changed

+220
-0
lines changed

7 files changed

+220
-0
lines changed

.gitattributes

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

.github/workflows/ci.yaml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
workflow_dispatch:
11+
12+
jobs:
13+
build:
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
zig-version: [master]
18+
os: [ubuntu-latest, macos-latest, windows-latest]
19+
include:
20+
- zig-version: "0.12.1"
21+
os: ubuntu-latest
22+
- zig-version: "0.13.0"
23+
os: ubuntu-latest
24+
runs-on: ${{ matrix.os }}
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
29+
- name: Setup Zig
30+
uses: mlugg/setup-zig@v1
31+
with:
32+
version: ${{ matrix.zig-version }}
33+
34+
- name: Install Dependencies
35+
if: matrix.os == 'ubuntu-latest'
36+
run: |
37+
sudo apt-get update
38+
sudo apt-get install libgtk-3-dev libdbus-1-dev
39+
40+
- name: Check Formatting
41+
run: zig fmt --ast-check --check .
42+
43+
- name: Build
44+
run: zig build install install-tests --summary all
45+
46+
- name: Build with -Dportal
47+
if: matrix.os == 'ubuntu-latest'
48+
run: zig build install install-tests -Dportal --summary all

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.zig-cache
2+
zig-cache
3+
zig-out

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (Expat)
2+
3+
Copyright (c) contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[![CI](https://github.com/allyourcodebase/nativefiledialog-extended/actions/workflows/ci.yaml/badge.svg)](https://github.com/allyourcodebase/nativefiledialog-extended/actions)
2+
3+
# nativefiledialog-extended
4+
5+
This is [nativefiledialog-extended](https://github.com/btzy/nativefiledialog-extended), packaged for [Zig](https://ziglang.org/).
6+
7+
## Installation
8+
9+
First, update your `build.zig.zon`:
10+
11+
```
12+
# Initialize a `zig build` project if you haven't already
13+
zig init
14+
zig fetch --save git+https://github.com/allyourcodebase/nativefiledialog-extended.git#1.2.1
15+
```
16+
17+
You can then import `nativefiledialog-extended` in your `build.zig` with:
18+
19+
```zig
20+
const nfd_dependency = b.dependency("nativefiledialog-extended", .{
21+
.target = target,
22+
.optimize = optimize,
23+
});
24+
your_exe.linkLibrary(nfd_dependency.artifact("nfd"));
25+
```
26+
27+
## Dependencies
28+
29+
See https://github.com/btzy/nativefiledialog-extended/tree/v1.2.1#dependencies

build.zig

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
const std = @import("std");
2+
3+
pub fn build(b: *std.Build) void {
4+
const upstream = b.dependency("nativefiledialog-extended", .{});
5+
const target = b.standardTargetOptions(.{});
6+
const optimize = b.standardOptimizeOption(.{});
7+
8+
const strip = b.option(bool, "strip", "Omit debug information");
9+
const pic = b.option(bool, "pie", "Produce Position Independent Code");
10+
11+
const portal = b.option(bool, "portal", "Use xdg-desktop-portal instead of GTK") orelse false;
12+
const use_allowedcontenttypes_if_available = b.option(bool, "use-allowedcontenttypes-if-available", "Use allowedContentTypes for filter lists on macOS >= 11.0") orelse true;
13+
const append_extension = b.option(bool, "append-extension", "Automatically append file extension to an extensionless selection in SaveDialog()") orelse false;
14+
15+
const nfd = b.addStaticLibrary(.{
16+
.name = "nfd",
17+
.target = target,
18+
.optimize = optimize,
19+
.pic = pic,
20+
.strip = strip,
21+
});
22+
b.installArtifact(nfd);
23+
nfd.addIncludePath(upstream.path("src/include"));
24+
nfd.installHeadersDirectory(upstream.path("src/include"), "", .{ .include_extensions = &.{ ".h", ".hpp" } });
25+
if (target.result.os.tag == .windows) {
26+
nfd.linkLibCpp();
27+
nfd.addCSourceFile(.{ .file = upstream.path("src/nfd_win.cpp") });
28+
nfd.linkSystemLibrary("ole32");
29+
nfd.linkSystemLibrary("uuid");
30+
nfd.linkSystemLibrary("shell32");
31+
} else if (target.result.os.tag.isDarwin()) {
32+
nfd.addCSourceFile(.{ .file = upstream.path("src/nfd_cocoa.m") });
33+
nfd.linkFramework("AppKit");
34+
// Whether this is correct is completely untested since I don't use macOS.
35+
nfd.root_module.addCMacro("NFD_MACOS_ALLOWEDCONTENTTYPES", if (use_allowedcontenttypes_if_available) "1" else "0");
36+
if (use_allowedcontenttypes_if_available and target.result.os.isAtLeast(.macos, .{ .major = 11, .minor = 0, .patch = 0 }).?) {
37+
nfd.linkFramework("UniformTypeIdentifiers");
38+
}
39+
} else {
40+
nfd.linkLibCpp();
41+
if (append_extension) nfd.root_module.addCMacro("NFD_APPEND_EXTENSION", "1");
42+
if (portal) {
43+
nfd.addCSourceFile(.{ .file = upstream.path("src/nfd_portal.cpp") });
44+
nfd.linkSystemLibrary("dbus-1");
45+
nfd.root_module.addCMacro("NFD_PORTAL", "1");
46+
} else {
47+
nfd.addCSourceFile(.{ .file = upstream.path("src/nfd_gtk.cpp") });
48+
nfd.linkSystemLibrary("gtk+-3.0");
49+
}
50+
}
51+
52+
const install_tests_step = b.step("install-tests", "Install all test executables");
53+
54+
for (test_sources) |sub_path| {
55+
const name = b.dupe(std.fs.path.stem(sub_path));
56+
std.mem.replaceScalar(u8, name, '.', '-');
57+
std.mem.replaceScalar(u8, name, '_', '-');
58+
59+
const test_exe = b.addExecutable(.{
60+
.name = name,
61+
.target = target,
62+
.optimize = optimize,
63+
.pic = pic,
64+
.strip = strip,
65+
});
66+
test_exe.addCSourceFile(.{ .file = upstream.path("test").path(b, sub_path) });
67+
test_exe.linkLibrary(nfd);
68+
69+
install_tests_step.dependOn(&b.addInstallArtifact(test_exe, .{}).step);
70+
71+
const run_test_exe = b.addRunArtifact(test_exe);
72+
73+
const test_step = b.step(name, b.fmt("Run {s}", .{sub_path}));
74+
test_step.dependOn(&run_test_exe.step);
75+
}
76+
}
77+
78+
const test_sources: []const []const u8 = &.{
79+
"test_opendialog.c",
80+
"test_opendialog_cpp.cpp",
81+
"test_opendialog_native.c",
82+
"test_opendialog_with.c",
83+
"test_opendialog_native_with.c",
84+
"test_opendialogmultiple.c",
85+
"test_opendialogmultiple_cpp.cpp",
86+
"test_opendialogmultiple_native.c",
87+
"test_opendialogmultiple_enum.c",
88+
"test_opendialogmultiple_enum_native.c",
89+
"test_pickfolder.c",
90+
"test_pickfolder_cpp.cpp",
91+
"test_pickfolder_native.c",
92+
"test_pickfolder_with.c",
93+
"test_pickfolder_native_with.c",
94+
"test_pickfoldermultiple.c",
95+
"test_pickfoldermultiple_native.c",
96+
"test_savedialog.c",
97+
"test_savedialog_native.c",
98+
"test_savedialog_with.c",
99+
"test_savedialog_native_with.c",
100+
};

build.zig.zon

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.{
2+
.name = "nativefiledialog-extended",
3+
.version = "1.2.1",
4+
.minimum_zig_version = "0.12.0",
5+
.dependencies = .{
6+
.@"nativefiledialog-extended" = .{
7+
.url = "git+https://github.com/btzy/nativefiledialog-extended.git?ref=v1.2.1#86d5f2005fe1c00747348a12070fec493ea2407e",
8+
.hash = "1220f7fb0d64d9c6e06bff39d93abaed733afef7c64281edfd3e433bee9eba28c8cf",
9+
},
10+
},
11+
.paths = .{
12+
"build.zig",
13+
"build.zig.zon",
14+
"LICENSE",
15+
"README.md",
16+
},
17+
}

0 commit comments

Comments
 (0)