Skip to content

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

@jrxpana

Description

@jrxpana

Version of emscripten/emsdk:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.15 (09f5255)
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

#include <iostream>

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

build.ps1

$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 WebAssembly/design#1271 [-Wpthreads-mem-growth]

build using em++.ps1
python.exe : em++: warning: -pthread + ALLOW_MEMORY_GROWTH may run non-wasm code slowly, see
WebAssembly/design#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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions