From 434d73c7bdf2fd25093f27b54852b2b4170c3051 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Wed, 20 Mar 2024 22:25:24 +0100 Subject: [PATCH] Emscripten support. Doesn't work due to i64 vs i32 type mismatch in glGetIntegerv, which seems like some general compatibility bullshit, not something related to CMake. --- cmake/config.cmake | 2 +- cmake/server.cmake | 2 +- cmake/vendor.cmake | 10 +++------- profiler/CMakeLists.txt | 18 +++++++++++++++++- profiler/wasm/Makefile | 20 -------------------- profiler/wasm/build.mk | 16 ---------------- profiler/wasm/debug.mk | 7 ------- profiler/wasm/index.html | 2 +- profiler/wasm/release.mk | 7 ------- 9 files changed, 23 insertions(+), 61 deletions(-) delete mode 100644 profiler/wasm/Makefile delete mode 100644 profiler/wasm/build.mk delete mode 100644 profiler/wasm/debug.mk delete mode 100644 profiler/wasm/release.mk diff --git a/cmake/config.cmake b/cmake/config.cmake index afbca26d..e4262581 100644 --- a/cmake/config.cmake +++ b/cmake/config.cmake @@ -25,6 +25,6 @@ if(WIN32) add_definitions(-DNOMINMAX -DWIN32_LEAN_AND_MEAN) endif() -if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") +if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT EMSCRIPTEN) set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) endif() diff --git a/cmake/server.cmake b/cmake/server.cmake index 58993101..6bb0557d 100644 --- a/cmake/server.cmake +++ b/cmake/server.cmake @@ -33,7 +33,7 @@ if(NO_STATISTICS) target_compile_definitions(TracyServer PUBLIC TRACY_NO_STATISTICS) endif() -if(UNIX AND NOT APPLE) +if(UNIX AND NOT APPLE AND NOT EMSCRIPTEN) target_link_libraries(TracyServer PRIVATE TracyTbb) endif() diff --git a/cmake/vendor.cmake b/cmake/vendor.cmake index b5cd4366..51943db0 100644 --- a/cmake/vendor.cmake +++ b/cmake/vendor.cmake @@ -33,7 +33,7 @@ endif() # GLFW -if(NOT USE_WAYLAND) +if(NOT USE_WAYLAND AND NOT EMSCRIPTEN) pkg_check_modules(GLFW glfw3) if (GLFW_FOUND AND NOT DOWNLOAD_GLFW) add_library(TracyGlfw3 INTERFACE) @@ -161,13 +161,9 @@ add_library(TracyImGui STATIC ${IMGUI_SOURCES}) target_include_directories(TracyImGui PUBLIC ${IMGUI_DIR}) target_link_libraries(TracyImGui PUBLIC TracyFreetype) -if (NOT USE_WAYLAND) - target_link_libraries(TracyImGui PUBLIC TracyGlfw3) -endif() - # NFD -if (NOT NO_FILESELECTOR) +if (NOT NO_FILESELECTOR AND NOT EMSCRIPTEN) set(NFD_DIR "${ROOT_DIR}/nfd") if (WIN32) @@ -215,7 +211,7 @@ endif() # TBB -if (UNIX AND NOT APPLE) +if (UNIX AND NOT APPLE AND NOT EMSCRIPTEN) # Tracy does not use TBB directly, but the implementation of parallel algorithms # in some versions of libstdc++ depends on TBB. When it does, you must # explicitly link against -ltbb. diff --git a/profiler/CMakeLists.txt b/profiler/CMakeLists.txt index 1921c919..db468de0 100644 --- a/profiler/CMakeLists.txt +++ b/profiler/CMakeLists.txt @@ -141,4 +141,20 @@ else() add_executable(${PROJECT_NAME} ${PROFILER_FILES} ${COMMON_FILES} ${SERVER_FILES}) endif() -target_link_libraries(${PROJECT_NAME} PRIVATE TracyServer TracyImGui TracyNfd) +target_link_libraries(${PROJECT_NAME} PRIVATE TracyServer TracyImGui) + +if(NOT EMSCRIPTEN) + target_link_libraries(${PROJECT_NAME} PRIVATE TracyNfd) + if (NOT USE_WAYLAND) + target_link_libraries(${PROJECT_NAME} PRIVATE TracyGlfw3) + endif() +endif() + +if(EMSCRIPTEN) + set_property(TARGET ${PROJECT_NAME} PROPERTY COMPILE_FLAGS "-sUSE_FREETYPE=1 -pthread -DIMGUI_IMPL_OPENGL_ES2") + set_property(TARGET ${PROJECT_NAME} PROPERTY LINK_FLAGS "-sASSERTIONS=0 -sUSE_GLFW=3 -sINITIAL_MEMORY=384mb -sALLOW_MEMORY_GROWTH=1 -sMAXIMUM_MEMORY=4gb -sWASM_BIGINT=1 -sPTHREAD_POOL_SIZE=4 -sEXPORTED_FUNCTIONS=_main,_nativeResize,_nativeOpenFile -sEXPORTED_RUNTIME_METHODS=ccall -sENVIRONMENT=web,worker --preload-file embed.tracy") + + file(DOWNLOAD https://share.nereid.pl/i/embed.tracy ${CMAKE_CURRENT_BINARY_DIR}/embed.tracy EXPECTED_MD5 ca0fa4f01e7b8ca5581daa16b16c768d) + file(COPY ${CMAKE_CURRENT_LIST_DIR}/wasm/index.html DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) + file(COPY ${CMAKE_CURRENT_LIST_DIR}/wasm/httpd.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +endif() diff --git a/profiler/wasm/Makefile b/profiler/wasm/Makefile deleted file mode 100644 index fa6dfacc..00000000 --- a/profiler/wasm/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -all: release - -embed.tracy: - wget https://share.nereid.pl/i/embed.tracy - -debug: embed.tracy - @$(MAKE) -f debug.mk all TRACY_NO_ISA_EXTENSIONS=1 - -release: embed.tracy - @$(MAKE) -f release.mk all TRACY_NO_ISA_EXTENSIONS=1 - -clean: - @$(MAKE) -f build.mk clean - rm -rf Tracy-release.* - rm -rf Tracy-debug.* - -serve: - @python httpd.py - -.PHONY: all clean debug release serve diff --git a/profiler/wasm/build.mk b/profiler/wasm/build.mk deleted file mode 100644 index 8bba220e..00000000 --- a/profiler/wasm/build.mk +++ /dev/null @@ -1,16 +0,0 @@ -CC=emcc -CXX=em++ - -CFLAGS += -sUSE_FREETYPE=1 -pthread -CXXFLAGS := $(CFLAGS) -std=c++17 -DEFINES += -DIMGUI_ENABLE_FREETYPE -DIMGUI_IMPL_OPENGL_ES2 -INCLUDES := -I../../../imgui -I$(HOME)/.emscripten_cache/sysroot/include/capstone -LIBS += -lpthread -ldl $(HOME)/.emscripten_cache/sysroot/lib/libcapstone.a -sUSE_GLFW=3 -sINITIAL_MEMORY=384mb -sALLOW_MEMORY_GROWTH=1 -sMAXIMUM_MEMORY=4gb -sWASM_BIGINT=1 -sPTHREAD_POOL_SIZE=4 -sEXPORTED_FUNCTIONS=_main,_nativeResize,_nativeOpenFile -sEXPORTED_RUNTIME_METHODS=ccall -sENVIRONMENT=web,worker --preload-file embed.tracy - -PROJECT := Tracy -IMAGE := $(PROJECT)-$(BUILD).html -NO_TBB := 1 - -FILTER := ../../../nfd/nfd_win.cpp -include ../../../common/src-from-vcxproj.mk -include ../../../common/unix.mk diff --git a/profiler/wasm/debug.mk b/profiler/wasm/debug.mk deleted file mode 100644 index 9f09ba3e..00000000 --- a/profiler/wasm/debug.mk +++ /dev/null @@ -1,7 +0,0 @@ -CFLAGS := -g3 -gsource-map -Wall -DEFINES := -DDEBUG -BUILD := debug -LIBS := -sDEMANGLE_SUPPORT=1 - -include ../../../common/unix-debug.mk -include build.mk diff --git a/profiler/wasm/index.html b/profiler/wasm/index.html index 63b45685..74261e53 100644 --- a/profiler/wasm/index.html +++ b/profiler/wasm/index.html @@ -161,6 +161,6 @@ addEventListener('resize', resizeHandler); resizeHandler(); - + diff --git a/profiler/wasm/release.mk b/profiler/wasm/release.mk deleted file mode 100644 index d075f112..00000000 --- a/profiler/wasm/release.mk +++ /dev/null @@ -1,7 +0,0 @@ -CFLAGS := -Os -DEFINES := -DNDEBUG -BUILD := release -LIBS := -sASSERTIONS=0 - -include ../../../common/unix-release.mk -include build.mk