Skip to content

Fix Windows-only cmd /c calls in build_web.ps1 to support Linux#2

Draft
sriail with Copilot wants to merge 2 commits into
copilot/copy-mcpe-assets-to-web-buildfrom
copilot/fix-emcc-cmd-invocation
Draft

Fix Windows-only cmd /c calls in build_web.ps1 to support Linux#2
sriail with Copilot wants to merge 2 commits into
copilot/copy-mcpe-assets-to-web-buildfrom
copilot/fix-emcc-cmd-invocation

Conversation

Copilot AI commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

build_web.ps1 used cmd /c to invoke the compiler and linker, which fails on Linux where cmd.exe doesn't exist. The script also hardcoded a Windows backslash path separator in Join-Path.

Changes

  • Cross-platform Join-Path — replaced "upstream\emscripten\emcc.py" string with multi-argument Join-Path $env:EMSDK "upstream" "emscripten" "emcc.py" so PowerShell resolves the separator per OS

  • Compile step — replaced cmd /c "... > tmpOut 2>&1" with Start-Process -FilePath $env:EMSDK_PYTHON -ArgumentList @("-E", $emccPy, "@$rspFull") -RedirectStandardOutput ... -RedirectStandardError ... -PassThru; exit code checked via $proc.ExitCode instead of $LASTEXITCODE

  • Link step — replaced cmd /c "emcc @$linkRsp" with & emcc "@$linkRsp"; $LASTEXITCODE is set correctly by PowerShell for external executable invocations

# Before
$emccPy = Join-Path $env:EMSDK "upstream\emscripten\emcc.py"
cmd /c "`"$env:EMSDK_PYTHON`" -E `"$emccPy`" @`"$rspFull`" > `"$tmpOut`" 2>&1"
# ...
cmd /c "emcc @$linkRsp"

# After
$emccPy = Join-Path $env:EMSDK "upstream" "emscripten" "emcc.py"
$proc = Start-Process -FilePath $env:EMSDK_PYTHON -ArgumentList @("-E", $emccPy, "@$rspFull") `
    -NoNewWindow -Wait -RedirectStandardOutput $tmpOut -RedirectStandardError $tmpErr -PassThru
# ...
& emcc "@$linkRsp"
Original prompt

Problem

The file web-build/project/emscripten/build_web.ps1 uses cmd /c (Windows Command Prompt) to invoke emcc on lines 91 and 113. This fails on Linux because cmd doesn't exist there. The user is running on Linux (/home/admin1/MCPE-WASM/...) with PowerShell Core installed.

The errors look like:

cmd: /home/admin1/MCPE-WASM/web-build/project/emscripten/build_web.ps1:91
Line |
  91 |          cmd /c "`"$env:EMSDK_PYTHON`" -E `"$emccPy`" @`"$rspFull`" >  …
     |          ~~~
     | The term 'cmd' is not recognized as a name of a cmdlet, function, script
     | file, or executable program.

And similarly on line 113:

Line |
 113 |  cmd /c "emcc @$linkRsp"
     |  ~~~
     | The term 'cmd' is not recognized as a name of a cmdlet, function, script
     | file, or executable program.

Required Fix

Replace the Windows-specific cmd /c invocations with cross-platform PowerShell equivalents that work on both Windows and Linux:

Line 88 — Fix the emsdk path separator

# Change from Windows backslash:
$emccPy = Join-Path $env:EMSDK "upstream\emscripten\emcc.py"
# To cross-platform:
$emccPy = Join-Path $env:EMSDK "upstream" "emscripten" "emcc.py"

Lines 89-96 — Replace the compile cmd /c block

The current code:

$tmpOut = [System.IO.Path]::GetTempFileName()
$rspFull = (Resolve-Path $rspFile).Path
cmd /c "`"$env:EMSDK_PYTHON`" -E `"$emccPy`" @`"$rspFull`" > `"$tmpOut`" 2>&1"
$output = Get-Content $tmpOut -Raw
Remove-Item $tmpOut -Force -ErrorAction SilentlyContinue
if ($LASTEXITCODE -ne 0) {
    $errors += @{ "file" = $srcFile; "output" = $output }
}

Should be replaced with a cross-platform approach using Start-Process or direct invocation with & $env:EMSDK_PYTHON -E $emccPy @args and redirecting output, or simply using & emcc directly since emsdk_env.ps1 should put emcc on the PATH. A good approach:

$rspFull = (Resolve-Path $rspFile).Path
$tmpOut = [System.IO.Path]::GetTempFileName()
$procArgs = @("-E", $emccPy, "@$rspFull")
$proc = Start-Process -FilePath $env:EMSDK_PYTHON -ArgumentList $procArgs -NoNewWindow -Wait -RedirectStandardOutput $tmpOut -RedirectStandardError "$tmpOut.err" -PassThru
$output = ""
if (Test-Path $tmpOut) { $output += Get-Content $tmpOut -Raw -ErrorAction SilentlyContinue }
if (Test-Path "$tmpOut.err") { $output += Get-Content "$tmpOut.err" -Raw -ErrorAction SilentlyContinue }
Remove-Item $tmpOut, "$tmpOut.err" -Force -ErrorAction SilentlyContinue
if ($proc.ExitCode -ne 0) {
    $errors += @{ "file" = $srcFile; "output" = $output }
}

Line 113 — Replace the link cmd /c

The current code:

cmd /c "emcc @$linkRsp"

Should become:

& emcc "@$linkRsp"

Or if emcc is not directly on PATH, use the Python approach:

$emccPy = Join-Path $env:EMSDK "upstream" "emscripten" "emcc.py"
& $env:EMSDK_PYTHON -E $emccPy "@$linkRsp"

Important Notes

  • The fix must work on BOTH Windows and Linux (cross-platform PowerShell).
  • Join-Path with multiple arguments is cross-platform and handles path separators automatically.
  • Do NOT break the existing response-file (@file) argument passing to emcc.
  • The $ErrorActionPreference = "Continue" at the top of the file should remain.
  • Test that $LASTEXITCODE is still properly captured after the changes.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: how do i test this branch and test deploy it on localhost?

Assistant:

Let me look at the repository structure and the PR to understand how this project is set up.

Assistant: Here's a complete guide to testing this PR branch locally and serving it on localhost:


Step 1: Clone the repo and check out the PR branch

git clone https://github.com/sriail/MCPE-WASM.git
cd MCPE-WASM
git checkout copilot/copy-mcpe-assets-to-web-build

Or if you already have the repo cloned:

git fetch origin
git checkout copilot/copy-mcpe-assets-to-web-build

Step 2: Prerequisites

You'll need these installed on your system:

  • Git — to clone emsdk
  • Python 3 — used by the Emscripten SDK
  • PowerShell — the build scripts are all .ps1 (works on Windows natively; on macOS/Linux install PowerShell Core)

Step 3: Install the Emscripten SDK

From the web-build/ directory, run:

cd web-build
.\install_deps.ps1

This will:

  1. Clone the Emscripten SDK into a sibling emsdk/ folder (next to web-build/)
  2. Install and activate the latest Emscripten toolchain

Note: The first install takes several minutes as it downloads the LLVM/Clang toolchain.


Step 4: Build the WASM project

Still from web-build/, run:

.\build.ps1

This invokes `web-build/project/emscripten/build_w...

This pull request was created from Copilot chat.


💡 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.

Co-authored-by: sriail <225764385+sriail@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Windows cmd invocation to cross-platform PowerShell for emcc Fix Windows-only cmd /c calls in build_web.ps1 to support Linux Mar 9, 2026
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