dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.96k stars 4.65k forks source link

wasi project with long path results in error clang linking on Windows #106845

Closed jsturtevant closed 1 week ago

jsturtevant commented 3 weeks ago

Description

When creating a wasi mono project following https://github.com/dotnet/runtime/tree/main/src/mono/wasi#prototype-wasi-support in preview 7 if the path the project is installed on is long then it fails to build with error:

dotnet build .\MonoApp.csproj
Restore complete (0.7s)
You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy
  MonoApp failed with 5 error(s) (87.8s) → bin\Debug\net9.0\wasi-wasm\MonoApp.dll
    wasm-ld : error : unknown argument: --wasm-ld-path
    wasm-ld : error : cannot open C:\\Users\\jstur\\.wasi-sdk\\wasi-sdk-24.0\\bin\\wasm-ld: no such file or directory
    EXEC : error : failed to invoke LLD: exit code: 1
    clang : error : linker command failed with exit code 1 (use -v to see invocation)
    C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk\9.0.0-preview.7.24405.7\Sdk\WasiApp.targets(372,5): error MSB3073: The command ""C:/Users/jstur/.wasi-sdk/wasi-sdk-24.0/bin/clang.exe" "@C:\Users\jstur\projects\component\test\really\log\file\path\mess\up\clang\MonoApp\obj\Debug\net9.0\wasi-wasm\wasm\for-build\clang-link.rsp"" exited with code 1.

Build failed with 5 error(s) in 89.3s

Reproduction Steps

mkdir projects\component\test\really\log\file\path\mess\up\clang\

use project file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net9.0</TargetFramework>
    <RuntimeIdentifier>wasi-wasm</RuntimeIdentifier>
    <OutputType>Exe</OutputType>
    <PublishTrimmed>true</PublishTrimmed>
    <WasmSingleFileBundle>true</WasmSingleFileBundle>
    <WasmBuildNative>true</WasmBuildNative>
    <WASI_SDK_PATH>C:\Users\jstur\.wasi-sdk\wasi-sdk-24.0</WASI_SDK_PATH>
  </PropertyGroup>
</Project>
dotnet build

Expected behavior

project to build

Actual behavior

fails to build.

Regression?

no I don't think so

Known Workarounds

move to shorter path

Configuration

.NET v9.0.100-preview.7.24407.12

Other information

this might be an issue with wasi-sdk or clang project, but I couldn't reproduce it with a simple c program and build script

Found when adding dotnet mono support to https://github.com/bytecodealliance/componentize-dotnet and adding the project file to the ~\projects\componentize-dotnet\test\WasmComponentSdkTest\testapps\MonoApp folder

ilonatommy commented 3 weeks ago

Thank you for the report. I can reproduce the problem.

 cannot open C:\\repos\\wasi-sdk\\bin\\wasm-ld: no such file or directory

The longest path in the response file has < 260 chars and is invariant of project's location - it seems it is not directly connected with long path issues, e.g. browser on AOT https://github.com/dotnet/runtime/issues/103625.

C:/Program Files/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.wasi-wasm/9.0.0-preview.7.24405.7/runtimes/wasi-wasm/native/libmono-component-diagnostics_tracing-stub-static.a

From some reason when I specify the linker (originally we run with -Wl option that tells Clang to pass an argument to the linker, which is wasm-ld, i.e. LLD targeting WASM), by changing from

<Exec Command="&quot;$(WasiClang)&quot; &quot;@$(_WasmLinkRsp)&quot;" />

to

<Exec Command="&quot;$(WasiClang)&quot; -fuse-ld=$(WASI_SDK_PATH)\bin\wasm-ld.exe &quot;@$(_WasmLinkRsp)&quot;" />

it starts working. Is it possible that clang does not know that linker for windows should have .exe extension? @radekdoulik As a fix I will add conditional execution depending on the OS, unless you have a better suggestion.

ilonatommy commented 3 weeks ago

Checking the short path scenario I am not that sure the proposed fix makes sense - project in short path location does not have the problem with linker extension. Differences between long and short path scenario: C:\Users\Public\projects\tests1\really\log\file\path\mess\up\clang\MonoApp 74 chars - NOT OK

End of search list.
 "C:\\repos\\wasi-sdk\\bin\\wasm-component-ld" "@C:\\Users\\USER~1\\AppData\\Local\\Temp\\response-ebfeef.txt"
 Arguments passed via response file:
"-m" "wasm32" "--wasm-ld-path" "C:\\repos\\wasi-sdk\\bin\\wasm-ld" "-LC:/repos/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasip2"

C:\Users\Public\projects\tests\really\log\file\path\mess\up\clang\MonoApp 73 chars - OK

End of search list.
 "C:\\repos\\wasi-sdk\\bin\\wasm-component-ld" -m wasm32 --wasm-ld-path "C:\\repos\\wasi-sdk\\bin\\wasm-ld"  -LC:/repos/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasip2
ilonatommy commented 2 weeks ago

To make sure it's Windows only problem I checked Linux and it's not failing in /workspaces/long-path-test-for-the-windows-issue-to-see-if-linux-also-has-problems/another-directory-just-to-make-sure/MonoApp (126 chars). To check how if it's a regression I checked wasi-sdk 23 . It is not getting to the linking step, it's failing on compilation step:

  Failed to compile C:\Users\user\source\repos\runtime-fork\.dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.wasi-wasm\9.0.0-preview.7.24405.7\runtimes\wasi-wasm\native\src\synthetic-pthread.c -> C:\Users\user\source\repos\issue-106845-wasi-long-path-windows\loong\obj\De
  bug\net9.0\wasi-wasm\wasm\for-build\synthetic-pthread.o