Skip to content

Commit 98607df

Browse files
committed
Updated readme, added native build option
1 parent 8f6ec25 commit 98607df

File tree

3 files changed

+68
-35
lines changed

3 files changed

+68
-35
lines changed

README.md

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,29 @@
22

33
This is a fork of [glfw](https://github.com/glfw/glfw), packaged for Zig. Unnecessary files have been deleted, and the build system has been replaced with build.zig.
44

5-
_Looking for Zig bindings to GLFW?_ See [mach/glfw](https://github.com/hexops/mach-glfw).
5+
_Looking for Zig bindings to GLFW?_ See [zlfw](https://github.com/Batres3/zlfw).
66

7+
## Usage
8+
```
9+
git clone https://github.com/Batres3/glfw/
10+
cd glfw
11+
zig build
12+
```
13+
14+
If you would like to integrate this into your own project, it is as simple as adding the dependency to `build.zig.zon`,
15+
and adding the following to your `build.zig`
16+
```
17+
const glfw = b.dependency("glfw", .{
18+
.target = target,
19+
.optimize = optimize,
20+
// Additional options here
21+
});
22+
23+
your_module.linkLibrary(glfw.artifact("glfw"));
24+
25+
```
26+
By default, the the library adds the `include/` folder as an include path, meaning that you may access `glfw3.h` via `GLFW/glfw3.h`, however,
27+
if you would like access to the files in `src/` you must add the `include_src` build option.
728
## Updating
829

930
To update this repository, run `./update.sh` followed by `./verify.sh` to verify the repository contents.
@@ -18,6 +39,19 @@ For supply chain security reasons (e.g. to confirm we made no patches to the cod
1839

1940
If nothing is printed, there is no diff. Deleted files, and changes to `README.md`, `build.zig`, `.github` CI files and `.gitignore` are ignored.
2041

21-
## Issues
22-
23-
Issues are tracked in the [main Mach repository](https://github.com/hexops/mach/issues?q=is%3Aissue+is%3Aopen+label%3Aglfw).
42+
## Dependencies
43+
Technically, glfw has no _explicit_ dependencies and can, in theory, obtain all necessary code to compile directly from the user,
44+
this would include things such as vulkan headers, wayland headers and so on. However, considering that one of the main selling points of zig
45+
is the seamless cross compilation, it would defeat the point to use system dependencies, as such, the necessary files are included as dependencies
46+
in `build.zig.zon`, of those dependencies, x11, wayland and vulkan, which are public, are simple forks of the sources.
47+
On the other hand the macos dependencies are private, and can only be found on mac systems, I do not have access to one of these, so for
48+
now I am using the [mach xcode repo](https://github.com/hexops/xcode-frameworks), which is maintained by the [mach](https://machengine.org/) team
49+
50+
However, I understand now wanting to depend on some other repo for dependencies to header file, therefore, I have added the `native` build option
51+
which will simply ignore the dependencies and assume that the user will provide the appropriate headers. If you are building for your own system,
52+
this method is entirely equivalent to the other one, however, you will not be able to cross-compile.
53+
54+
### Wayland
55+
There is a caveat here for wayland, since it does not provide the headers files for many of its protocols, even when natively running wayland
56+
if you would like to build it natively, you may use `wayland-scanner` to do so, see [wayland-headers](https://github.com/Batres3/wayland-headers/)
57+
to see an example of how this is done.

build.zig

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub fn build(b: *std.Build) void {
55
const target = b.standardTargetOptions(.{});
66
const optimize = b.standardOptimizeOption(.{});
77

8+
const native = b.option(bool, "native", "Do not use dependencies, use system files instead") orelse false;
89
const shared = b.option(bool, "shared", "Build as a shared library") orelse false;
910

1011
const include_src = b.option(bool, "include_src", "Add the src/ directory as an include directory") orelse false;
@@ -41,39 +42,41 @@ pub fn build(b: *std.Build) void {
4142
//
4243
// Header packaging for easy cross compilation
4344
//
44-
if (b.lazyDependency("vulkan_headers", .{
45-
.target = target,
46-
.optimize = optimize,
47-
})) |dep| {
48-
lib.installLibraryHeaders(dep.artifact("vulkan-headers"));
49-
}
50-
if (target.result.os.tag == .linux) {
51-
if (b.lazyDependency("x11_headers", .{
45+
if (!native) {
46+
if (b.lazyDependency("vulkan_headers", .{
5247
.target = target,
5348
.optimize = optimize,
5449
})) |dep| {
55-
lib.linkLibrary(dep.artifact("x11-headers"));
56-
lib.installLibraryHeaders(dep.artifact("x11-headers"));
50+
lib.installLibraryHeaders(dep.artifact("vulkan-headers"));
5751
}
58-
if (b.lazyDependency("wayland_headers", .{})) |dep| {
59-
lib.addIncludePath(dep.path("wayland"));
60-
lib.addIncludePath(dep.path("wayland-protocols"));
61-
lib.installHeadersDirectory(dep.path("wayland"), ".", .{});
62-
lib.installHeadersDirectory(dep.path("wayland-protocols"), ".", .{});
52+
if (target.result.os.tag == .linux) {
53+
if (b.lazyDependency("x11_headers", .{
54+
.target = target,
55+
.optimize = optimize,
56+
})) |dep| {
57+
lib.linkLibrary(dep.artifact("x11-headers"));
58+
lib.installLibraryHeaders(dep.artifact("x11-headers"));
59+
}
60+
if (b.lazyDependency("wayland_headers", .{})) |dep| {
61+
lib.addIncludePath(dep.path("wayland"));
62+
lib.addIncludePath(dep.path("wayland-protocols"));
63+
lib.installHeadersDirectory(dep.path("wayland"), ".", .{});
64+
lib.installHeadersDirectory(dep.path("wayland-protocols"), ".", .{});
65+
}
6366
}
64-
}
65-
66-
if (target.result.os.tag.isDarwin()) {
67-
// MacOS: this must be defined for macOS 13.3 and older.
68-
lib.root_module.addCMacro("__kernel_ptr_semantics", "");
6967

70-
if (b.lazyDependency("xcode_frameworks", .{
71-
.target = target,
72-
.optimize = optimize,
73-
})) |dep| {
74-
lib.root_module.addSystemFrameworkPath(dep.path("Frameworks"));
75-
lib.root_module.addSystemIncludePath(dep.path("include"));
76-
lib.root_module.addLibraryPath(dep.path("lib"));
68+
if (target.result.os.tag.isDarwin()) {
69+
// MacOS: this must be defined for macOS 13.3 and older.
70+
lib.root_module.addCMacro("__kernel_ptr_semantics", "");
71+
72+
if (b.lazyDependency("xcode_frameworks", .{
73+
.target = target,
74+
.optimize = optimize,
75+
})) |dep| {
76+
lib.root_module.addSystemFrameworkPath(dep.path("Frameworks"));
77+
lib.root_module.addSystemIncludePath(dep.path("include"));
78+
lib.root_module.addLibraryPath(dep.path("lib"));
79+
}
7780
}
7881
}
7982

build.zig.zon

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
"src/",
88
"build.zig",
99
"build.zig.zon",
10-
"CONTRIBUTORS.md",
1110
"LICENSE.md",
12-
"README.md",
13-
"update.sh",
14-
"verify.sh",
1511
},
1612
.dependencies = .{
1713
.xcode_frameworks = .{

0 commit comments

Comments
 (0)