Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasm-shell: fix wasm build #807

Merged
merged 3 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions build_support/build-web-shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,21 @@ cp bin/bustub-wasm-shell.js "deploy/${BUSTUB_SHELL_DIRECTORY}"
cp bin/bustub-wasm-shell.wasm "deploy/${BUSTUB_SHELL_DIRECTORY}"
cp -a ../tools/wasm-shell/extra_files/index.html "deploy/${BUSTUB_SHELL_DIRECTORY}"
cp ../logo/bustub.svg "deploy/${BUSTUB_SHELL_DIRECTORY}"
sed -i '' "s|\${BUSTUB_PRIVATE_VERSION}|${BUSTUB_PRIVATE_VERSION}|" "deploy/${BUSTUB_SHELL_DIRECTORY}/index.html"
sed -i '' "s|\${BUSTUB_PUBLIC_VERSION}|${BUSTUB_PUBLIC_VERSION}|" "deploy/${BUSTUB_SHELL_DIRECTORY}/index.html"
sed -i '' "s|\${BUSTUB_BUILD_TIME}|${BUSTUB_BUILD_TIME}|" "deploy/${BUSTUB_SHELL_DIRECTORY}/index.html"
# Change `sed -i` to `sed -i ''` if you are on a Mac.
sed -i "s|\${BUSTUB_PRIVATE_VERSION}|${BUSTUB_PRIVATE_VERSION}|" "deploy/${BUSTUB_SHELL_DIRECTORY}/index.html"
sed -i "s|\${BUSTUB_PUBLIC_VERSION}|${BUSTUB_PUBLIC_VERSION}|" "deploy/${BUSTUB_SHELL_DIRECTORY}/index.html"
sed -i "s|\${BUSTUB_BUILD_TIME}|${BUSTUB_BUILD_TIME}|" "deploy/${BUSTUB_SHELL_DIRECTORY}/index.html"

make -j$(nproc) wasm-bpt-printer
mkdir -p "deploy/${BUSTUB_BPT_DIRECTORY}"
cp bin/bustub-wasm-bpt-printer.js "deploy/${BUSTUB_BPT_DIRECTORY}"
cp bin/bustub-wasm-bpt-printer.wasm "deploy/${BUSTUB_BPT_DIRECTORY}"
cp -a ../tools/wasm-bpt-printer/extra_files/index.html "deploy/${BUSTUB_BPT_DIRECTORY}"
cp ../logo/bustub.svg "deploy/${BUSTUB_BPT_DIRECTORY}"
sed -i '' "s|\${BUSTUB_PRIVATE_VERSION}|${BUSTUB_PRIVATE_VERSION}|" "deploy/${BUSTUB_BPT_DIRECTORY}/index.html"
sed -i '' "s|\${BUSTUB_PUBLIC_VERSION}|${BUSTUB_PUBLIC_VERSION}|" "deploy/${BUSTUB_BPT_DIRECTORY}/index.html"
sed -i '' "s|\${BUSTUB_BUILD_TIME}|${BUSTUB_BUILD_TIME}|" "deploy/${BUSTUB_BPT_DIRECTORY}/index.html"
# Change `sed -i` to `sed -i ''` if you are on a Mac.
sed -i "s|\${BUSTUB_PRIVATE_VERSION}|${BUSTUB_PRIVATE_VERSION}|" "deploy/${BUSTUB_BPT_DIRECTORY}/index.html"
sed -i "s|\${BUSTUB_PUBLIC_VERSION}|${BUSTUB_PUBLIC_VERSION}|" "deploy/${BUSTUB_BPT_DIRECTORY}/index.html"
sed -i "s|\${BUSTUB_BUILD_TIME}|${BUSTUB_BUILD_TIME}|" "deploy/${BUSTUB_BPT_DIRECTORY}/index.html"

