Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error if user in no python utf8 encoding ENV to run blazor AOT #53367

Closed
newbe36524 opened this issue May 26, 2021 · 6 comments · Fixed by #53557
Closed

Error if user in no python utf8 encoding ENV to run blazor AOT #53367

newbe36524 opened this issue May 26, 2021 · 6 comments · Fixed by #53557
Assignees
Labels
arch-wasm WebAssembly architecture area-Codegen-AOT-mono
Milestone

Comments

@newbe36524
Copy link

newbe36524 commented May 26, 2021

Solution , click here #53367 (comment)

Describe the bug

User have to set default encoding of python to utf8 when run blazor AOT.

To Reproduce

Try AOT as docs mentioned in a Chinese locals PC

https://devblogs.microsoft.com/aspnet/asp-net-core-updates-in-net-6-preview-4/#blazor-webassembly-ahead-of-time-aot-compilation

error as below:

Compiling native assets with emcc. This may take a while ...
  Traceback (most recent call last):
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\emcc.py", line 3315, in <module>
      sys.exit(main(sys.argv))
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\emcc.py", line 3308, in main
      ret = run(args)
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\emcc.py", line 2156, in run
      post_link(options, wasm_target, wasm_target, target)
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\emcc.py", line 2185, in post_link
      emscripten.run(in_wasm, wasm_target, final_js, memfile)
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\emscripten.py", line 876, in run
      return temp_files.run_and_clean(lambda: emscript(
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\tools\tempfiles.py", line 104, in run_and_clean
      return func()
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\emscripten.py", line 876, in <lambda>
      return temp_files.run_and_clean(lambda: emscript(
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\emscripten.py", line 331, in emscript
      glue, forwarded_data = compile_settings(temp_files)
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\emscripten.py", line 195, in compile_settings
      out = shared.run_js_tool(path_from_root('src', 'compiler.js'),
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\tools\shared.py", line 118, in run_js_tool
      return check_call(command, *args, **kw).stdout
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\tools\shared.py", line 104, in check_call
      return run_process(cmd, *args, **kw)
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\tools\shared.py", line 94, in run_process
      ret = subprocess.run(cmd, check=check, input=input, *args, **kw)
    File "subprocess.py", line 507, in run
    File "subprocess.py", line 1121, in communicate
  UnicodeDecodeError: 'gbk' codec can't decode byte 0x94 in position 325809: illegal multibyte sequence
C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-preview.4.21253.7\Sdk\WasmApp.targets(504,5): error MSB3073: The command "emcc "@D:\Repo\newbe\Newbe.BookmarkManager\src\Newbe.BookmarkManager\obj\Release\net6.0\wasm\emcc-link.rsp"" exited with code 1. [D:\Repo\newbe\Newbe.BookmarkManager\src\Newbe.BookmarkManager\Newbe.BookmarkManager.csproj]

Set env PYTHONUTF8=1.

Everything works.

I think the root cause is the all emscripten scripts has no encoding header.

Further technical details

net6 pre4

@SIkebe
Copy link

SIkebe commented May 26, 2021

Japanese locale also has this issue. It requires @newbe36524 's workaround to publish without error.

dotnet publish -c Release
.NET 向け Microsoft (R) Build Engine バージョン 16.11.0-preview-21254-21+e73d08c28
Copyright (C) Microsoft Corporation.All rights reserved.

  復元対象のプロジェクトを決定しています...
  復元対象のすべてのプロジェクトは最新です。
  プレビュー版の .NET を使用しています。https://aka.ms/dotnet-core-preview をご覧くだ
さい
  AoTBlazor -> D:\poc\build2021\AoTBlazor\bin\Release\net6.0\AoTBlazor.dll
  AoTBlazor (Blazor output) -> D:\poc\build2021\AoTBlazor\bin\Release\net6.0\wwwroot
  アセンブリのサイズを最適化しています。これにより、アプリの動作が変更される可能性が
あります。公開した後にテストしてください。https://aka.ms/dotnet-illink を参照してくだ
さい
  AOT'ing 30 assemblies
  Compiling native assets with emcc. This may take a while ...
  Traceback (most recent call last):
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\emcc.py", line 3315, in <module>     
      sys.exit(main(sys.argv))
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\emcc.py", line 3308, in main
      ret = run(args)
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\emcc.py", line 2156, in run
      post_link(options, wasm_target, wasm_target, target)
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\emcc.py", line 2185, in post_link    
      emscripten.run(in_wasm, wasm_target, final_js, memfile)
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\emscripten.py", line 876, in run     
      return temp_files.run_and_clean(lambda: emscript(
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\tools\tempfiles.py", line 104, in run_and_clean
      return func()
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\emscripten.py", line 876, in <lambda>      return temp_files.run_and_clean(lambda: emscript(
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\emscripten.py", line 331, in emscript      glue, forwarded_data = compile_settings(temp_files)
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\emscripten.py", line 195, in compile_settings
      out = shared.run_js_tool(path_from_root('src', 'compiler.js'),
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\tools\shared.py", line 118, in run_js_tool
      return check_call(command, *args, **kw).stdout
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\tools\shared.py", line 104, in check_call
      return run_process(cmd, *args, **kw)
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\tools\shared.py", line 94, in run_process
      ret = subprocess.run(cmd, check=check, input=input, *args, **kw)
    File "subprocess.py", line 507, in run
    File "subprocess.py", line 1121, in communicate
  UnicodeDecodeError: 'cp932' codec can't decode byte 0x94 in position 325809: illegal multibyte sequence
C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-preview.4.21253.7\Sdk\WasmApp.targets(504,5): error MSB3073: コマンド "emcc "@D:\poc\build2021\AoTBlazor\obj\Release\net6.0\wasm\emcc-link.rsp"" はコ
ード 1 で終了しました。 [D:\poc\build2021\AoTBlazor\AoTBlazor.csproj]

@mkArtakMSFT mkArtakMSFT transferred this issue from dotnet/aspnetcore May 27, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label May 27, 2021
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@lewing lewing added the arch-wasm WebAssembly architecture label Jun 1, 2021
@ghost
Copy link

ghost commented Jun 1, 2021

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

Describe the bug

User have to set default encoding of python to utf8 when run blazor AOT.

To Reproduce

Try AOT as docs mentioned in a Chinese locals PC

https://devblogs.microsoft.com/aspnet/asp-net-core-updates-in-net-6-preview-4/#blazor-webassembly-ahead-of-time-aot-compilation

error as below:

Compiling native assets with emcc. This may take a while ...
  Traceback (most recent call last):
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\emcc.py", line 3315, in <module>
      sys.exit(main(sys.argv))
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\emcc.py", line 3308, in main
      ret = run(args)
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\emcc.py", line 2156, in run
      post_link(options, wasm_target, wasm_target, target)
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\emcc.py", line 2185, in post_link
      emscripten.run(in_wasm, wasm_target, final_js, memfile)
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\emscripten.py", line 876, in run
      return temp_files.run_and_clean(lambda: emscript(
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\tools\tempfiles.py", line 104, in run_and_clean
      return func()
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\emscripten.py", line 876, in <lambda>
      return temp_files.run_and_clean(lambda: emscript(
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\emscripten.py", line 331, in emscript
      glue, forwarded_data = compile_settings(temp_files)
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\emscripten.py", line 195, in compile_settings
      out = shared.run_js_tool(path_from_root('src', 'compiler.js'),
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\tools\shared.py", line 118, in run_js_tool
      return check_call(command, *args, **kw).stdout
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\tools\shared.py", line 104, in check_call
      return run_process(cmd, *args, **kw)
    File "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64\6.0.0-preview.4.21220.1\tools\emscripten\tools\shared.py", line 94, in run_process
      ret = subprocess.run(cmd, check=check, input=input, *args, **kw)
    File "subprocess.py", line 507, in run
    File "subprocess.py", line 1121, in communicate
  UnicodeDecodeError: 'gbk' codec can't decode byte 0x94 in position 325809: illegal multibyte sequence
C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-preview.4.21253.7\Sdk\WasmApp.targets(504,5): error MSB3073: The command "emcc "@D:\Repo\newbe\Newbe.BookmarkManager\src\Newbe.BookmarkManager\obj\Release\net6.0\wasm\emcc-link.rsp"" exited with code 1. [D:\Repo\newbe\Newbe.BookmarkManager\src\Newbe.BookmarkManager\Newbe.BookmarkManager.csproj]

Set env PYTHONUTF8=1.

Everything works.

I think the root cause is the all emscripten scripts has no encoding header.

Further technical details

net6 pre4

Author: newbe36524
Assignees: -
Labels:

arch-wasm, area-Codegen-AOT-mono, untriaged

Milestone: -

@lewing lewing added this to the 6.0.0 milestone Jun 1, 2021
@lewing lewing removed the untriaged New issue has not been triaged by the area owner label Jun 1, 2021
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jun 1, 2021
radical added a commit to radical/runtime that referenced this issue Jun 1, 2021
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jun 2, 2021
@qinhuaihe
Copy link

@newbe36524 Could you tell me how to Set env PYTHONUTF8=1. ? Thank you.

@radical
Copy link
Member

radical commented Jun 3, 2021

Adding this to your project file should do it:

<ItemGroup>
  <EmscriptenEnvVars Include="PYTHONUTF8=1" />
</ItemGroup>

@newbe36524
Copy link
Author

@newbe36524 Could you tell me how to Set env PYTHONUTF8=1. ? Thank you.

I make this done in 'Enviroment Variabes' dialog in my Windows PC by add a new System variable

radical added a commit to radical/emsdk that referenced this issue Jul 2, 2021
Python defaults to the system charset, and thus expects the files it's reading to
match that. But that might not always be true. Eg. system charset=gbk, failing to read
utf-8 files.

See dotnet/runtime#53367 for the motivating issue
@ghost ghost locked as resolved and limited conversation to collaborators Jul 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture area-Codegen-AOT-mono
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants