diff --git a/eng/pipelines/common/templates/wasi-wasm-coreclr-library-tests.yml b/eng/pipelines/common/templates/wasi-wasm-coreclr-library-tests.yml new file mode 100644 index 00000000000000..dff30c87bbfa31 --- /dev/null +++ b/eng/pipelines/common/templates/wasi-wasm-coreclr-library-tests.yml @@ -0,0 +1,86 @@ +parameters: + alwaysRun: false + extraBuildArgs: '' + extraHelixArguments: '' + isExtraPlatformsBuild: false + isWasmOnlyBuild: false + nameSuffix: '' + platforms: [] + scenarios: ['WasmTestOnWasmtime'] + shouldContinueOnError: false + shouldRunSmokeOnly: false + +jobs: + +# +# Build CoreCLR libraries for WASI and run the library tests on wasmtime via Helix. +# Mirrors wasm-coreclr-library-tests.yml (the browser-CoreCLR LibraryTestsCoreCLR leg), +# with the WasmTestOnWasmtime scenario and the wasi_wasm helix queue. +# See https://github.com/dotnet/runtime/issues/130129. +# +# Bring-up leg: smoke-only and non-gating (rolling alwaysRun). WasiApp.CoreCLR.targets +# performs a per-app native link of the wasihost corehost so a test's own +# [UnmanagedCallersOnly] reverse thunks are generated + linked into the host; with that link +# + the nested-type reverse-thunk +# key fix (also filed standalone as dotnet/runtime#130740; the remaining enclosing-type +# collision limitation is tracked by #130739) the interpreter discovers and runs the suite +# (validated locally: 9930 System.Runtime.Tests cases). #130634 (cold portable-entry-point +# publication) only affects a future R2R-enabled leg, not this pure-interpreter smoke. +# +- template: /eng/pipelines/common/platform-matrix.yml + parameters: + jobTemplate: /eng/pipelines/common/global-build-job.yml + helixQueuesTemplate: /eng/pipelines/libraries/helix-queues-setup.yml + buildConfig: Release + runtimeFlavor: coreclr + platforms: ${{ parameters.platforms }} + shouldContinueOnError: ${{ parameters.shouldContinueOnError }} + variables: + - name: alwaysRunVar + value: ${{ parameters.alwaysRun }} + - name: shouldRunOnDefaultPipelines + value: $[ + or( + eq(variables['wasmDarcDependenciesChanged'], true), + eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_tools_illink.containsChange'], true), + eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_libraries.containsChange'], true), + eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_wasm_coreclr_runtimetests.containsChange'], true)) + ] + # run smoke tests only if: + # - explicitly requested + # - libraries or illink changed and no wasm specific changes + - name: shouldRunSmokeOnlyVar + value: $[ + or( + eq('${{ parameters.shouldRunSmokeOnly }}', 'true'), + and( + eq('${{ parameters.shouldRunSmokeOnly }}', 'onLibrariesAndIllinkChanges'), + ne(variables['wasmDarcDependenciesChanged'], true), + or( + eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_tools_illink.containsChange'], true), + eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_libraries.containsChange'], true) + ) + ) + ) + ] + - name: _wasmRunSmokeTestsOnlyArg + value: /p:RunSmokeTestsOnly=$(shouldRunSmokeOnlyVar) + + jobParameters: + isExtraPlatforms: ${{ parameters.isExtraPlatformsBuild }} + testGroup: innerloop + nameSuffix: LibraryTestsCoreCLR_WASI${{ parameters.nameSuffix }} + buildArgs: -s clr+libs+host+packs+libs.tests -c $(_BuildConfig) /p:ArchiveTests=true $(_wasmRunSmokeTestsOnlyArg) /maxcpucount:1 ${{ parameters.extraBuildArgs }} + timeoutInMinutes: 240 + condition: >- + or( + eq(variables['alwaysRunVar'], true), + eq(variables['isDefaultPipeline'], variables['shouldRunOnDefaultPipelines'])) + # extra steps, run tests + postBuildSteps: + - template: /eng/pipelines/libraries/helix.yml + parameters: + creator: dotnet-bot + testRunNamePrefixSuffix: CoreCLR_WASI_$(_BuildConfig) + extraHelixArguments: $(_wasmRunSmokeTestsOnlyArg) ${{ parameters.extraHelixArguments }} + scenarios: ${{ parameters.scenarios }} diff --git a/eng/pipelines/runtime.yml b/eng/pipelines/runtime.yml index 77ec17437b8a1e..870fdb32116102 100644 --- a/eng/pipelines/runtime.yml +++ b/eng/pipelines/runtime.yml @@ -165,6 +165,16 @@ extends: - wasi_wasm alwaysRun: ${{ variables.isRollingBuild }} + # CoreCLR library-test smoke leg run on wasmtime via Helix + # (wasi_wasm queue). Starts with a single-library smoke set; see + # https://github.com/dotnet/runtime/issues/130129. + - template: /eng/pipelines/common/templates/wasi-wasm-coreclr-library-tests.yml + parameters: + platforms: + - wasi_wasm + shouldRunSmokeOnly: true + alwaysRun: ${{ variables.isRollingBuild }} + - template: /eng/pipelines/common/platform-matrix.yml parameters: jobTemplate: /eng/pipelines/common/global-build-job.yml diff --git a/eng/testing/tests.wasi.targets b/eng/testing/tests.wasi.targets index ec824fe2f52f3d..9a591156932b1f 100644 --- a/eng/testing/tests.wasi.targets +++ b/eng/testing/tests.wasi.targets @@ -21,9 +21,22 @@ for WBT, and debugger tests --> + + + false + + <_AppArgs Condition="'$(WasmSingleFileBundle)' == 'true'">$([System.IO.Path]::GetFileNameWithoutExtension('$(WasmMainAssemblyFileName)')).wasm - <_AppArgs Condition="'$(WasmSingleFileBundle)' != 'true'">dotnet.wasm WasmTestRunner + + <_AppArgs Condition="'$(WasmSingleFileBundle)' != 'true' and '$(RuntimeFlavor)' != 'CoreCLR'">dotnet.wasm WasmTestRunner + <_AppArgs Condition="'$(WasmSingleFileBundle)' != 'true' and '$(RuntimeFlavor)' == 'CoreCLR'">managed/corerun managed/WasmTestRunner.dll <_AppArgs Condition="'$(IsFunctionalTest)' != 'true' and '$(WasmSingleFileBundle)' != 'true'">$(_AppArgs) managed/$(AssemblyName).dll <_AppArgs Condition="'$(IsFunctionalTest)' != 'true' and '$(WasmSingleFileBundle)' == 'true'">$(_AppArgs) $(AssemblyName).dll @@ -52,6 +65,11 @@ <_XHarnessArgs >$(_XHarnessArgs) --engine-arg=--wasi --engine-arg=allow-ip-name-lookup <_XHarnessArgs >$(_XHarnessArgs) --engine-arg=--wasi --engine-arg=hostcall-fuel=4294967295 <_XHarnessArgs >$(_XHarnessArgs) --engine-arg=--env --engine-arg=DOTNET_WASI_PRINT_EXIT_CODE=1 + + <_XHarnessArgs Condition="'$(RuntimeFlavor)' == 'CoreCLR'">$(_XHarnessArgs) --engine-arg=-W --engine-arg=exceptions=y + <_XHarnessArgs Condition="'$(RuntimeFlavor)' == 'CoreCLR'">$(_XHarnessArgs) --engine-arg=--env --engine-arg=CORE_ROOT=/managed <_XHarnessArgs Condition="'$(WasmXHarnessArgsCli)' != ''" >$(_XHarnessArgs) $(WasmXHarnessArgsCli) <_InvariantGlobalization Condition="'$(InvariantGlobalization)' == 'true'">--env=DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ExceptionTests.cs b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ExceptionTests.cs index 843813a14997a4..879dfff4cd8d23 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ExceptionTests.cs +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ExceptionTests.cs @@ -110,6 +110,7 @@ public static void Exception_TargetSite_Rethrow() [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.HasAssemblyFiles))] [ActiveIssue("https://github.com/mono/mono/issues/15140", TestRuntimes.Mono)] [ActiveIssue("https://github.com/dotnet/runtime/issues/124344", typeof(PlatformDetection), nameof(PlatformDetection.IsAppleMobile), nameof(PlatformDetection.IsCoreCLR))] + [ActiveIssue("https://github.com/dotnet/runtime/issues/130796", typeof(PlatformDetection), nameof(PlatformDetection.IsWasi), nameof(PlatformDetection.IsCoreCLR))] public static void ThrowStatementDoesNotResetExceptionStackLineSameMethod() { (string, string, int) rethrownExceptionStackFrame = (null, null, 0); @@ -141,6 +142,7 @@ private static (string, string, int) ThrowAndRethrowSameMethod(out (string, stri // [ActiveIssue(https://github.com/dotnet/runtime/issues/1871)] can't use ActiveIssue for archs [ActiveIssue("https://github.com/mono/mono/issues/15141", TestRuntimes.Mono)] [ActiveIssue("https://github.com/dotnet/runtime/issues/124344", typeof(PlatformDetection), nameof(PlatformDetection.IsAppleMobile), nameof(PlatformDetection.IsX64Process), nameof(PlatformDetection.IsCoreCLR))] + [ActiveIssue("https://github.com/dotnet/runtime/issues/130796", typeof(PlatformDetection), nameof(PlatformDetection.IsWasi), nameof(PlatformDetection.IsCoreCLR))] public static void ThrowStatementDoesNotResetExceptionStackLineOtherMethod() { (string, string, int) rethrownExceptionStackFrame = (null, null, 0); diff --git a/src/libraries/sendtohelix-wasi.targets b/src/libraries/sendtohelix-wasi.targets index 44500dfaad7b7b..2da43e62f9cc6f 100644 --- a/src/libraries/sendtohelix-wasi.targets +++ b/src/libraries/sendtohelix-wasi.targets @@ -32,6 +32,9 @@ true + + $(Scenario)-CLR-ST- wasmtime true @@ -124,12 +127,21 @@ + + + + + + diff --git a/src/libraries/tests.proj b/src/libraries/tests.proj index 4d543e9028294d..f5bb4e5f998421 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -557,8 +557,8 @@ - - + + @@ -576,7 +576,11 @@ - + + + + diff --git a/src/mono/wasi/build/WasiApp.CoreCLR.targets b/src/mono/wasi/build/WasiApp.CoreCLR.targets new file mode 100644 index 00000000000000..9415a5ab7f9ca4 --- /dev/null +++ b/src/mono/wasi/build/WasiApp.CoreCLR.targets @@ -0,0 +1,324 @@ + + + + + + + + + CoreCLR + false + + false + false + + + + + + + + + + + + + + + + + + + + + + <_WasiCoreCLRCoreLib Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)System.Private.CoreLib.dll" /> + + <_WasiCoreCLRFrameworkFiles Include="$(MicrosoftNetCoreAppRuntimePackRidLibTfmDir)\*.dll" /> + <_WasiCoreCLRFrameworkToCopy Include="@(_WasiCoreCLRFrameworkFiles)" + Condition="!Exists('$(WasmAppDir)managed\%(_WasiCoreCLRFrameworkFiles.FileName)%(_WasiCoreCLRFrameworkFiles.Extension)')" /> + + + + + + + + + + + + + + + <_WasiRelinkObjDir>$([MSBuild]::NormalizeDirectory('$(_WasmIntermediateOutputPath)', 'corerun-relink')) + <_WasiClangxx>$(WASI_SDK_PATH)bin/clang++ + <_WasiClangxx Condition="$([MSBuild]::IsOSPlatform('Windows'))">$(_WasiClangxx).exe + <_WasiComponentLd>$(WasiSdkBinPath)wasm-component-ld + <_WasiComponentLd Condition="$([MSBuild]::IsOSPlatform('Windows'))">$(_WasiComponentLd).exe + <_WasiSysroot>$(WASI_SDK_PATH)share/wasi-sysroot + + <_WasiPInvokeTablePath>$(_WasiRelinkObjDir)callhelpers-pinvoke.cpp + <_WasiReversePInvokeTablePath>$(_WasiRelinkObjDir)callhelpers-reverse.cpp + <_WasiInterpToNativeTablePath>$(_WasiRelinkObjDir)callhelpers-interp-to-managed.cpp + <_WasiM2NCachePath>$(_WasiRelinkObjDir)m2n_cache.txt + + + <_WasiCoreClrCompatHeader Condition="'$(CORECLR_COMPAT_HEADER)' != ''">$([System.IO.Path]::GetFullPath('$(CORECLR_COMPAT_HEADER)')) + <_WasiCoreClrCompatHeader Condition="'$(_WasiCoreClrCompatHeader)' == ''">$([MSBuild]::NormalizePath('$(MSBuildThisFileDirectory)', '..', '..', 'browser', 'build', 'coreclr_compat.h')) + <_WasiVmWasmIncludeDir Condition="'$(CORECLR_VM_WASM_INCLUDE_DIR)' != ''">$([MSBuild]::EnsureTrailingSlash($([System.IO.Path]::GetFullPath('$(CORECLR_VM_WASM_INCLUDE_DIR)')))) + <_WasiVmWasmIncludeDir Condition="'$(_WasiVmWasmIncludeDir)' == ''">$([MSBuild]::NormalizeDirectory('$(MSBuildThisFileDirectory)..', '..', '..', 'coreclr', 'vm', 'wasm')) + <_WasiMinipalIncludeRoot Condition="'$(MINIPAL_INCLUDE_DIR)' != ''">$([MSBuild]::NormalizeDirectory($([System.IO.Path]::GetFullPath('$(MINIPAL_INCLUDE_DIR)')), '..')) + <_WasiMinipalIncludeRoot Condition="'$(_WasiMinipalIncludeRoot)' == ''">$([MSBuild]::NormalizeDirectory('$(MSBuildThisFileDirectory)..', '..', '..', 'native')) + + + <_WasiHttpWorldWit>$(MicrosoftNetCoreAppRuntimePackRidNativeDir)WasiHttpWorld_component_type.wit + <_WasiHttpWorldWit Condition="!Exists('$(_WasiHttpWorldWit)')">$([MSBuild]::NormalizePath('$(MSBuildThisFileDirectory)..', '..', '..', 'libraries', 'System.Net.Http', 'src', 'System', 'Net', 'Http', 'WasiHttpHandler', 'WasiHttpWorld_component_type.wit')) + + <_WasiRelinkCompileRsp>$(_WasiRelinkObjDir)compile.rsp + <_WasiRelinkLinkRsp>$(_WasiRelinkObjDir)link.rsp + <_WasiRelinkOptFlag Condition="'$(Configuration)' == 'Debug'">-O1 + <_WasiRelinkOptFlag Condition="'$(_WasiRelinkOptFlag)' == ''">-O2 + + + + + + + + + + <_WasiManagedAssemblies Include="$(WasmAppDir)managed\*.dll" /> + + <_WasiPInvokeModules Include="libSystem.Native" /> + <_WasiPInvokeModules Include="libSystem.IO.Compression.Native" /> + <_WasiPInvokeModules Include="libSystem.Globalization.Native" Condition="'$(InvariantGlobalization)' != 'true'" /> + <_WasiIgnoredPInvokeModules Include="libSystem.Globalization.Native" Condition="'$(InvariantGlobalization)' == 'true'" /> + + + + + + + + + <_WasiRelinkCompileFlags Include="--target=wasm32-unknown-wasip2" /> + <_WasiRelinkCompileFlags Include="--sysroot="$(_WasiSysroot.Replace('\','/'))"" /> + <_WasiRelinkCompileFlags Include="$(_WasiRelinkOptFlag)" /> + <_WasiRelinkCompileFlags Include="-DNDEBUG" Condition="'$(Configuration)' != 'Debug'" /> + <_WasiRelinkCompileFlags Include="-std=gnu++17" /> + <_WasiRelinkCompileFlags Include="-fwasm-exceptions" /> + <_WasiRelinkCompileFlags Include="-mllvm" /> + <_WasiRelinkCompileFlags Include="-wasm-use-legacy-eh=false" /> + <_WasiRelinkCompileFlags Include="-fno-rtti" /> + + <_WasiRelinkCompileFlags Include="-DGEN_PINVOKE=1" /> + <_WasiRelinkCompileFlags Include="-DCOMPILER_SUPPORTS_W_RESERVED_IDENTIFIER" /> + <_WasiRelinkCompileFlags Include="-DDEBUGGING_SUPPORTED" /> + <_WasiRelinkCompileFlags Include="-DDISABLE_CONTRACTS" /> + <_WasiRelinkCompileFlags Include="-DFEATURE_CACHED_INTERFACE_DISPATCH" /> + <_WasiRelinkCompileFlags Include="-DFEATURE_COLLECTIBLE_TYPES" /> + <_WasiRelinkCompileFlags Include="-DFEATURE_CORECLR" /> + <_WasiRelinkCompileFlags Include="-DFEATURE_CORECLR_FLUSH_INSTRUCTION_CACHE_TO_PROTECT_STUB_READS" /> + <_WasiRelinkCompileFlags Include="-DFEATURE_DBGIPC_TRANSPORT_DI" /> + <_WasiRelinkCompileFlags Include="-DFEATURE_DBGIPC_TRANSPORT_VM" /> + <_WasiRelinkCompileFlags Include="-DFEATURE_DEFAULT_INTERFACES" /> + <_WasiRelinkCompileFlags Include="-DFEATURE_INTERPRETER" /> + <_WasiRelinkCompileFlags Include="-DFEATURE_MULTICOREJIT" /> + <_WasiRelinkCompileFlags Include="-DFEATURE_PAL_ANSI" /> + <_WasiRelinkCompileFlags Include="-DFEATURE_PORTABLE_ENTRYPOINTS" /> + <_WasiRelinkCompileFlags Include="-DFEATURE_PORTABLE_HELPERS" /> + <_WasiRelinkCompileFlags Include="-DFEATURE_READYTORUN" /> + <_WasiRelinkCompileFlags Include="-DFEATURE_REMOTE_PROC_MEM" /> + <_WasiRelinkCompileFlags Include="-DFEATURE_STATICALLY_LINKED" /> + <_WasiRelinkCompileFlags Include="-DFEATURE_SYMDIFF" /> + <_WasiRelinkCompileFlags Include="-DFEATURE_USE_ASM_GC_WRITE_BARRIERS" /> + <_WasiRelinkCompileFlags Include="-DFEATURE_WEBCIL" /> + <_WasiRelinkCompileFlags Include="-DHOST_32BIT=1" /> + <_WasiRelinkCompileFlags Include="-DHOST_UNIX" /> + <_WasiRelinkCompileFlags Include="-DHOST_WASM" /> + <_WasiRelinkCompileFlags Include="-DTARGET_32BIT" /> + <_WasiRelinkCompileFlags Include="-DTARGET_UNIX" /> + <_WasiRelinkCompileFlags Include="-DTARGET_WASI" /> + <_WasiRelinkCompileFlags Include="-DTARGET_WASM" /> + <_WasiRelinkCompileFlags Include="-DTARGET_WASM32" /> + <_WasiRelinkCompileFlags Include="-DUNICODE" /> + <_WasiRelinkCompileFlags Include="-D_UNICODE" /> + <_WasiRelinkCompileFlags Include="-DURTBLDENV_FRIENDLY=Retail" /> + <_WasiRelinkCompileFlags Include="-D_FILE_OFFSET_BITS=64" /> + <_WasiRelinkCompileFlags Include="-D_TIME_BITS=64" /> + <_WasiRelinkCompileFlags Include="-D_SECURE_SCL=0" /> + <_WasiRelinkCompileFlags Include="-D_WASI_EMULATED_GETPID" /> + <_WasiRelinkCompileFlags Include="-D_WASI_EMULATED_MMAN" /> + <_WasiRelinkCompileFlags Include="-D_WASI_EMULATED_PROCESS_CLOCKS" /> + <_WasiRelinkCompileFlags Include="-D_WASI_EMULATED_SIGNAL" /> + <_WasiRelinkCompileFlags Include="-include "$(_WasiCoreClrCompatHeader.Replace('\','/'))"" /> + <_WasiRelinkCompileFlags Include="-I"$(_WasiVmWasmIncludeDir.TrimEnd('\/').Replace('\','/'))"" /> + <_WasiRelinkCompileFlags Include="-I"$(_WasiMinipalIncludeRoot.TrimEnd('\/').Replace('\','/'))"" /> + + + + + <_WasiCallHelperSource Include="$(_WasiPInvokeTablePath)" ObjectFile="$(_WasiRelinkObjDir)callhelpers-pinvoke.o" /> + <_WasiCallHelperSource Include="$(_WasiReversePInvokeTablePath)" ObjectFile="$(_WasiRelinkObjDir)callhelpers-reverse.o" /> + <_WasiCallHelperSource Include="$(_WasiInterpToNativeTablePath)" ObjectFile="$(_WasiRelinkObjDir)callhelpers-interp-to-managed.o" /> + + + + + + + + <_WasiHostLibsPre Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)libminipal.a" /> + <_WasiHostLibsPre Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)libcoreclr_static.a" /> + <_WasiHostLibsPre Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)libSystem.IO.Compression.Native.a" /> + <_WasiHostLibsPre Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)libSystem.Native.a" /> + <_WasiHostLibsPre Condition="'$(InvariantTimezone)' == 'true'" Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)libSystem.Native.TimeZoneData.Invariant.a" /> + <_WasiHostLibsPre Condition="'$(InvariantTimezone)' != 'true'" Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)libSystem.Native.TimeZoneData.a" /> + + <_WasiHostLibsPre Include="%(_WasiCallHelperSource.ObjectFile)" /> + <_WasiHostLibsPre Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)libnativeresourcestring.a" /> + + + <_WasiHostLibsPre Condition="'$(InvariantGlobalization)' != 'true'" Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)libSystem.Globalization.Native.a" /> + <_WasiHostLibsPre Condition="'$(InvariantGlobalization)' != 'true'" Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)libicuuc.a" /> + <_WasiHostLibsPre Condition="'$(InvariantGlobalization)' != 'true'" Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)libicui18n.a" /> + <_WasiHostLibsPre Condition="'$(InvariantGlobalization)' != 'true'" Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)libicudata.a" /> + + + <_WasiHostLibsPost Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)libcoreclrminipal.a" /> + <_WasiHostLibsPost Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)libcoreclrpal.a" /> + <_WasiHostLibsPost Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)libminipal.a" /> + <_WasiHostLibsPost Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)libz.a" /> + <_WasiHostLibsPost Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)libzstd.a" Condition="Exists('$(MicrosoftNetCoreAppRuntimePackRidNativeDir)libzstd.a')" /> + + + + <_WasiRelinkOutput>$(WasmAppDir)managed\corerun + + + + <_WasiRelinkLinkFlags Include="--target=wasm32-unknown-wasip2" /> + <_WasiRelinkLinkFlags Include="$(_WasiRelinkOptFlag)" /> + <_WasiRelinkLinkFlags Include="-DNDEBUG" Condition="'$(Configuration)' != 'Debug'" /> + <_WasiRelinkLinkFlags Include="-Wl,--gc-sections" /> + <_WasiRelinkLinkFlags Include="-fwasm-exceptions" /> + <_WasiRelinkLinkFlags Include="-mllvm" /> + <_WasiRelinkLinkFlags Include="-wasm-use-legacy-eh=false" /> + <_WasiRelinkLinkFlags Include="-Wno-unused-command-line-argument" /> + <_WasiRelinkLinkFlags Include="-Wl,--error-limit=0" /> + <_WasiRelinkLinkFlags Include="-lc -lc++ -lc++abi -lunwind -ldl" /> + <_WasiRelinkLinkFlags Include="-lwasi-emulated-process-clocks -lwasi-emulated-signal -lwasi-emulated-mman -lwasi-emulated-getpid" /> + <_WasiRelinkLinkFlags Include="-fuse-ld="$(_WasiComponentLd.Replace('\','/'))"" /> + <_WasiRelinkLinkFlags Include="-Wl,-z,stack-size=8388608" /> + <_WasiRelinkLinkFlags Include="-Wl,--initial-memory=134217728" /> + <_WasiRelinkLinkFlags Include="-Wl,--max-memory=4294967296" /> + <_WasiRelinkLinkFlags Include="-Wl,--component-type,"$(_WasiHttpWorldWit.Replace('\','/'))"" /> + + <_WasiRelinkLinkFlags Include="-Wl,--whole-archive" /> + <_WasiRelinkLinkFlags Include=""$(MicrosoftNetCoreAppRuntimePackRidNativeDir)libWasiHost.a"" /> + <_WasiRelinkLinkFlags Include="-Wl,--no-whole-archive" /> + <_WasiRelinkLinkFlags Include="@(_WasiHostLibsPre->'"%(Identity)"')" /> + <_WasiRelinkLinkFlags Include="-lstdc++" /> + <_WasiRelinkLinkFlags Include="@(_WasiHostLibsPost->'"%(Identity)"')" /> + <_WasiRelinkLinkFlags Include="-o "$(_WasiRelinkOutput.Replace('\','/'))"" /> + + + + + + + + + + + + diff --git a/src/mono/wasi/build/WasiApp.InTree.props b/src/mono/wasi/build/WasiApp.InTree.props index db34cf23a2f5f9..ae0f77312bfe23 100644 --- a/src/mono/wasi/build/WasiApp.InTree.props +++ b/src/mono/wasi/build/WasiApp.InTree.props @@ -1,6 +1,22 @@ + + + + false + + false + + + true + + AnyCPU false @@ -10,7 +26,7 @@ full false - + <_MonoRuntimeComponentDontLink Include="libmono-component-diagnostics_tracing-static.a"/> <_MonoRuntimeComponentDontLink Include="libmono-component-debugger-stub-static.a" /> <_MonoRuntimeComponentDontLink Include="libmono-component-hot_reload-stub-static.a" /> diff --git a/src/mono/wasi/build/WasiApp.InTree.targets b/src/mono/wasi/build/WasiApp.InTree.targets index 5161dead820985..03c856d16ad71d 100644 --- a/src/mono/wasi/build/WasiApp.InTree.targets +++ b/src/mono/wasi/build/WasiApp.InTree.targets @@ -7,7 +7,11 @@ - + + + _symbolNameFixups = new(); List managedAssemblies = FilterOutUnmanagedBinaries(Assemblies); - var pinvoke = new PInvokeTableGenerator(FixupSymbolName, log, IsLibraryMode, TargetOS); + var pinvoke = new PInvokeTableGenerator(FixupSymbolName, log, IsLibraryMode, TargetOS, WarnOnUnresolvedPInvokeModules); var internalCallCollector = new InternalCallSignatureCollector(log); var resolver = new PathAssemblyResolver(managedAssemblies); diff --git a/src/tasks/WasmAppBuilder/coreclr/PInvokeTableGenerator.cs b/src/tasks/WasmAppBuilder/coreclr/PInvokeTableGenerator.cs index 7542c7ddb55557..13d3a151e47874 100644 --- a/src/tasks/WasmAppBuilder/coreclr/PInvokeTableGenerator.cs +++ b/src/tasks/WasmAppBuilder/coreclr/PInvokeTableGenerator.cs @@ -25,13 +25,15 @@ internal sealed class PInvokeTableGenerator private readonly List callbacks = new(); private readonly PInvokeCollector _pinvokeCollector; private readonly bool _isLibraryMode; + private readonly bool _warnOnUnresolvedModules; - public PInvokeTableGenerator(Func fixupSymbolName, LogAdapter log, bool isLibraryMode, string targetOS) + public PInvokeTableGenerator(Func fixupSymbolName, LogAdapter log, bool isLibraryMode, string targetOS, bool warnOnUnresolvedModules = true) { Log = log; _fixupSymbolName = fixupSymbolName; _pinvokeCollector = new(log, targetOS); _isLibraryMode = isLibraryMode; + _warnOnUnresolvedModules = warnOnUnresolvedModules; } public void ScanAssembly(Assembly asm) @@ -103,7 +105,15 @@ private void EmitPInvokeTable(StreamWriter w, SortedDictionary m } else if (pinvoke.Module != "QCall") { - Log.Warning("WASM0066", $"PInvoke module '{pinvoke.Module}' for method '{pinvoke.Method.DeclaringType}::{pinvoke.Method.Name}' is not in the list of allowed modules. It is also not a specially treated module."); + // Unresolved module: not statically linked, ignored, [WasmImportLinkage], "*" or QCall. + // By design we skip it and throw at runtime if it is ever called. For hand-authored + // apps this is likely a bug, so warn; consumers scanning untrimmed closures full of + // cross-platform interop (library-test bundles) disable the warning to avoid failing + // the build under warn-as-error for P/Invokes that are never called on wasm. + if (_warnOnUnresolvedModules) + Log.Warning("WASM0066", $"PInvoke module '{pinvoke.Module}' for method '{pinvoke.Method.DeclaringType}::{pinvoke.Method.Name}' is not in the list of allowed modules. It is also not a specially treated module."); + else if (ignoredModules.Add(pinvoke.Module)) + Log.LogMessage(MessageImportance.Low, $"Skipping unresolved PInvoke module '{pinvoke.Module}' for method '{pinvoke.Method.DeclaringType}::{pinvoke.Method.Name}' (not statically linked on wasm; will throw if called)." ); } }