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

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

Closed
jsturtevant opened this issue Aug 23, 2024 · 3 comments · Fixed by #107253
Closed

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

jsturtevant opened this issue Aug 23, 2024 · 3 comments · Fixed by #107253
Assignees
Labels
area-Build-mono in-pr There is an active PR which will close this issue when it is merged
Milestone

Comments

@jsturtevant
Copy link

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

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Aug 23, 2024
@lewing lewing added this to the 10.0.0 milestone Aug 23, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Aug 23, 2024
@ilonatommy
Copy link
Member

ilonatommy commented Aug 23, 2024

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 #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
Copy link
Member

ilonatommy commented Aug 23, 2024

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
Copy link
Member

ilonatommy commented Aug 30, 2024

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

@dotnet-policy-service dotnet-policy-service bot added the in-pr There is an active PR which will close this issue when it is merged label Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Build-mono in-pr There is an active PR which will close this issue when it is merged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants