Skip to content

Commit

Permalink
refactor: Clean up WASM glue code
Browse files Browse the repository at this point in the history
  • Loading branch information
slavek-kucera authored Jul 25, 2024
1 parent 642ec23 commit bc04cd9
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 87 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ if(BUILD_TESTING)
include(external_gtest)
endif()

include(emscripten_node_runner)

# Libraries (+ their includes)
add_subdirectory(parser_library)

Expand Down
1 change: 0 additions & 1 deletion benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ project(benchmark)
add_executable(benchmark
benchmark.cpp
diagnostic_counter.h)
generate_emscripten_node_runner(benchmark)

target_include_directories(benchmark
PRIVATE
Expand Down
35 changes: 0 additions & 35 deletions clients/vscode-hlasmplugin/build/bin/bundle.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion clients/vscode-hlasmplugin/src/serverFactory.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string[]>('arguments', [])) });

return new vscodelc.LanguageClient(EXTENSION_ID, 'HLASM extension Language Server', clientOptions, worker);
Expand Down
25 changes: 0 additions & 25 deletions cmake/emscripten_node_runner.cmake

This file was deleted.

14 changes: 0 additions & 14 deletions cmake/emscripten_node_runner_generator.cmake

This file was deleted.

2 changes: 0 additions & 2 deletions cmake/node_runner.js.template

This file was deleted.

39 changes: 39 additions & 0 deletions cmake/wasm_post.js
Original file line number Diff line number Diff line change
@@ -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();
}
1 change: 0 additions & 1 deletion language_server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 0 additions & 1 deletion language_server/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion parser_library/fuzzer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 0 additions & 1 deletion parser_library/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/config.wasm.sh
Original file line number Diff line number Diff line change
@@ -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 ../
2 changes: 1 addition & 1 deletion scripts/test-runner.wasm.sh
Original file line number Diff line number Diff line change
@@ -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})"
1 change: 0 additions & 1 deletion utils/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bc04cd9

Please sign in to comment.