dawn_node: Begin working on the CMake rules

This is enough to compile the interop code. This doesn't do anything as we need to emit the NodeJS module entry point, and actually hook up the interop to the Dawn bindings.
This comes next.

Bug: dawn:1123
Change-Id: I754b4bcb0532c8446031622d8e8e64e2faaff585
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/64903
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Ben Clayton 2021-09-28 11:14:42 +00:00 committed by Dawn LUCI CQ
parent 897cdeeb61
commit affb7a3ab9
3 changed files with 160 additions and 0 deletions

View File

@ -115,6 +115,9 @@ option_if_not_defined(DAWN_ALWAYS_ASSERT "Enable assertions on all build types"
option_if_not_defined(DAWN_USE_X11 "Enable support for X11 surface" ${USE_X11})
option_if_not_defined(DAWN_BUILD_EXAMPLES "Enables building Dawn's exmaples" ${BUILD_EXAMPLE})
option_if_not_defined(DAWN_BUILD_NODE_BINDINGS "Enables building Dawn's NodeJS bindings" OFF)
option_if_not_defined(DAWN_ENABLE_PIC "Build with Position-Independent-Code enabled" OFF)
set_if_not_defined(DAWN_THIRD_PARTY_DIR "${Dawn_SOURCE_DIR}/third_party" "Directory in which to find third-party dependencies.")
@ -130,6 +133,11 @@ set_if_not_defined(DAWN_SPIRV_HEADERS_DIR "${DAWN_THIRD_PARTY_DIR}/vulkan-deps/s
set_if_not_defined(DAWN_SPIRV_TOOLS_DIR "${DAWN_THIRD_PARTY_DIR}/vulkan-deps/spirv-tools/src" "Directory in which to find SPIRV-Tools")
set_if_not_defined(DAWN_TINT_DIR "${DAWN_THIRD_PARTY_DIR}/tint" "Directory in which to find Tint")
# Dependencies for DAWN_BUILD_NODE_BINDINGS
set_if_not_defined(NODE_ADDON_API_DIR "${DAWN_THIRD_PARTY_DIR}/node-addon-api" "Directory in which to find node-addon-api")
set_if_not_defined(NODE_API_HEADERS_DIR "${DAWN_THIRD_PARTY_DIR}/node-api-headers/include" "Directory in which to find node-api-headers")
set_if_not_defined(WEBGPU_IDL_PATH "${DAWN_THIRD_PARTY_DIR}/gpuweb/webgpu.idl" "Path to the webgpu.idl definition file")
# Much of the backend code is shared among desktop OpenGL and OpenGL ES
if (${DAWN_ENABLE_DESKTOP_GL} OR ${DAWN_ENABLE_OPENGLES})
set(DAWN_ENABLE_OPENGL ON)
@ -141,6 +149,10 @@ if (DAWN_ENABLE_OPENGL)
set(DAWN_REQUIRES_SPIRV_CROSS ON)
endif()
if(DAWN_ENABLE_PIC)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
################################################################################
# Dawn's public and internal "configs"
################################################################################
@ -213,3 +225,25 @@ if (DAWN_BUILD_EXAMPLES)
#add_subdirectory(src/utils)
add_subdirectory(examples)
endif()
if (DAWN_BUILD_NODE_BINDINGS)
set(NODE_BINDING_DEPS
${NODE_ADDON_API_DIR}
${NODE_API_HEADERS_DIR}
${WEBGPU_IDL_PATH}
)
foreach(DEP ${NODE_BINDING_DEPS})
if (NOT EXISTS ${DEP})
message(FATAL_ERROR
"DAWN_BUILD_NODE_BINDINGS requires missing dependency '${DEP}'\n"
"Try running:\n"
"gclient sync --gclientfile=scripts/standalone-with-node.gclient"
)
endif()
endforeach()
if (NOT CMAKE_POSITION_INDEPENDENT_CODE)
message(FATAL_ERROR "DAWN_BUILD_NODE_BINDINGS requires building with DAWN_ENABLE_PIC")
endif()
add_subdirectory(src/dawn_node)
endif()

View File

@ -0,0 +1,58 @@
# 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.
set(GEN_DIR "${CMAKE_CURRENT_BINARY_DIR}/gen")
set(IDLGEN_TOOL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tools/cmd/idlgen")
# idlgen() is a function that uses the tools/cmd/idlgen/main.go tool to generate
# code from an IDL file and template.
# idlgen() accepts the following named arguments:
# TEMPLATE <path> - (required) the path to the root .tmpl file. If the
# template imports other templates, then these should be
# added to the DEPENDS argument list.
# OUTPUT <path> - (required) the output file path.
# IDLS <paths> - (at least one required) the list of input WebIDL files.
# DEPENDS <paths> - an optional list of additional file dependencies used.
function(idlgen)
cmake_parse_arguments(IDLGEN
"" # options
"TEMPLATE;OUTPUT" # one_value_keywords
"IDLS;DEPENDS" # multi_value_keywords
${ARGN})
if(NOT IDLGEN_TEMPLATE)
message(FATAL_ERROR "idlgen() missing TEMPLATE argument")
endif()
if(NOT IDLGEN_OUTPUT)
message(FATAL_ERROR "idlgen() missing OUTPUT argument")
endif()
if(NOT IDLGEN_IDLS)
message(FATAL_ERROR "idlgen() missing IDLS argument(s)")
endif()
add_custom_command(
COMMAND "go" "run" "main.go"
"--template" "${IDLGEN_TEMPLATE}"
"--output" "${IDLGEN_OUTPUT}"
${IDLGEN_IDLS}
DEPENDS "${IDLGEN_TOOL_DIR}/main.go"
${IDLGEN_TEMPLATE}
${IDLGEN_DEPENDS}
${IDLGEN_IDLS}
OUTPUT ${IDLGEN_OUTPUT}
WORKING_DIRECTORY ${IDLGEN_TOOL_DIR}
COMMENT "Generating ${IDLGEN_OUTPUT}"
)
endfunction()
add_subdirectory(interop)

View File

@ -0,0 +1,68 @@
# 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.
# Paths to generated files
set(INTEROP_GEN_DIR "${GEN_DIR}/src/dawn_node/interop")
set(INTEROP_WEBGPU_H "${INTEROP_GEN_DIR}/WebGPU.h")
set(INTEROP_WEBGPU_CPP "${INTEROP_GEN_DIR}/WebGPU.cpp")
idlgen(
TEMPLATE
"${CMAKE_CURRENT_SOURCE_DIR}/WebGPU.h.tmpl"
IDLS
"${CMAKE_CURRENT_SOURCE_DIR}/Browser.idl"
"${WEBGPU_IDL_PATH}"
DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/WebGPUCommon.tmpl"
OUTPUT
"${INTEROP_WEBGPU_H}"
)
idlgen(
TEMPLATE
"${CMAKE_CURRENT_SOURCE_DIR}/WebGPU.cpp.tmpl"
IDLS
"${CMAKE_CURRENT_SOURCE_DIR}/Browser.idl"
"${WEBGPU_IDL_PATH}"
DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/WebGPUCommon.tmpl"
OUTPUT
"${INTEROP_WEBGPU_CPP}"
)
add_library(dawn_node_interop STATIC
"Core.cpp"
"Core.h"
"${INTEROP_WEBGPU_H}"
"${INTEROP_WEBGPU_CPP}"
)
target_include_directories(dawn_node_interop
PRIVATE
${CMAKE_SOURCE_DIR}
${NODE_API_HEADERS_DIR}
${NODE_ADDON_API_DIR}
${GEN_DIR}
)
target_link_libraries(dawn_node_interop
PRIVATE
dawncpp
)
# dawn_node targets require C++17
set_property(
TARGET dawn_node_interop
PROPERTY CXX_STANDARD 17
)