diff --git a/CMakeLists.txt b/CMakeLists.txt index 6cd7b5efe..6457b6b27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,8 +112,6 @@ if(BUILD_TESTING) include(external_gtest) endif() -include(emscripten_node_runner) - # Libraries (+ their includes) add_subdirectory(parser_library) diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index bb3d78146..cf63ac846 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -15,7 +15,6 @@ project(benchmark) add_executable(benchmark benchmark.cpp diagnostic_counter.h) -generate_emscripten_node_runner(benchmark) target_include_directories(benchmark PRIVATE diff --git a/clients/vscode-hlasmplugin/build/bin/bundle.mjs b/clients/vscode-hlasmplugin/build/bin/bundle.mjs index e470a2c56..c5db6d1a7 100644 --- a/clients/vscode-hlasmplugin/build/bin/bundle.mjs +++ b/clients/vscode-hlasmplugin/build/bin/bundle.mjs @@ -76,41 +76,6 @@ for (const bd of buildDetails) { }); } -if (target === 1) { - const main = fs.readFileSync('bin/wasm/hlasm_language_server.mjs', { encoding: 'utf8' }); - const worker = ` -if (!isPthread) { - const tmpQueue = []; - self.onmessage = (event) => { - self.onmessage = (event) => { tmpQueue.push(event); }; - - const { extensionUri, arguments } = event.data; - - return Module({ - tmpQueue, - worker: self, - arguments, - locateFile(path) { - if (typeof path !== 'string') return path; - if (path.endsWith(".wasm")) { - return extensionUri + 'bin/wasm/hlasm_language_server.wasm'; - } - return path; - }, - }); - } -} -`; - const superRunner = main - .replaceAll('import.meta.url', 'self.location.href') - .replace('"type":"module",', '') - .replace('export default Module', '// export default Module') - .replace('if (isNode)', '// if (isNode)') - .concat(worker); - - fs.writeFileSync('bin/wasm/hlasm_language_server_web.js', superRunner); -} - console.log('Done!'); // details follow diff --git a/clients/vscode-hlasmplugin/src/serverFactory.web.ts b/clients/vscode-hlasmplugin/src/serverFactory.web.ts index 35374eb22..5ad0012c7 100644 --- a/clients/vscode-hlasmplugin/src/serverFactory.web.ts +++ b/clients/vscode-hlasmplugin/src/serverFactory.web.ts @@ -23,7 +23,7 @@ export async function createLanguageServer(_serverVariant: ServerVariant, client if (!extensionUri.endsWith('/')) extensionUri += '/'; - const worker = new Worker(extensionUri + 'bin/wasm/hlasm_language_server_web.js'); + const worker = new Worker(extensionUri + 'bin/wasm/hlasm_language_server.js'); worker.postMessage({ INIT: "INIT", extensionUri, arguments: decorateArgs(getConfig('arguments', [])) }); return new vscodelc.LanguageClient(EXTENSION_ID, 'HLASM extension Language Server', clientOptions, worker); diff --git a/cmake/emscripten_node_runner.cmake b/cmake/emscripten_node_runner.cmake deleted file mode 100644 index 4d268bd4e..000000000 --- a/cmake/emscripten_node_runner.cmake +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright (c) 2023 Broadcom. -# The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. -# -# This program and the accompanying materials are made -# available under the terms of the Eclipse Public License 2.0 -# which is available at https://www.eclipse.org/legal/epl-2.0/ -# -# SPDX-License-Identifier: EPL-2.0 -# -# Contributors: -# Broadcom, Inc. - initial API and implementation - -function(generate_emscripten_node_runner target) - if (NOT EMSCRIPTEN) - return() - endif() - if (NOT ${CMAKE_EXECUTABLE_SUFFIX_CXX} STREQUAL ".mjs") - return() - endif() - add_custom_command( - TARGET ${target} - POST_BUILD - COMMAND ${CMAKE_COMMAND} -D "OUTPUT_FILE=$/$$.js" -D "INPUT_FILE=$" -P "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/emscripten_node_runner_generator.cmake" - ) -endfunction() diff --git a/cmake/emscripten_node_runner_generator.cmake b/cmake/emscripten_node_runner_generator.cmake deleted file mode 100644 index 988ee516b..000000000 --- a/cmake/emscripten_node_runner_generator.cmake +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2023 Broadcom. -# The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. -# -# This program and the accompanying materials are made -# available under the terms of the Eclipse Public License 2.0 -# which is available at https://www.eclipse.org/legal/epl-2.0/ -# -# SPDX-License-Identifier: EPL-2.0 -# -# Contributors: -# Broadcom, Inc. - initial API and implementation - -message(STATUS "Generating Node runner for ${INPUT_FILE} into ${OUTPUT_FILE}...") -configure_file("${CMAKE_CURRENT_LIST_DIR}/node_runner.js.template" ${OUTPUT_FILE}) diff --git a/cmake/node_runner.js.template b/cmake/node_runner.js.template deleted file mode 100755 index 00dd080b1..000000000 --- a/cmake/node_runner.js.template +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env node -import(require('url').pathToFileURL(require('path').join(__dirname, '${INPUT_FILE}'))).then(m => m.default({ arguments: process.argv.slice(2) })); diff --git a/cmake/wasm_post.js b/cmake/wasm_post.js new file mode 100644 index 000000000..e3eb5eec5 --- /dev/null +++ b/cmake/wasm_post.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 Broadcom. + * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Broadcom, Inc. - initial API and implementation + */ + +if (typeof importScripts == "function") { + const tmpQueue = []; + self.onmessage = (event) => { + self.onmessage = (event) => { tmpQueue.push(event); }; + + const { extensionUri, arguments } = event.data; + + Module({ + tmpQueue, + worker: self, + arguments, + mainScriptUrlOrBlob: self.location.href, + locateFile(path) { + if (typeof path !== 'string') return path; + if (path.endsWith(".wasm")) { + return extensionUri + 'bin/wasm/hlasm_language_server.wasm'; + } + return path; + }, + }); + } +} +else if (require.main === module) { + Module(); +} diff --git a/language_server/CMakeLists.txt b/language_server/CMakeLists.txt index 67e38a9de..86b7a258c 100644 --- a/language_server/CMakeLists.txt +++ b/language_server/CMakeLists.txt @@ -20,7 +20,6 @@ add_library(hlasm_language_server_base OBJECT) target_include_directories(hlasm_language_server_base PRIVATE src) add_executable(hlasm_language_server) -generate_emscripten_node_runner(hlasm_language_server) add_subdirectory(src) diff --git a/language_server/test/CMakeLists.txt b/language_server/test/CMakeLists.txt index faf172e20..1f5e07fa4 100644 --- a/language_server/test/CMakeLists.txt +++ b/language_server/test/CMakeLists.txt @@ -11,7 +11,6 @@ # Broadcom, Inc. - initial API and implementation add_executable(server_test) -generate_emscripten_node_runner(server_test) target_sources(server_test PRIVATE blocking_queue_test.cpp diff --git a/parser_library/fuzzer/CMakeLists.txt b/parser_library/fuzzer/CMakeLists.txt index df92239ba..3102f646d 100644 --- a/parser_library/fuzzer/CMakeLists.txt +++ b/parser_library/fuzzer/CMakeLists.txt @@ -16,7 +16,6 @@ Project(fuzzer) if(BUILD_FUZZER) add_executable(library_fuzzer) set_target_properties(library_fuzzer PROPERTIES LINK_FLAGS "-fsanitize=fuzzer") - generate_emscripten_node_runner(library_fuzzer) else() add_library(library_fuzzer STATIC) endif() diff --git a/parser_library/test/CMakeLists.txt b/parser_library/test/CMakeLists.txt index d056d1535..e6e79a9dc 100644 --- a/parser_library/test/CMakeLists.txt +++ b/parser_library/test/CMakeLists.txt @@ -11,7 +11,6 @@ # Broadcom, Inc. - initial API and implementation add_executable(library_test) -generate_emscripten_node_runner(library_test) target_sources(library_test PRIVATE aread_time_test.cpp diff --git a/scripts/config.wasm.sh b/scripts/config.wasm.sh index 7ec1388a9..869e0ed95 100755 --- a/scripts/config.wasm.sh +++ b/scripts/config.wasm.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash set -e -emcmake cmake -G Ninja -DCMAKE_VERIFY_HEADER_SETS=On -DCMAKE_BUILD_TYPE=Release -DDISCOVER_TESTS=Off -DWITH_LIBCXX=Off -DWITH_STATIC_CRT=Off -DCMAKE_CXX_FLAGS="-s USE_PTHREADS=1 -fwasm-exceptions" -DUSE_PRE_GENERATED_GRAMMAR="generated_parser" -DCMAKE_EXE_LINKER_FLAGS="-s PTHREAD_POOL_SIZE=8 -s MAXIMUM_MEMORY=2147418112 -s INITIAL_MEMORY=268435456 -s ALLOW_MEMORY_GROWTH=1 -s PROXY_TO_PTHREAD=1 -s EXPORT_ES6=1 -s EXIT_RUNTIME=1 --bind -s STACK_SIZE=4MB -fwasm-exceptions" -DCMAKE_CROSSCOMPILING_EMULATOR="node;--experimental-wasm-eh" -DCMAKE_EXECUTABLE_SUFFIX_CXX=.mjs -Dgtest_disable_pthreads=On -DBUILD_VSIX=Off ../ +emcmake cmake -G Ninja -DCMAKE_VERIFY_HEADER_SETS=On -DCMAKE_BUILD_TYPE=Release -DDISCOVER_TESTS=Off -DWITH_LIBCXX=Off -DWITH_STATIC_CRT=Off -DCMAKE_CXX_FLAGS="-s USE_PTHREADS=1 -fwasm-exceptions" -DUSE_PRE_GENERATED_GRAMMAR="generated_parser" -DCMAKE_EXE_LINKER_FLAGS="-s PTHREAD_POOL_SIZE=8 -s MAXIMUM_MEMORY=2147418112 -s INITIAL_MEMORY=268435456 -s ALLOW_MEMORY_GROWTH=1 -s PROXY_TO_PTHREAD=1 -s MODULARIZE=1 -s EXIT_RUNTIME=1 --bind -s STACK_SIZE=4MB -fwasm-exceptions --extern-post-js `pwd`/../cmake/wasm_post.js" -DCMAKE_CROSSCOMPILING_EMULATOR="node;--experimental-wasm-eh" -Dgtest_disable_pthreads=On -DBUILD_VSIX=Off ../ diff --git a/scripts/test-runner.wasm.sh b/scripts/test-runner.wasm.sh index 654fccfc5..407184e84 100755 --- a/scripts/test-runner.wasm.sh +++ b/scripts/test-runner.wasm.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash set -e node --experimental-wasm-eh $1.js -node --experimental-wasm-eh --eval "import('$1.mjs').then(m=>{m.default({web:true})})" +node --experimental-wasm-eh --eval "require('$1.js')({web:true})" diff --git a/utils/test/CMakeLists.txt b/utils/test/CMakeLists.txt index e17a678d8..12eb551a1 100644 --- a/utils/test/CMakeLists.txt +++ b/utils/test/CMakeLists.txt @@ -11,7 +11,6 @@ # Broadcom, Inc. - initial API and implementation add_executable(hlasm_utils_test) -generate_emscripten_node_runner(hlasm_utils_test) target_sources(hlasm_utils_test PRIVATE bk_tree_test.cpp