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

C++20 Modules Support #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions dawn/webgpu.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#define WEBGPU_CPP_MODULE
#include "webgpu.hpp"
21 changes: 18 additions & 3 deletions dawn/webgpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@

#pragma once

#ifdef WEBGPU_CPP_MODULE
#define EXPORT export
#else
#define EXPORT
#endif

#ifdef WEBGPU_CPP_MODULE
module;
#endif

#include <webgpu/webgpu.h>

#include <iostream>
Expand All @@ -46,10 +56,14 @@
#include <emscripten.h>
#endif

#ifdef WEBGPU_CPP_MODULE
export module webgpu;
#endif

/**
* A namespace providing a more C++ idiomatic API to WebGPU.
*/
namespace wgpu {
EXPORT namespace wgpu {

struct DefaultFlag {};
constexpr DefaultFlag Default;
Expand Down Expand Up @@ -1919,7 +1933,7 @@ END

Instance createInstance(const InstanceDescriptor& descriptor);

#ifdef WEBGPU_CPP_IMPLEMENTATION
#if defined(WEBGPU_CPP_IMPLEMENTATION) || defined(WEBGPU_CPP_MODULE)

Instance createInstance(const InstanceDescriptor& descriptor) {
return wgpuCreateInstance(&descriptor);
Expand Down Expand Up @@ -4078,12 +4092,13 @@ Device Adapter::requestDevice(const DeviceDescriptor& descriptor) {
return device;
}

#endif // WEBGPU_CPP_IMPLEMENTATION
#endif // defined(WEBGPU_CPP_IMPLEMENTATION) || defined(WEBGPU_CPP_MODULE)

#undef HANDLE
#undef DESCRIPTOR
#undef ENUM
#undef ENUM_ENTRY
#undef END
#undef EXPORT

} // namespace wgpu
21 changes: 18 additions & 3 deletions dawn/webgpu.template.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@

#pragma once

#ifdef WEBGPU_CPP_MODULE
#define EXPORT export
#else
#define EXPORT
#endif

#ifdef WEBGPU_CPP_MODULE
module;
#endif

#include <webgpu/webgpu.h>

#include <iostream>
Expand All @@ -46,10 +56,14 @@
#include <emscripten.h>
#endif

#ifdef WEBGPU_CPP_MODULE
export module webgpu;
#endif

/**
* A namespace providing a more C++ idiomatic API to WebGPU.
*/
namespace wgpu {
EXPORT namespace wgpu {

struct DefaultFlag {};
constexpr DefaultFlag Default;
Expand Down Expand Up @@ -167,7 +181,7 @@ wgpuDevicePopErrorScope

Instance createInstance(const InstanceDescriptor& descriptor);

#ifdef WEBGPU_CPP_IMPLEMENTATION
#if defined(WEBGPU_CPP_IMPLEMENTATION) || defined(WEBGPU_CPP_MODULE)

Instance createInstance(const InstanceDescriptor& descriptor) {
return wgpuCreateInstance(&descriptor);
Expand Down Expand Up @@ -227,12 +241,13 @@ Device Adapter::requestDevice(const DeviceDescriptor& descriptor) {
return device;
}

#endif // WEBGPU_CPP_IMPLEMENTATION
#endif // defined(WEBGPU_CPP_IMPLEMENTATION) || defined(WEBGPU_CPP_MODULE)

#undef HANDLE
#undef DESCRIPTOR
#undef ENUM
#undef ENUM_ENTRY
#undef END
#undef EXPORT

} // namespace wgpu
2 changes: 2 additions & 0 deletions emscripten/webgpu.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#define WEBGPU_CPP_MODULE
#include "webgpu.hpp"
2 changes: 2 additions & 0 deletions wgpu-native/webgpu.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#define WEBGPU_CPP_MODULE
#include "webgpu.hpp"
21 changes: 18 additions & 3 deletions wgpu-native/webgpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@

#pragma once

#ifdef WEBGPU_CPP_MODULE
#define EXPORT export
#else
#define EXPORT
#endif

#ifdef WEBGPU_CPP_MODULE
module;
#endif

#include <webgpu/webgpu.h>
#include <webgpu/wgpu.h>

Expand All @@ -47,10 +57,14 @@
#include <emscripten.h>
#endif

#ifdef WEBGPU_CPP_MODULE
export module webgpu;
#endif

/**
* A namespace providing a more C++ idiomatic API to WebGPU.
*/
namespace wgpu {
EXPORT namespace wgpu {

struct DefaultFlag {};
constexpr DefaultFlag Default;
Expand Down Expand Up @@ -1398,7 +1412,7 @@ END

Instance createInstance(const InstanceDescriptor& descriptor);

#ifdef WEBGPU_CPP_IMPLEMENTATION
#if defined(WEBGPU_CPP_IMPLEMENTATION) || defined(WEBGPU_CPP_MODULE)

Instance createInstance(const InstanceDescriptor& descriptor) {
return wgpuCreateInstance(&descriptor);
Expand Down Expand Up @@ -2826,12 +2840,13 @@ Device Adapter::requestDevice(const DeviceDescriptor& descriptor) {
return device;
}

#endif // WEBGPU_CPP_IMPLEMENTATION
#endif // defined(WEBGPU_CPP_IMPLEMENTATION) || defined(WEBGPU_CPP_MODULE)

#undef HANDLE
#undef DESCRIPTOR
#undef ENUM
#undef ENUM_ENTRY
#undef END
#undef EXPORT

} // namespace wgpu
21 changes: 18 additions & 3 deletions wgpu-native/webgpu.template.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@

#pragma once

#ifdef WEBGPU_CPP_MODULE
#define EXPORT export
#else
#define EXPORT
#endif

#ifdef WEBGPU_CPP_MODULE
module;
#endif

#include <webgpu/webgpu.h>
#include <webgpu/wgpu.h>

Expand All @@ -47,10 +57,14 @@
#include <emscripten.h>
#endif

#ifdef WEBGPU_CPP_MODULE
export module webgpu;
#endif

/**
* A namespace providing a more C++ idiomatic API to WebGPU.
*/
namespace wgpu {
EXPORT namespace wgpu {

struct DefaultFlag {};
constexpr DefaultFlag Default;
Expand Down Expand Up @@ -167,7 +181,7 @@ END

Instance createInstance(const InstanceDescriptor& descriptor);

#ifdef WEBGPU_CPP_IMPLEMENTATION
#if defined(WEBGPU_CPP_IMPLEMENTATION) || defined(WEBGPU_CPP_MODULE)

Instance createInstance(const InstanceDescriptor& descriptor) {
return wgpuCreateInstance(&descriptor);
Expand Down Expand Up @@ -227,12 +241,13 @@ Device Adapter::requestDevice(const DeviceDescriptor& descriptor) {
return device;
}

#endif // WEBGPU_CPP_IMPLEMENTATION
#endif // defined(WEBGPU_CPP_IMPLEMENTATION) || defined(WEBGPU_CPP_MODULE)

#undef HANDLE
#undef DESCRIPTOR
#undef ENUM
#undef ENUM_ENTRY
#undef END
#undef EXPORT

} // namespace wgpu