Skip to content

Commit

Permalink
Extract the playground in its own HTML file (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
vhiairrassary authored Dec 16, 2024
1 parent 547bbf1 commit bd381c1
Show file tree
Hide file tree
Showing 5 changed files with 846 additions and 16 deletions.
21 changes: 18 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,24 @@ set(EXTENSION_NAME ${TARGET_NAME}_extension)
set(LOADABLE_EXTENSION_NAME ${TARGET_NAME}_loadable_extension)

project(${TARGET_NAME})
include_directories(src/include duckdb/third_party/httplib duckdb/parquet/include)

set(EXTENSION_SOURCES src/httpserver_extension.cpp)
include_directories(
src/include
${CMAKE_CURRENT_BINARY_DIR}
duckdb/third_party/httplib
duckdb/parquet/include
)

# Embed ./src/assets/index.html as a C++ header
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/playground.hpp
COMMAND ${CMAKE_COMMAND} -P ${PROJECT_SOURCE_DIR}/embed.cmake ${PROJECT_SOURCE_DIR}/src/assets/index.html ${CMAKE_CURRENT_BINARY_DIR}/playground.hpp playgroundContent
DEPENDS ${PROJECT_SOURCE_DIR}/src/assets/index.html
)

set(EXTENSION_SOURCES
src/httpserver_extension.cpp
${CMAKE_CURRENT_BINARY_DIR}/playground.hpp
)

if(MINGW)
set(OPENSSL_USE_STATIC_LIBS TRUE)
Expand Down
18 changes: 18 additions & 0 deletions embed.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
set(resource_file_name ${CMAKE_ARGV3})
set(output_file_name ${CMAKE_ARGV4})
set(variable_name ${CMAKE_ARGV5})

file(READ "${resource_file_name}" hex_content HEX)

string(REPEAT "[0-9a-f]" 32 pattern)
string(REGEX REPLACE "(${pattern})" "\\1\n" content "${hex_content}")

string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1, " content "${content}")

string(REGEX REPLACE ", $" "" content "${content}")

set(array_definition "static const unsigned char ${variable_name}[] =\n{\n${content}\n};")

set(output "// Auto generated file.\n${array_definition}\n")

file(WRITE "${output_file_name}" "${output}")
Loading

0 comments on commit bd381c1

Please sign in to comment.