Skip to content

Commit

Permalink
Merge pull request #18 from chances/dmd
Browse files Browse the repository at this point in the history
Allow DMD toolchain >= 2.107.0
  • Loading branch information
chances authored Feb 10, 2024
2 parents 04dfd58 + 936a8af commit fba65ae
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 52 deletions.
29 changes: 18 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,36 @@ jobs:
test:
name: Tests

runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, macos-12]
# TODO: os: [ubuntu-latest, macos-12, windows-latest]
compiler: [ldc-1.36.0, dmd-2.107.0]
# FIXME: ImportC doesn't emit `struct` constructors?
# Undefined symbols for architecture x86_64:
# "__C.WGPURenderPassDescriptor.__initwgpu_bindings", referenced from:
# @trusted wgpu.api.RenderPass wgpu.api.CommandEncoder.beginRenderPass(const(__C.WGPURenderPassDescriptor)) in wgpu-d-test-unittest.o
exclude:
- os: macos-12
compiler: dmd-2.107.0

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v1
- name: Install D compiler
uses: dlang-community/setup-dlang@v1
with:
compiler: ldc-1.35.0-beta1
compiler: ${{ matrix.compiler }}
# - name: Install *nix Dependencies
# if: runner.os == 'Linux'
# run: sudo apt-get install --quiet -y libglfw3 libglfw3-dev
- name: Lint
run: dub lint
run: dub run dscanner -- lint -f github source
# - name: Integration Test
# run: make headless
# run: dub build wgpu-d:headless
- name: Test
run: env LD_LIBRARY_PATH=lib make cover
run: make cover
- name: Upload Coverage to Codecov
if: success()
run: bash <(curl -s https://codecov.io/bash)
# - name: Upload Test Log Artifact on Failure
# uses: actions/upload-artifact@v1
# if: failure()
# with:
# name: Linux_Meson_Testlog
# path: build/meson-logs/testlog.txt
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Install D compiler
uses: dlang-community/setup-dlang@v1
with:
compiler: ldc-1.35.0-beta1
compiler: ldc-1.36.0
- name: Build Documentation
run: make docs

Expand Down
17 changes: 11 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,23 @@ endif
ifndef LIB_WGPU
$(error Unsupported target OS '$(OS)')
endif
LIB_WGPU_SOURCE := subprojects/wgpu
$(LIB_WGPU_SOURCE): subprojects/wgpu.Makefile
@make -C subprojects -f wgpu.Makefile
$(LIB_WGPU_SOURCE)/$(LIB_WGPU): $(LIB_WGPU_SOURCE)
wgpu: $(LIB_WGPU_SOURCE)/$(LIB_WGPU)
subprojects/wgpu: subprojects/wgpu.Makefile
@make --no-print-directory -C subprojects -f wgpu.Makefile
ifneq ($(OS),Windows_NT)
file subprojects/wgpu/$(LIB_WGPU)
else
IF EXIST subprojects/wgpu/$(LIB_WGPU) ECHO subprojects/wgpu/$(LIB_WGPU) exists.
endif
subprojects/wgpu/$(LIB_WGPU): subprojects/wgpu
wgpu: subprojects/wgpu/$(LIB_WGPU)
.PHONY: wgpu

#################################################
# Test Coverage
#################################################
cover: $(SOURCES)
dub test --build=unittest-cov
.PHONY: cover

#################################################
# Documentation
Expand All @@ -67,7 +72,7 @@ docs/sitemap.xml: $(SOURCES)
# Footer
@$(SED) -i -e "/<p class=\"faint\">Generated using the DDOX documentation generator<\/p>/r views/footer.html" -e "/<p class=\"faint\">Generated using the DDOX documentation generator<\/p>/d" `find docs -name '*.html'`
# Dub Package Version
@echo `git describe --tags --abbrev=0`
@echo Latest tag: `git describe --tags --abbrev=0`
@$(SED) -i "s/DUB_VERSION/$(PACKAGE_VERSION)/g" `find docs -name '*.html'`
@echo Done

Expand Down
2 changes: 1 addition & 1 deletion dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"targetPath": "bin",
"toolchainRequirements": {
"frontend": ">=2.105",
"dmd": "no",
"dmd": ">=2.107.0",
"gdc": "no",
"ldc": ">=1.35.0-beta1"
},
Expand Down
3 changes: 2 additions & 1 deletion examples/triangle/dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
}
},
"versions": ["GLFW_32"],
"versions-linux": ["Linux"],
"subConfigurations": {
"bindbc-glfw": "static",
"wgpu-d": "static"
},
"preGenerateCommands": [
"make -C subprojects -f glfw.Makefile"
"make --no-print-directory -C subprojects -f glfw.Makefile"
],
"lflags-posix": ["$PACKAGE_DIR/subprojects/glfw/src/libglfw3.a"],
"lflags-windows": ["/LIBPATH:$PACKAGE_DIR/subprojects/glfw/src"],
Expand Down
43 changes: 30 additions & 13 deletions examples/triangle/source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import wgpu.api;

package:

