emscripten-core / emscripten-core/emscripten

em++.ps1 passes arguments differently than em++.bat

Open
#25,570 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

**Version of emscripten/emsdk:**
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.15 (09f52557f0d48b65b8c724853ed8f4e8bf80e669)
clang version 22.0.0git (https:/github.com/llvm/llvm-project 3388d40684742e950b3c5d1d2dafe5a40695cfc1)
Target: wasm32-unknown-emscripten
Thread model: posix

**Problem Description**
In previous versions of emscripten, calling em++ with a specific set of command line arguments succeeded. After we updated to 4.0.15 it suddenly failed. I traced it back to the fact that the previous versions we used had 3 versions of the file/command:

- em++
- em++.bat
- em++.py

and 4.0.15 now also has:

- em++.ps1

When our build script calls em++ it now ends up calling em++.ps1 instead of em++.bat, which somehow passes the arguments to python differently.

Minimal repro:

**hi.cpp**
```cpp
#include

int main()
{
std::cout << "hi" << std::endl;
return 0;
}
```

**build.ps1**
```powershell
$emsdk_path = "$env:LOCALAPPDATA\emsdk"

& "$emsdk_path\emsdk.ps1" construct_env

Write-Host "build using em++.bat" -fore green
& em++.bat -pthread -s ALLOW_MEMORY_GROWTH=1 hi.cpp 2>&1 | % ToString | Tee-Object -Variable build_result

Write-Host "build using em++.ps1" -fore green
& em++.ps1 -pthread -s ALLOW_MEMORY_GROWTH=1 hi.cpp 2>&1 | % ToString | Tee-Object -Variable build_result
```

With both of these files in the same folder, when I open a Powershell window and run .\build.ps1, I get the following output:

> Setting up EMSDK environment (suppress these messages with EMSDK_QUIET=1)
> Setting environment variables:
>
> build using em++.bat
> em++: warning: -pthread + ALLOW_MEMORY_GROWTH may run non-wasm code slowly, see https://github.com/WebAssembly/design/issues/1271 [-Wpthreads-mem-growth]
>
> build using em++.ps1
> python.exe : em++: warning: -pthread + ALLOW_MEMORY_GROWTH may run non-wasm code slowly, see
https://github.com/WebAssembly/design/issues/1271 [-Wpthreads-mem-growth]
> At C:\Users\yournamehere\AppData\Local\emsdk\upstream\emscripten\em++.ps1:38 char:1
> \+ & $launcher $launcherArgs $pythonScript $MyInvocation.UnboundArgument ...
> \+ \~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> \+ CategoryInfo : NotSpecified: (em++: warning: ...ads-mem-growth]:String) [], RemoteException
> \+ FullyQualifiedErrorId : NativeCommandError

The .bat command works, the .ps1 command fails. We are piping the output to a build_result variable so we can examine it later; if we remove the ``2>&1 | % ToString | Tee-Object -Variable build_result`` stuff at the end of the command both commands work fine.

We have another similar issue with emcmake.ps1 / emcmake.bat, but in that case it's because arguments that are sent using Powershell splatting are somehow passed differently than arguments that are passed directly to the command. I can create a separate issue for that.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.