ls -alh "deploy/${BUSTUB_SHELL_DIRECTORY}"
ls -alh "deploy/${BUSTUB_BPT_DIRECTORY}"
2 changes: 1 addition & 1 deletion tools/wasm-bpt-printer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ if(EMSCRIPTEN)
add_executable(wasm-bpt-printer ${WASM_SHELL_SOURCES})
target_link_libraries(wasm-bpt-printer bustub)
set_target_properties(wasm-bpt-printer PROPERTIES OUTPUT_NAME bustub-wasm-bpt-printer)
target_link_options(wasm-bpt-printer PRIVATE -sEXPORTED_FUNCTIONS=['_BusTubInit','_BusTubApplyCommand','_free'] -sEXPORTED_RUNTIME_METHODS=['ccall','cwrap','allocateUTF8','UTF8ToString'])
target_link_options(wasm-bpt-printer PRIVATE -sEXPORTED_FUNCTIONS=['_BusTubInit','_BusTubApplyCommand','_free','_malloc'] -sEXPORTED_RUNTIME_METHODS=['ccall','cwrap','stringToUTF8','UTF8ToString'])
endif()
8 changes: 4 additions & 4 deletions tools/wasm-bpt-printer/extra_files/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<meta name="twitter:creator" content="@CMUDB">
<meta name="twitter:domain" content=".">
<meta property="twitter:label1" content="Semester?" />
<meta property="twitter:data1" content="Fall 2024" />
<meta property="twitter:data1" content="Spring 2025" />
<meta property="twitter:label1" content="Relational?" />
<meta property="twitter:data1" content="Hell Yes" />

Expand Down Expand Up @@ -99,8 +99,8 @@
const executeQuery = Module.cwrap('BusTubApplyCommand', 'number', ['string', 'number', 'number'])
window.executeQuery = (x) => {
const bufferSize = 64 * 1024
let output = "\0".repeat(bufferSize)
let ptrOutput = Module.allocateUTF8(output)
const ptrOutput = Module._malloc(bufferSize)
Module.stringToUTF8("", ptrOutput, bufferSize)
const retCode = executeQuery(x, ptrOutput, bufferSize)
output = Module.UTF8ToString(ptrOutput)
Module._free(ptrOutput)
Expand Down Expand Up @@ -190,4 +190,4 @@
gtag('config', 'UA-52525161-8');
</script>

</html>
</html>
2 changes: 1 addition & 1 deletion tools/wasm-shell/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ if(EMSCRIPTEN)
add_executable(wasm-shell ${WASM_SHELL_SOURCES})
target_link_libraries(wasm-shell bustub)
set_target_properties(wasm-shell PROPERTIES OUTPUT_NAME bustub-wasm-shell)
target_link_options(wasm-shell PRIVATE -sEXPORTED_FUNCTIONS=['_BusTubInit','_BusTubExecuteQuery','_free'] -sEXPORTED_RUNTIME_METHODS=['ccall','cwrap','allocateUTF8','UTF8ToString'])
target_link_options(wasm-shell PRIVATE -sEXPORTED_FUNCTIONS=['_BusTubInit','_BusTubExecuteQuery','_free','_malloc'] -sEXPORTED_RUNTIME_METHODS=['ccall','cwrap','stringToUTF8','UTF8ToString'])
endif()
10 changes: 5 additions & 5 deletions tools/wasm-shell/extra_files/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@
const initialize = Module.cwrap('BusTubInit', 'number', [])
window.executeQuery = (x) => {
const bufferSize = 64 * 1024
let output = "\0".repeat(bufferSize)
let ptrOutput = Module.allocateUTF8(output)
let output2 = "\0".repeat(bufferSize)
let ptrOutput2 = Module.allocateUTF8(output2)
const ptrOutput = Module._malloc(bufferSize)
Module.stringToUTF8("", ptrOutput, bufferSize)
const ptrOutput2 = Module._malloc(bufferSize)
Module.stringToUTF8("", ptrOutput2, bufferSize)
const retCode = executeQuery(x, ptrOutput2, ptrOutput, bufferSize)
output = Module.UTF8ToString(ptrOutput)
output2 = Module.UTF8ToString(ptrOutput2)
Expand Down Expand Up @@ -159,4 +159,4 @@
gtag('config', 'UA-52525161-8');
</script>

</html>
</html>
Loading