sungaila / PDFtoImage

A .NET library to render PDF files into images.
https://www.sungaila.de/PDFtoImage/
MIT License
176 stars 19 forks source link

Unable to build Blazor project with .NET 8 #56

Closed nor0x closed 8 months ago

nor0x commented 9 months ago

PDFtoImage version

3.0.0

OS

Windows

OS version

Windows 11

Architecture

x64

Framework

.NET (Core)

App framework

Blazor

Detailed bug report

I cloned the repository and tried to run the WebConverter project on .net8 instead of .net7. I'm unable to get the build working and get the following errors in the build output

2>EXEC : warning : To disable errors for undefined symbols use `-sERROR_ON_UNDEFINED_SYMBOLS=0`
2>EXEC : warning : _emscripten_longjmp may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
2>EXEC : error : undefined symbol: emscripten_longjmp (referenced by top-level compiled C/C++ code)
2>EXEC : error : Aborting compilation due to previous errors
2>emcc : error : '"C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.3.1.34.Node.win-x64\8.0.0\tools\bin\node.exe" "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.3.1.34.Sdk.win-x64\8.0.0\tools\emscripten\src\compiler.js" C:\Users\dev\AppData\Local\Temp\tmpyv8t97kd.json' failed (returned 1)
2>C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\8.0.0\Sdk\WasmApp.Native.targets(513,5): error MSB3073: The command "emcc "@C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\8.0.0\runtimes\browser-wasm\native\src\emcc-default.rsp" -msimd128 "@C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\8.0.0\runtimes\browser-wasm\native\src\emcc-link.rsp" "@C:\dev\PDFtoImage-master\src\WebConverter\obj\Debug\net8.0\wasm\for-build\emcc-link.rsp"" exited with code 1.
2>    5 Warning(s)
2>    4 Error(s)

Has anyone tried running PDFtoImage on Blazor WASM in .NET8?

sungaila commented 9 months ago

Hi @nor0x, this is a known issue and the reason I didn't upgrade the WebConverter project to .NET 8.

This has been fixed in emscripten (https://github.com/emscripten-core/emscripten/pull/19004) but .NET 8 uses an older release.

So either we have to wait for .NET 9 that uses a newer emscripten version or hope that freetype (pdfium depends on it) fixes it on their side.

Edit: To be more precise: .NET 8 is locked to emscripten 3.1.34 but this workaround/bugfix was included in 3.1.35. Very unfortunate.

sungaila commented 9 months ago

Oops, I didn't mean to close this. This will be fixed once either of those things happen.

nor0x commented 9 months ago

thank you for your reply and the explanation - it's very unfortunate that .NET 8 is stuck exactly one version below the one which includes the fix.

I did some research about the issue and was able to get my app building by adding these two properties in my Blazor csproj file

    <WasmEnableSIMD>false</WasmEnableSIMD>
    <WasmEnableExceptionHandling>false</WasmEnableExceptionHandling>

SIMD support and WASM Exception handling got added in NET 8 and by disabling those features I was able to build and run successfully for now.

I will also try it now with the WebConverter sample from this repo

sungaila commented 9 months ago

Thanks a lot for this tip! Setting <WasmEnableExceptionHandling>false</WasmEnableExceptionHandling> fixes the issue and I could upgrade to .NET 8 now.

However, this project has a dependency to SkiaSharp and I cannot turn off wasm exceptions for this one. I guess SkiaSharp was compiled with -fwasm-exceptions.

Fortunately staying on emsdk 3.1.12 for SkiaSharp (compiled for .NET 7) seems to work. Even though the version mismatch between 3.1.12 and 3.1.34 causes the compiler warning wasm-ld : warning : function signature mismatch: time.

nor0x commented 9 months ago

i was able to keep SIMD enabled with a change in the NativeFileReference based on the subfolders in the package

<NativeFileReference Include="$(SkiaSharpStaticLibraryPath)\3.1.12\simd\libSkiaSharp.a" />

image

sungaila commented 8 months ago

PDFtoImage 3.1.0 released with support for Blazor WebAssembly. When targeting .NET 7 (or newer) the matching pdfium.a will be included.

There is a catch, however. I could not include libSkiaSharp.a automatically, so the consuming project must add this itself:

<NativeFileReference Include="$(SkiaSharpStaticLibraryPath)\3.1.12\simd\libSkiaSharp.a" />

Many thanks for your help, @nor0x! :-)