diff --git a/meson.build b/meson.build index 91154e553..6b4baff30 100644 --- a/meson.build +++ b/meson.build @@ -202,6 +202,7 @@ project_cpp_args = [] fftw_dep = dependency('fftw3f', static: is_static) threads_dep = dependency('threads') if host_platform == 'emscripten' + app_exe_jssafe = app_exe.underscorify() zlib_dep = [] png_dep = [] sdl2_dep = [] @@ -215,19 +216,20 @@ if host_platform == 'emscripten' '-s', 'EXPORTED_RUNTIME_METHODS=ccall,cwrap', '-s', 'FS_DEBUG', '-s', 'MODULARIZE', - '-s', 'EXPORT_NAME=create_' + app_exe, + '-s', 'EXPORT_NAME=create_' + app_exe_jssafe, '-Wl,-u,_emscripten_run_callback_on_thread', '-lidbfs.js', + '--source-map-base=./', ] emcc_args = [ '-s', 'USE_SDL=2', '-s', 'USE_BZIP2=1', '-s', 'USE_LIBPNG', + '-s', 'USE_PTHREADS', '-s', 'USE_ZLIB=1', '-s', 'DISABLE_EXCEPTION_CATCHING=0', + '-gsource-map', ] - project_link_args += [ '--source-map-base=./' ] - emcc_args += [ '-gsource-map' ] project_link_args += emcc_args project_cpp_args += emcc_args else @@ -542,7 +544,7 @@ if get_option('build_powder') ) subdir('android') else - executable( + powder_exe = executable( app_exe, sources: powder_files, include_directories: project_inc, @@ -623,3 +625,14 @@ if get_option('clang_tidy') ], ) endif + +if host_platform == 'emscripten' + run_target( + 'serve-locally', + command: [ + python3_prog, + serve_wasm_py, + ], + depends: powder_exe, + ) +endif diff --git a/resources/meson.build b/resources/meson.build index 7eec9548b..62c905656 100644 --- a/resources/meson.build +++ b/resources/meson.build @@ -115,6 +115,16 @@ elif host_platform == 'linux' output: 'appdata.xml', configuration: conf_data, ) +elif host_platform == 'emscripten' + servewasm_conf_data = configuration_data() + servewasm_conf_data.set('SERVER', server) + servewasm_conf_data.set('APP_EXE', app_exe) + servewasm_conf_data.set('APP_EXE_JSSAFE', app_exe_jssafe) + serve_wasm_py = configure_file( + input: 'serve-wasm.template.py', + output: 'serve-wasm.py', + configuration: servewasm_conf_data, + ) endif embedded_files += [ diff --git a/resources/serve-wasm.template.py b/resources/serve-wasm.template.py new file mode 100644 index 000000000..e1d130a9e --- /dev/null +++ b/resources/serve-wasm.template.py @@ -0,0 +1,120 @@ +from OpenSSL import crypto +import http.server +import json +import os +import re +import ssl +import sys +import time + +HTTP_HOST = '127.0.0.1' +HTTP_PORT = 8000 +HTTP_INDEX = 'serve-wasm.index.html' +KEY_FILE = 'serve-wasm.key.pem' +CERT_FILE = 'serve-wasm.cert.crt' +CERT_CN = 'serve-wasm.py self-signed certificate for @APP_EXE@.js' +CERT_TTL = 30 * 24 * 60 * 60 + +print(f'generating index for @APP_EXE@.js') +with open(HTTP_INDEX, 'wt') as f: + f.write(f''' + + +
+Remember, this is being served locally, so it will not be able to connect to @SERVER@. To enable this, serve the following files there:
+