Skip to content

Commit d4159e3

Browse files
authored
wasm-shell: fix wasm build (#807)
* fix web shell Signed-off-by: Yuchen Liang <yuchenl3@andrew.cmu.edu> * remove deprecated allocateUTF8 Signed-off-by: Yuchen Liang <yuchenl3@andrew.cmu.edu> * update metadata semester/year Signed-off-by: Yuchen Liang <yuchenl3@andrew.cmu.edu> --------- Signed-off-by: Yuchen Liang <yuchenl3@andrew.cmu.edu>
1 parent 84a0823 commit d4159e3

File tree

5 files changed

+19
-17
lines changed

5 files changed

+19
-17
lines changed

build_support/build-web-shell.sh

+8-6
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,21 @@ cp bin/bustub-wasm-shell.js "deploy/${BUSTUB_SHELL_DIRECTORY}"
2828
cp bin/bustub-wasm-shell.wasm "deploy/${BUSTUB_SHELL_DIRECTORY}"
2929
cp -a ../tools/wasm-shell/extra_files/index.html "deploy/${BUSTUB_SHELL_DIRECTORY}"
3030
cp ../logo/bustub.svg "deploy/${BUSTUB_SHELL_DIRECTORY}"
31-
sed -i '' "s|\${BUSTUB_PRIVATE_VERSION}|${BUSTUB_PRIVATE_VERSION}|" "deploy/${BUSTUB_SHELL_DIRECTORY}/index.html"
32-
sed -i '' "s|\${BUSTUB_PUBLIC_VERSION}|${BUSTUB_PUBLIC_VERSION}|" "deploy/${BUSTUB_SHELL_DIRECTORY}/index.html"
33-
sed -i '' "s|\${BUSTUB_BUILD_TIME}|${BUSTUB_BUILD_TIME}|" "deploy/${BUSTUB_SHELL_DIRECTORY}/index.html"
31+
# Change `sed -i` to `sed -i ''` if you are on a Mac.
32+
sed -i "s|\${BUSTUB_PRIVATE_VERSION}|${BUSTUB_PRIVATE_VERSION}|" "deploy/${BUSTUB_SHELL_DIRECTORY}/index.html"
33+
sed -i "s|\${BUSTUB_PUBLIC_VERSION}|${BUSTUB_PUBLIC_VERSION}|" "deploy/${BUSTUB_SHELL_DIRECTORY}/index.html"
34+
sed -i "s|\${BUSTUB_BUILD_TIME}|${BUSTUB_BUILD_TIME}|" "deploy/${BUSTUB_SHELL_DIRECTORY}/index.html"
3435

3536
make -j$(nproc) wasm-bpt-printer
3637
mkdir -p "deploy/${BUSTUB_BPT_DIRECTORY}"
3738
cp bin/bustub-wasm-bpt-printer.js "deploy/${BUSTUB_BPT_DIRECTORY}"
3839
cp bin/bustub-wasm-bpt-printer.wasm "deploy/${BUSTUB_BPT_DIRECTORY}"
3940
cp -a ../tools/wasm-bpt-printer/extra_files/index.html "deploy/${BUSTUB_BPT_DIRECTORY}"
4041
cp ../logo/bustub.svg "deploy/${BUSTUB_BPT_DIRECTORY}"
41-
sed -i '' "s|\${BUSTUB_PRIVATE_VERSION}|${BUSTUB_PRIVATE_VERSION}|" "deploy/${BUSTUB_BPT_DIRECTORY}/index.html"
42-
sed -i '' "s|\${BUSTUB_PUBLIC_VERSION}|${BUSTUB_PUBLIC_VERSION}|" "deploy/${BUSTUB_BPT_DIRECTORY}/index.html"
43-
sed -i '' "s|\${BUSTUB_BUILD_TIME}|${BUSTUB_BUILD_TIME}|" "deploy/${BUSTUB_BPT_DIRECTORY}/index.html"
42+
# Change `sed -i` to `sed -i ''` if you are on a Mac.
43+
sed -i "s|\${BUSTUB_PRIVATE_VERSION}|${BUSTUB_PRIVATE_VERSION}|" "deploy/${BUSTUB_BPT_DIRECTORY}/index.html"
44+
sed -i "s|\${BUSTUB_PUBLIC_VERSION}|${BUSTUB_PUBLIC_VERSION}|" "deploy/${BUSTUB_BPT_DIRECTORY}/index.html"
45+
sed -i "s|\${BUSTUB_BUILD_TIME}|${BUSTUB_BUILD_TIME}|" "deploy/${BUSTUB_BPT_DIRECTORY}/index.html"
4446

4547
ls -alh "deploy/${BUSTUB_SHELL_DIRECTORY}"
4648
ls -alh "deploy/${BUSTUB_BPT_DIRECTORY}"

tools/wasm-bpt-printer/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ if(EMSCRIPTEN)
44
add_executable(wasm-bpt-printer ${WASM_SHELL_SOURCES})
55
target_link_libraries(wasm-bpt-printer bustub)
66
set_target_properties(wasm-bpt-printer PROPERTIES OUTPUT_NAME bustub-wasm-bpt-printer)
7-
target_link_options(wasm-bpt-printer PRIVATE -sEXPORTED_FUNCTIONS=['_BusTubInit','_BusTubApplyCommand','_free'] -sEXPORTED_RUNTIME_METHODS=['ccall','cwrap','allocateUTF8','UTF8ToString'])
7+
target_link_options(wasm-bpt-printer PRIVATE -sEXPORTED_FUNCTIONS=['_BusTubInit','_BusTubApplyCommand','_free','_malloc'] -sEXPORTED_RUNTIME_METHODS=['ccall','cwrap','stringToUTF8','UTF8ToString'])
88
endif()

tools/wasm-bpt-printer/extra_files/index.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<meta name="twitter:creator" content="@CMUDB">
3333
<meta name="twitter:domain" content=".">
3434
<meta property="twitter:label1" content="Semester?" />
35-
<meta property="twitter:data1" content="Fall 2024" />
35+
<meta property="twitter:data1" content="Spring 2025" />
3636
<meta property="twitter:label1" content="Relational?" />
3737
<meta property="twitter:data1" content="Hell Yes" />
3838

@@ -99,8 +99,8 @@
9999
const executeQuery = Module.cwrap('BusTubApplyCommand', 'number', ['string', 'number', 'number'])
100100
window.executeQuery = (x) => {
101101
const bufferSize = 64 * 1024
102-
let output = "\0".repeat(bufferSize)
103-
let ptrOutput = Module.allocateUTF8(output)
102+
const ptrOutput = Module._malloc(bufferSize)
103+
Module.stringToUTF8("", ptrOutput, bufferSize)
104104
const retCode = executeQuery(x, ptrOutput, bufferSize)
105105
output = Module.UTF8ToString(ptrOutput)
106106
Module._free(ptrOutput)
@@ -190,4 +190,4 @@
190190
gtag('config', 'UA-52525161-8');
191191
</script>
192192

193-
</html>
193+
</html>

tools/wasm-shell/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ if(EMSCRIPTEN)
44
add_executable(wasm-shell ${WASM_SHELL_SOURCES})
55
target_link_libraries(wasm-shell bustub)
66
set_target_properties(wasm-shell PROPERTIES OUTPUT_NAME bustub-wasm-shell)
7-
target_link_options(wasm-shell PRIVATE -sEXPORTED_FUNCTIONS=['_BusTubInit','_BusTubExecuteQuery','_free'] -sEXPORTED_RUNTIME_METHODS=['ccall','cwrap','allocateUTF8','UTF8ToString'])
7+
target_link_options(wasm-shell PRIVATE -sEXPORTED_FUNCTIONS=['_BusTubInit','_BusTubExecuteQuery','_free','_malloc'] -sEXPORTED_RUNTIME_METHODS=['ccall','cwrap','stringToUTF8','UTF8ToString'])
88
endif()

tools/wasm-shell/extra_files/index.html

+5-5
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@
8585
const initialize = Module.cwrap('BusTubInit', 'number', [])
8686
window.executeQuery = (x) => {
8787
const bufferSize = 64 * 1024
88-
let output = "\0".repeat(bufferSize)
89-
let ptrOutput = Module.allocateUTF8(output)
90-
let output2 = "\0".repeat(bufferSize)
91-
let ptrOutput2 = Module.allocateUTF8(output2)
88+
const ptrOutput = Module._malloc(bufferSize)
89+
Module.stringToUTF8("", ptrOutput, bufferSize)
90+
const ptrOutput2 = Module._malloc(bufferSize)
91+
Module.stringToUTF8("", ptrOutput2, bufferSize)
9292
const retCode = executeQuery(x, ptrOutput2, ptrOutput, bufferSize)
9393
output = Module.UTF8ToString(ptrOutput)
9494
output2 = Module.UTF8ToString(ptrOutput2)
@@ -159,4 +159,4 @@
159159
gtag('config', 'UA-52525161-8');
160160
</script>
161161

162-
</html>
162+
</html>

0 commit comments

Comments
 (0)