From dfccf4d01b71aafa8c9c576f932cd1b3afb09f89 Mon Sep 17 00:00:00 2001 From: Warwick Date: Wed, 16 Apr 2025 16:49:16 +0100 Subject: [PATCH] Fixed debug builds --- .gitignore | 1 + CMakeLists.txt | 24 ++++++++++++------------ src/main.c | 13 ++++++++++++- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index f64ceba..43255e9 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ CMakeFiles/ Makefile cmake_install.cmake compile_commands.json +webgpu diff --git a/CMakeLists.txt b/CMakeLists.txt index 1064c4b..13705f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,24 +9,13 @@ project(webgpu set(CMAKE_C_STANDARD 17) # Since nix include dirs isn't appearing in compile_commands.json we're gonna -# force cmake to link it's includes explicitly +# force cmake to link it's includes more explicitly set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "") if(CMAKE_EXPORT_COMPILE_COMMANDS) set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}) endif() -# Error on memory address issues in debug mode -if(CMAKE_BUILD_TYPE MATCHES "Debug") - set( - CMAKE_C_FLAGS - "${CMAKE_C_FLAGS} -Werror -fsanitize=undefined -fsanitize=address" - ) - target_link_options(${PROJECT_NAME} - BEFORE PUBLIC -fsanitize=undefined PUBLIC -fsanitize=address - ) -endif() - # Use environment set by nix-shell to find wgpu include and library find_path(WGPU_INCLUDE webgpu) find_library(WGPU_LIBRARY libwgpu_native.so) @@ -45,6 +34,17 @@ file(GLOB_RECURSE HEADER_FILES ${CMAKE_SOURCE_DIR}/src/*.h) add_executable(${PROJECT_NAME} ${HEADER_FILES} ${SOURCE_FILES}) +# Error on memory address issues in debug mode +if(CMAKE_BUILD_TYPE MATCHES "Debug") + set( + CMAKE_C_FLAGS + "${CMAKE_C_FLAGS} -Werror -fsanitize=undefined -fsanitize=address" + ) + target_link_options(${PROJECT_NAME} + BEFORE PUBLIC -fsanitize=undefined PUBLIC -fsanitize=address + ) +endif() + target_include_directories(${PROJECT_NAME} PRIVATE ${WGPU_INCLUDE} ${SDL3_INCLUDE_DIRS} diff --git a/src/main.c b/src/main.c index 5fc3cc7..bcffe66 100644 --- a/src/main.c +++ b/src/main.c @@ -8,6 +8,17 @@ int main() { // We create the instance using this descriptor WGPUInstance instance = wgpuCreateInstance(&desc); - printf("Hello World!\n"); + // + // We can check whether there is actually an instance created + if (!instance) { + printf("Could not initialize WebGPU!\n"); + return 1; + } + + // Display the object (WGPUInstance is a simple pointer, it may be + // copied around without worrying about its size). + printf("WGPU instance: %p\n", instance); + + wgpuInstanceRelease(instance); return 0; }