Skip to content

[WIP] Replace wasi-browser.sh to mirror wasi.sh with wasm-browser flag#24973

Closed
Copilot wants to merge 1 commit intomasterfrom
copilot/replace-wasi-browser-script
Closed

[WIP] Replace wasi-browser.sh to mirror wasi.sh with wasm-browser flag#24973
Copilot wants to merge 1 commit intomasterfrom
copilot/replace-wasi-browser-script

Conversation

Copy link
Contributor

Copilot AI commented Dec 2, 2025

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.

Original prompt

Problem

The linux-wasi and linux-wasi-browser CI jobs should behave identically except linux-wasi-browser must pass the --with-wasm-browser configure flag. Currently, sys/wasi-browser.sh diverges from sys/wasi.sh and the linux-wasi-browser job fails at configure with errors like "checking for c compiler... no" and "clang --target=wasm32-wasi -Os cannot create executables". Because configure fails, generated files (config-user.mk, .wasm) are missing and subsequent make/cp steps fail.

Goal

Create a pull request that replaces sys/wasi-browser.sh so it mirrors sys/wasi.sh exactly except for adding the --with-wasm-browser configure flag. The new script must ensure the WASI SDK is installed and on PATH, run a small sanity compile to verify the toolchain can produce a wasm executable, exit early with clear diagnostics when downloads/configure/toolchain checks fail, and then run make and package the wasm-browser artifacts into radare2--wasm-browser.zip.

Changes to make (detailed and actionable)

  1. Replace file sys/wasi-browser.sh with the content below. It must:

    • source sys/wasi-env.sh
    • download/extract wasi-sdk and wasi-sysroot when missing
    • copy dist/plugins-cfg/plugins.wasi.cfg to plugins.cfg
    • export PATH with "$WASI_SDK/bin"
    • perform a quick clang --target=wasm32-wasi test compile to detect toolchain problems early
    • run ./configure with the same flags as sys/wasi.sh plus --with-wasm-browser
    • run make only if configure succeeded
    • copy built .wasm files into radare2--wasm-browser directory and zip it
  2. Ensure script exits non-zero with a clear message when any critical step fails (download/configure/sanity compile/make).

New file content for sys/wasi-browser.sh (exact content to write):

#!/bin/sh

. dirname $0/wasi-env.sh

echo "WASI_SDK=$WASI_SDK"

TOOLS="rax2 radiff2 rahash2 radare2 rasm2 rabin2 rafind2"

Install WASI SDK and sysroot if not present

if [ ! -d "$WASI_SDK" ]; then
OS=uname
case "$OS" in
linux|Linux) OS=linux ;;
darwin|Darwin) OS=macos ;;
windows|Windows) OS=mingw ;;
esac
mkdir -p ~/Downloads/wasi
rm -f ~/Downloads/wasi/wasi-sdk.tar.gz
wget -c -O ~/Downloads/wasi/wasi-sdk.tar.gz https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_MAJOR}/wasi-sdk-${WASI_VERSION}-$OS.tar.gz || { echo "Failed to download wasi-sdk"; exit 1; }
rm -f ~/Downloads/wasi/wasi-root.tar.gz
wget -c -O ~/Downloads/wasi/wasi-root.tar.gz https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_MAJOR}/wasi-sysroot-${WASI_VERSION}.tar.gz || { echo "Failed to download wasi-sysroot"; exit 1; }
(
cd ~/Downloads/wasi
tar xzvf wasi-sdk.tar.gz
tar xzvf wasi-root.tar.gz
mv wasi-sysroot wasi-sysroot-${WASI_VERSION}
)
fi

Use same plugins config as wasi

cp -f dist/plugins-cfg/plugins.wasi.cfg plugins.cfg

Ensure WASI_SDK/bin is on PATH for clang/wasm-ld

export PATH="$WASI_SDK/bin:$PATH"

ERR=0

Quick sanity test: ensure clang and wasm-ld are present and can create a minimal wasm

if ! command -v clang >/dev/null 2>&1 ; then
echo "clang not found in PATH ($PATH)"; exit 1
fi
if ! command -v wasm-ld >/dev/null 2>&1 ; then
echo "Warning: wasm-ld not found in PATH. Linking may fail."
fi

Create and compile a tiny test program to check the toolchain can produce wasm

cat > /tmp/r2_wasi_test.c <<'EOF'
int main(void) { return 0; }
EOF
clang --target=wasm32-wasi -Os /tmp/r2_wasi_test.c -o /tmp/r2_wasi_test.wasm >/tmp/r2_wasi_test.log 2>&1 || { echo "WASI clang cannot create executables. See /tmp/r2_wasi_test.log"; sed -n '1,200p' /tmp/r2_wasi_test.log || true; exit 1; }

Configure: same flags as wasi but adding --with-wasm-browser

./configure --with-static-themes --without-gperf --with-compiler=wasi --disable-debugger
--without-fork --with-ostype=wasi --with-checks-level=0 --disable-threads
--without-dylink --with-libr --with-wasm-browser || { echo "configure failed"; exit 1; }

Run make only if configure succeeded

make -j || { echo "make failed"; exit 1; }

R2V=./configure -qV
D="radare2-$R2V-wasm-browser"
mkdir -p $D
for a in ${TOOLS} ; do
make -C binr/$a
cp -f binr/$a/$a.wasm $D || ERR=1
done

zip -r "$D".zip $D
exit $ERR

Testing & Validation

  • After the PR is created, CI will run and the linux-wasi-browser job should now mirror linux-wasi but with the --with-wasm-browser flag. The script includes explicit diagnostics (logs and messages) to help debug toolchain issues if any remain.

