dawn_node: Add Module.cpp

This is the node plugin entrypoint

Bug: dawn:1123
Change-Id: I4a48b047482a7c9f1a0f10cc2a5a02721d103b8a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/64940
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton 2021-09-29 09:51:21 +00:00 committed by Dawn LUCI CQ
parent cac3e7e110
commit d6ecf83c19
2 changed files with 56 additions and 0 deletions

View File

@ -57,3 +57,24 @@ endfunction()
add_subdirectory(binding)
add_subdirectory(interop)
add_library(dawn_node SHARED "Module.cpp")
set_target_properties(dawn_node PROPERTIES
PREFIX ""
OUTPUT_NAME "dawn"
SUFFIX ".node"
LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}"
)
target_link_libraries(dawn_node dawn_node_binding dawn_node_interop dawn_native dawncpp dawn_proc)
target_include_directories(dawn_node PRIVATE
${CMAKE_SOURCE_DIR}
${NODE_API_HEADERS_DIR}
${NODE_ADDON_API_DIR}
${GEN_DIR}
)
# dawn_node targets require C++17
set_property(
TARGET dawn_node
PROPERTY CXX_STANDARD 17
)

35
src/dawn_node/Module.cpp Normal file
View File

@ -0,0 +1,35 @@
// Copyright 2021 The Dawn Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "dawn/dawn_proc.h"
#include "src/dawn_node/binding/GPU.h"
// Initialize() initializes the Dawn node module, registering all the WebGPU
// types into the global object, and adding the 'gpu' property on the exported
// object.
Napi::Object Initialize(Napi::Env env, Napi::Object exports) {
// Begin by setting the Dawn procedure function pointers.
dawnProcSetProcs(&dawn_native::GetProcs());
// Register all the interop types
wgpu::interop::Initialize(env);
// Construct a wgpu::interop::GPU interface, implemented by
// wgpu::bindings::GPU. This will be the 'gpu' field of exported object.
auto gpu = wgpu::interop::GPU::Create<wgpu::binding::GPU>(env);
exports.Set(Napi::String::New(env, "gpu"), gpu);
return exports;
}
NODE_API_MODULE(addon, Initialize)