version (OSX) enum SUPPORTED_TARGET = true;
version (Linux) enum SUPPORTED_TARGET = true;
version (Windows) enum SUPPORTED_TARGET = true;
static if (!__traits(compiles, SUPPORTED_TARGET)) enum SUPPORTED_TARGET = false;
static assert(SUPPORTED_TARGET, "Unsupported target platform");

string lastError = null;
extern(C) void wgpu_glfw_error_callback(int error, const char* description) nothrow {
import std.conv : ConvException;
Expand Down Expand Up @@ -56,6 +62,7 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4f {
// Adapted from https://github.com/gfx-rs/wgpu-native/blob/v0.10.4.1/examples/triangle/main.c
// See also https://sotrh.github.io/learn-wgpu/beginner/tutorial5-textures
void main() {
import std.exception : enforce;
import std.functional : toDelegate;
import std.string : toStringz;
import std.typecons : Yes;
Expand Down Expand Up @@ -88,22 +95,18 @@ void main() {

Surface surface;
version (OSX) {
import std.exception : enforce;

auto nativeWindow = NSWindow.from(enforce(glfwGetCocoaWindow(window), lastError));
auto nativeWindow = NSWindow.from(glfwGetCocoaWindow(window).enforce, lastError);
auto metalLayer = CAMetalLayer.classOf.layer;
nativeWindow.contentView.wantsLayer = true;
nativeWindow.contentView.layer = metalLayer;
surface = Surface.fromMetalLayer(instance, metalLayer.asId);
} else {
version (Linux) surface = Surface.fromXlib(instance, glfwGetX11Display().enforce, glfwGetX11Window(window).enforce);
else {
version (Windows) {
import core.sys.windows.windows : GetModuleHandleA;
surface = Surface.fromWindowsHwnd(instance, GetModuleHandleA(null), glfwGetWin32Window(window));
}
else static assert(0, "Unsupported target platform");
}
}
version (Linux) {
surface = Surface.fromXlib(instance, glfwGetX11Display().enforce, glfwGetX11Window(window).enforce.to!uint);
}
version (Windows) {
import core.sys.windows.windows : GetModuleHandleA;
surface = Surface.fromWindowsHwnd(instance, GetModuleHandleA(null), glfwGetWin32Window(window));
}
assert(surface.id !is null, "Could not create native surface");

Expand Down Expand Up @@ -306,8 +309,22 @@ auto bindDelegate(Func, string file = __FILE__, size_t line = __LINE__)(Func f)

version (Windows) {
import core.sys.windows.windows : HWND;
// FIXME: What's wrong with https://github.com/BindBC/bindbc-glfw/blob/6529ce4f67f69839a93de5e0bbe1150fab30d633/source/bindbc/glfw/bindstatic.d#L172
// FIXME: Undefined return types: https://github.com/BindBC/bindbc-glfw/blob/6529ce4f67f69839a93de5e0bbe1150fab30d633/source/bindbc/glfw/bindstatic.d#L172
extern(C) @nogc nothrow HWND glfwGetWin32Window(GLFWwindow* window);
extern(C) @nogc nothrow const(char)* glfwGetWin32Adapter(GLFWmonitor* monitor);
extern(C) @nogc nothrow const(char)* glfwGetWin32Monitor(GLFWmonitor* monitor);
}

version (Linux) {
// FIXME: Undefined return types: https://github.com/BindBC/bindbc-glfw/blob/6529ce4f67f69839a93de5e0bbe1150fab30d633/source/bindbc/glfw/bindstatic.d#L223
extern(C) @nogc nothrow {
void* glfwGetX11Display();
ulong glfwGetX11Window(GLFWwindow* window);
ulong glfwGetX11Adapter(GLFWmonitor* monitor);
ulong glfwGetX11Monitor(GLFWmonitor* monitor);
void glfwSetX11SelectionString(const(char)* string_);
const(char)* glfwGetX11SelectionString();
}
}

// mac OS interop with the Objective-C Runtime
Expand Down
15 changes: 10 additions & 5 deletions examples/triangle/subprojects/glfw.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@ else

.DEFAULT_GOAL := glfw/src/libglfw3.a

glfw/src/libglfw3.a:
glfw:
@echo "Downloading GLFW sources…"
@curl -L https://github.com/glfw/glfw/releases/download/$(VERSION)/glfw-$(VERSION).zip --output /tmp/glfw-$(VERSION).zip
@echo "Unzipping GLFW sources…"
@unzip -q /tmp/glfw-$(VERSION).zip
@mv glfw-3.3.6 glfw
@unzip -f -q /tmp/glfw-$(VERSION).zip
@mv --force glfw-3.3.6 glfw
glfw/src/libglfw3.a: glfw
@echo "Building GLFW…"
@cd glfw && \
cmake -B glfw glfw -DCMAKE_BUILD_TYPE=Release -DGLFW_BUILD_TESTS=OFF -DGLFW_BUILD_EXAMPLES=OFF -DGLFW_BUILD_DOCS=OFF -G"Unix Makefiles"
make
make -C glfw

clean:
rm -rf glfw
.PHONY: clean

endif
1 change: 1 addition & 0 deletions examples/utils/dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
}
},
"versions": ["GLFW_32"],
"versions-linux": ["Linux"],
"subConfigurations": {
"bindbc-glfw": "static"
},
Expand Down
45 changes: 39 additions & 6 deletions examples/utils/source/examples/window.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ import std.typecons : Tuple;
import bindbc.glfw;
import wgpu.api;

version (D_Ddoc) {
/// Whether the current target OS is supported.
enum SUPPORTED_TARGET = true;
} else {
version (OSX) enum SUPPORTED_TARGET = true;
version (Linux) enum SUPPORTED_TARGET = true;
version (Windows) enum SUPPORTED_TARGET = true;
static if (!__traits(compiles, SUPPORTED_TARGET)) enum SUPPORTED_TARGET = false;
static assert(SUPPORTED_TARGET, "Unsupported target platform");
}

/// Last observed GLFW error.
static string lastError = null;

Expand Down Expand Up @@ -60,6 +71,8 @@ abstract class Window {

///
this(string title, uint width = 640, uint height = 480, Instance gpu = null) {
import std.exception : enforce;

_gpu = gpu is null ? Instance.create() : gpu;
_title = title;

Expand All @@ -80,19 +93,19 @@ abstract class Window {

// Create GPU surface backed by this window
version (OSX) {
import std.exception : enforce;

auto nativeWindow = NSWindow.from(enforce(glfwGetCocoaWindow(_window), lastError));
auto metalLayer = CAMetalLayer.classOf.layer;
nativeWindow.contentView.wantsLayer = true;
nativeWindow.contentView.layer = metalLayer;
surface = Surface.fromMetalLayer(this.gpu, metalLayer.asId);
}
else version (Linux) surface = Surface.fromXlib(
this.gpu, assert(glfwGetX11Display()), assert(glfwGetX11Window(_window))
version (Linux) surface = Surface.fromXlib(
this.gpu, glfwGetX11Display().enforce, glfwGetX11Window(_window).enforce.to!uint
);
// TODO: Integrate with Windows platform, i.e. Surface.fromWindowsHwnd
else static assert(0, "Unsupported target platform");
version (Windows) {
import core.sys.windows.windows : GetModuleHandleA;
surface = Surface.fromWindowsHwnd(instance, GetModuleHandleA(null), glfwGetWin32Window(window));
}
assert(surface.id !is null, "Could not create native surface");

glfwSetWindowIconifyCallback(_window, ((GLFWwindow*, int iconified) nothrow {
Expand Down Expand Up @@ -225,6 +238,26 @@ auto bindDelegate(Func, string file = __FILE__, size_t line = __LINE__)(Func f)
return &func;
}

version (Windows) {
import core.sys.windows.windows : HWND;
// FIXME: Undefined return types: https://github.com/BindBC/bindbc-glfw/blob/6529ce4f67f69839a93de5e0bbe1150fab30d633/source/bindbc/glfw/bindstatic.d#L172
extern(C) @nogc nothrow HWND glfwGetWin32Window(GLFWwindow* window);
extern(C) @nogc nothrow const(char)* glfwGetWin32Adapter(GLFWmonitor* monitor);
extern(C) @nogc nothrow const(char)* glfwGetWin32Monitor(GLFWmonitor* monitor);
}

version (Linux) {
// FIXME: Undefined return types: https://github.com/BindBC/bindbc-glfw/blob/6529ce4f67f69839a93de5e0bbe1150fab30d633/source/bindbc/glfw/bindstatic.d#L223
extern(C) @nogc nothrow {
void* glfwGetX11Display();
ulong glfwGetX11Window(GLFWwindow* window);
ulong glfwGetX11Adapter(GLFWmonitor* monitor);
ulong glfwGetX11Monitor(GLFWmonitor* monitor);
void glfwSetX11SelectionString(const(char)* string_);
const(char)* glfwGetX11SelectionString();
}
}

// mac OS interop with the Objective-C Runtime
version (OSX) {
import core.attribute : selector;
Expand Down
14 changes: 6 additions & 8 deletions source/wgpu/api.d
Original file line number Diff line number Diff line change
Expand Up @@ -1762,14 +1762,12 @@ struct CommandEncoder {
string label = null
) {
assert(colorAttachments.length);
return beginRenderPass(RenderPassDescriptor(
null,
label is null ? null : label.toStringz,
colorAttachments.length.to!uint,
colorAttachments.ptr,
depthStencilAttachment,
null, // occlusion query set
));
auto descriptor = RenderPassDescriptor.init;
descriptor.label = label is null ? null : label.toStringz;
descriptor.colorAttachmentCount = colorAttachments.length.to!uint;
descriptor.colorAttachments = colorAttachments.ptr;
descriptor.depthStencilAttachment = depthStencilAttachment;
return beginRenderPass(descriptor);
}
/// Begins recording of a render pass.
///
Expand Down
1 change: 1 addition & 0 deletions source/wgpu/utils.d
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ bool valid(T)(T resource) if (isResource!T) {

unittest {
import wgpu.api : ShaderModule;
assert(!valid!SwapChain(null));
assert(!valid(ShaderModule(null)));
}

Expand Down

0 comments on commit fba65ae

Please sign in to comment.