Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This package exposes two modules: `wgpu-c` and `wgpu`.
## Adding this package to your build
Add the package to your dependencies, either with:
```sh
zig fetch --save https://github.com/bronter/wgpu_native_zig/archive/refs/tags/v6.5.0.tar.gz
zig fetch --save https://github.com/bronter/wgpu_native_zig/archive/refs/tags/v7.0.0.tar.gz
```
or by manually adding to your `build.zig.zon`:
```zig
Expand All @@ -24,7 +24,7 @@ or by manually adding to your `build.zig.zon`:
// You can either use a commit hash:
.url="https://github.com/bronter/wgpu_native_zig/archive/<commit_hash>.tar.gz",
// or a tagged release:
// .url = "https://github.com/bronter/wgpu_native_zig/archive/refs/tags/v6.5.0.tar.gz`
// .url = "https://github.com/bronter/wgpu_native_zig/archive/refs/tags/v7.0.0.tar.gz`
.hash="<dependency hash>"
}
}
Expand Down Expand Up @@ -97,7 +97,7 @@ b.getInstallStep().dependOn(&install_dll.step);

## Building `wgpu-native`

`wgpu-native` v25.0.2.1 is built from its pinned source commit by default. The matching
`wgpu-native` v29.0.0.0 is built from its pinned source commit by default. The matching
`webgpu-headers` commit is pinned separately, so the generated C ABI does not drift when
an upstream branch changes.

Expand Down
137 changes: 72 additions & 65 deletions build.zig.zon

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion build/WgpuNativeArtifact.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const std = @import("std");
const Platform = @import("platform/root.zig");
const addDirectoryFiles = @import("file_tree.zig").addDirectoryFiles;

pub const Result = struct {
header: std.Build.LazyPath,
Expand Down Expand Up @@ -76,7 +77,12 @@ fn buildSource(
if (source_dependency == null or headers_dependency == null) return null;

const staged_source = b.addWriteFiles();
_ = staged_source.addCopyDirectory(source_dependency.?.path(""), "", .{});
addDirectoryFiles(
b,
staged_source,
source_dependency.?.path(""),
"",
);
_ = staged_source.addCopyDirectory(
headers_dependency.?.path(""),
"ffi/webgpu-headers",
Expand All @@ -86,6 +92,12 @@ fn buildSource(
headers_dependency.?.path("webgpu.h"),
"ffi/webgpu.h",
);
if (!Platform.patchSource(
b,
staged_source,
source_dependency.?.path(""),
platform,
)) return null;
const source_root = staged_source.getDirectory();

const cargo = b.addSystemCommand(&.{
Expand All @@ -96,6 +108,10 @@ fn buildSource(
});
cargo.setName(b.fmt("build wgpu-native for {s}", .{platform.rust_target}));
cargo.addFileArg(source_root.path(b, "Cargo.toml"));
if (Platform.hasSourceCargoConfig(platform)) {
cargo.addArg("--config");
cargo.addFileArg(source_root.path(b, ".cargo/config.toml"));
}
cargo.addArgs(&.{ "--target", platform.rust_target, "--target-dir" });
const cargo_target_dir = cargo.addOutputDirectoryArg("wgpu-native-target");
if (optimize != .Debug) cargo.addArg("--release");
Expand Down
32 changes: 32 additions & 0 deletions build/file_tree.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const std = @import("std");

pub fn addDirectoryFiles(
b: *std.Build,
staged_source: *std.Build.Step.WriteFile,
source: std.Build.LazyPath,
destination: []const u8,
) void {
const resolved = source.getPath3(b, null);
var directory = resolved.root_dir.handle.openDir(
b.graph.io,
resolved.subPathOrDot(),
.{ .iterate = true },
) catch |err| std.debug.panic(
"unable to open {s}: {s}",
.{ source.getPath(b), @errorName(err) },
);
defer directory.close(b.graph.io);

var iterator = directory.walk(b.allocator) catch @panic("out of memory");
defer iterator.deinit();
while (iterator.next(b.graph.io) catch |err| std.debug.panic(
"unable to walk {s}: {s}",
.{ source.getPath(b), @errorName(err) },
)) |entry| {
if (entry.kind != .file) continue;
_ = staged_source.addCopyFile(
source.path(b, entry.path),
b.pathJoin(&.{ destination, entry.path }),
);
}
}
Loading
Loading