Please open a pull request that replaces sys/wasi-browser.sh with the content above and run CI to verify linux-wasi-browser passes.

This pull request was created as a result of the following prompt from Copilot chat.

Problem

The linux-wasi and linux-wasi-browser CI jobs should behave identically except linux-wasi-browser must pass the --with-wasm-browser configure flag. Currently, sys/wasi-browser.sh diverges from sys/wasi.sh and the linux-wasi-browser job fails at configure with errors like "checking for c compiler... no" and "clang --target=wasm32-wasi -Os cannot create executables". Because configure fails, generated files (config-user.mk, .wasm) are missing and subsequent make/cp steps fail.

Goal

Create a pull request that replaces sys/wasi-browser.sh so it mirrors sys/wasi.sh exactly except for adding the --with-wasm-browser configure flag. The new script must ensure the WASI SDK is installed and on PATH, run a small sanity compile to verify the toolchain can produce a wasm executable, exit early with clear diagnostics when downloads/configure/toolchain checks fail, and then run make and package the wasm-browser artifacts into radare2--wasm-browser.zip.

Changes to make (detailed and actionable)

  1. Replace file sys/wasi-browser.sh with the content below. It must:

    • source sys/wasi-env.sh
    • download/extract wasi-sdk and wasi-sysroot when missing
    • copy dist/plugins-cfg/plugins.wasi.cfg to plugins.cfg
    • export PATH with "$WASI_SDK/bin"
    • perform a quick clang --target=wasm32-wasi test compile to detect toolchain problems early
    • run ./configure with the same flags as sys/wasi.sh plus --with-wasm-browser
    • run make only if configure succeeded
    • copy built .wasm files into radare2--wasm-browser directory and zip it
  2. Ensure script exits non-zero with a clear message when any critical step fails (download/configure/sanity compile/make).

New file content for sys/wasi-browser.sh (exact content to write):

#!/bin/sh

. dirname $0/wasi-env.sh

echo "WASI_SDK=$WASI_SDK"

TOOLS="rax2 radiff2 rahash2 radare2 rasm2 rabin2 rafind2"

Install WASI SDK and sysroot if not present

if [ ! -d "$WASI_SDK" ]; then
OS=uname
case "$OS" in
linux|Linux) OS=linux ;;
darwin|Darwin) OS=macos ;;
windows|Windows) OS=mingw ;;
esac
mkdir -p ~/Downloads/wasi
rm -f ~/Downloads/wasi/wasi-sdk.tar.gz
wget -c -O ~/Downloads/wasi/wasi-sdk.tar.gz https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_MAJOR}/wasi-sdk-${WASI_VERSION}-$OS.tar.gz || { echo "Failed to download wasi-sdk"; exit 1; }
rm -f ~/Downloads/wasi/wasi-root.tar.gz
wget -c -O ~/Downloads/wasi/wasi-root.tar.gz https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_MAJOR}/wasi-sysroot-${WASI_VERSION}.tar.gz || { echo "Failed to download wasi-sysroot"; exit 1; }
(
cd ~/Downloads/wasi
tar xzvf wasi-sdk.tar.gz
tar xzvf wasi-root.tar.gz
mv wasi-sysroot wasi-sysroot-${WASI_VERSION}
)
fi

Use same plugins config as wasi

cp -f dist/plugins-cfg/plugins.wasi.cfg plugins.cfg

Ensure WASI_SDK/bin is on PATH for clang/wasm-ld

export PATH="$WASI_SDK/bin:$PATH"

ERR=0

Quick sanity test: ensure clang and wasm-ld are present and can create a minimal wasm

if ! command -v clang >/dev/null 2>&1 ; then
echo "clang not found in PATH ($PATH)"; exit 1
fi
if ! command -v wasm-ld >/dev/null 2>&1 ; then
echo "Warning: wasm-ld not found in PATH. Linking may fail."
fi

Create and compile a tiny test program to check the toolchain can produce wasm

cat > /tmp/r2_wasi_test.c <<'EOF'
int main(void) { return 0; }
EOF
clang --target=wasm32-wasi -Os /tmp/r2_wasi_test.c -o /tmp/r2_wasi_test.wasm >/tmp/r2_wasi_test.log 2>&1 || { echo "WASI clang cannot create executables. See /tmp/r2_wasi_test.log"; sed -n '1,200p' /tmp/r2_wasi_test.log || true; exit 1; }

Configure: same flags as wasi but adding --with-wasm-browser

./configure --with-static-themes --without-gperf --with-compiler=wasi --disable-debugger
--without-fork --with-ostype=wasi --with-checks-level=0 --disable-threads
--without-dylink --with-libr --with-wasm-browser || { echo "configure failed"; exit 1; }

Run make only if configure succeeded

make -j || { echo "make failed"; exit 1; }

R2V=./configure -qV
D="radare2-$R2V-wasm-browser"
mkdir -p $D
for a in ${TOOLS} ; do
make -C binr/$a
cp -f binr/$a/$a.wasm $D || ERR=1
done

zip -r "$D".zip $D
exit $ERR

Testing & Validation

  • After the PR is created, CI will run and the linux-wasi-browser job should now mirror linux-wasi but with the --with-wasm-browser flag. The script includes explicit diagnostics (logs and messages) to help debug toolchain issues if any remain.

Please open a pull request that replaces sys/wasi-browser.sh with the content above and run CI to verify linux-wasi-browser passes.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants