Fixed debug builds

This commit is contained in:
Warwick 2025-04-16 16:49:16 +01:00
parent 990e4871ad
commit dfccf4d01b
3 changed files with 25 additions and 13 deletions

1
.gitignore vendored
View file

@ -4,3 +4,4 @@ CMakeFiles/
Makefile Makefile
cmake_install.cmake cmake_install.cmake
compile_commands.json compile_commands.json
webgpu

View file

@ -9,24 +9,13 @@ project(webgpu
set(CMAKE_C_STANDARD 17) set(CMAKE_C_STANDARD 17)
# Since nix include dirs isn't appearing in compile_commands.json we're gonna # 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 "") set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
if(CMAKE_EXPORT_COMPILE_COMMANDS) if(CMAKE_EXPORT_COMPILE_COMMANDS)
set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES
${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}) ${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES})
endif() 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 # Use environment set by nix-shell to find wgpu include and library
find_path(WGPU_INCLUDE webgpu) find_path(WGPU_INCLUDE webgpu)
find_library(WGPU_LIBRARY libwgpu_native.so) find_library(WGPU_LIBRARY libwgpu_native.so)
@ -45,6 +34,17 @@ file(GLOB_RECURSE HEADER_FILES
${CMAKE_SOURCE_DIR}/src/*.h) ${CMAKE_SOURCE_DIR}/src/*.h)
add_executable(${PROJECT_NAME} ${HEADER_FILES} ${SOURCE_FILES}) 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 target_include_directories(${PROJECT_NAME} PRIVATE
${WGPU_INCLUDE} ${WGPU_INCLUDE}
${SDL3_INCLUDE_DIRS} ${SDL3_INCLUDE_DIRS}

View file

@ -8,6 +8,17 @@ int main() {
// We create the instance using this descriptor // We create the instance using this descriptor
WGPUInstance instance = wgpuCreateInstance(&desc); 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; return 0;
} }