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

[NativeAOT-LLVM] support System.Net.Http.HttpClient - leftovers #2758

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions eng/pipelines/common/global-build-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ jobs:
displayName: Install wasi-sdk
- script: pwsh $(Build.SourcesDirectory)/eng/pipelines/runtimelab/install-wasmtime.ps1 -CI -InstallDir $(Build.SourcesDirectory)/wasm-tools
displayName: Install wasmtime
- script: pwsh $(Build.SourcesDirectory)/eng/pipelines/runtimelab/install-jco.ps1 $(Build.SourcesDirectory)
displayName: Install Jco

- ${{ if or(eq(parameters.platform, 'browser_wasm_win'), and(eq(parameters.platform, 'wasi_wasm_win'), not(eq(parameters.runtimeFlavor, 'coreclr')))) }}:
# Update machine certs
Expand Down
9 changes: 9 additions & 0 deletions eng/pipelines/runtimelab/install-jco.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$RootPath = $Args[0]

$NpmExePath = $Env:NPM_EXECUTABLE

Set-Location -Path $RootPath

& $NpmExePath install @bytecodealliance/jco
& $NpmExePath install @bytecodealliance/preview2-shim

11 changes: 11 additions & 0 deletions eng/pipelines/runtimelab/install-nodejs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ if ($IsWindows)
{
Expand-Archive -LiteralPath "$InstallPath\$NodeJSZipName" -DestinationPath $InstallPath -Force
$NodeJSExePath = "$InstallPath\$NodeJSInstallName\node.exe"
$NpmExePath = "$InstallPath\$NodeJSInstallName\npm.cmd"
}
else
{
tar xJf $InstallPath/$NodeJSZipName -C $InstallPath
$NodeJSExePath = "$InstallPath/$NodeJSInstallName/bin/node"
$NpmExePath = "$InstallPath/$NodeJSInstallName/bin/npm"
}

if (!(Test-Path $NodeJSExePath))
Expand All @@ -64,5 +66,14 @@ if (!(Test-Path $NodeJSExePath))
exit 1
}

if (!(Test-Path $NpmExePath))
{
Write-Error "Did not find NPM at: '$NpmExePath'"
exit 1
}

Write-Host Setting NODEJS_EXECUTABLE to $NodeJSExePath
Write-Host "##vso[task.setvariable variable=NODEJS_EXECUTABLE]$NodeJSExePath"

Write-Host Setting NPM_EXECUTABLE to $NpmExePath
Write-Host "##vso[task.setvariable variable=NPM_EXECUTABLE]$NpmExePath"
6 changes: 4 additions & 2 deletions eng/testing/FindWasmHostExecutable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ exename=$(basename "$exename" .js)
dirname=$(dirname "$1")

node="node --stack_trace_limit=100"
WASM_HOST_ARGS_SEPERATOR=""

if [ -e "${dirname}/${exename}.js" ]; then
WASM_HOST_EXECUTABLE=$node
Expand All @@ -21,6 +20,9 @@ elif [ -e "${dirname}/main.mjs" ]; then
WASM_HOST_EXECUTABLE=$node
WASM_BINARY_TO_EXECUTE="${dirname}/main.mjs"
elif [ -e "${dirname}/${exename}.wasm" ]; then
WASM_HOST_EXECUTABLE="$WASMTIME_EXECUTABLE -S http"
if [ -z "$WASMTIME_EXECUTABLE" ]; then
WASMTIME_EXECUTABLE=wasmtime
fi
WASM_HOST_EXECUTABLE="$WASMTIME_EXECUTABLE run -S http"
WASM_BINARY_TO_EXECUTE="${dirname}/${exename}.wasm"
fi
4 changes: 2 additions & 2 deletions eng/testing/FindWasmHostExecutableAndRun.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ source $SCRIPT_DIR/FindWasmHostExecutable.sh "$1"

if [ -n "${WASM_HOST_EXECUTABLE}" ]; then
shift
echo $WASM_HOST_EXECUTABLE "$WASM_BINARY_TO_EXECUTE" $WASM_HOST_ARGS_SEPERATOR "$@"
$WASM_HOST_EXECUTABLE "$WASM_BINARY_TO_EXECUTE" $WASM_HOST_ARGS_SEPERATOR "$@"
echo $WASM_HOST_EXECUTABLE "$WASM_BINARY_TO_EXECUTE" "$@"
$WASM_HOST_EXECUTABLE "$WASM_BINARY_TO_EXECUTE" "$@"
else
echo WASM_HOST_EXECUTABLE not set.
exit 1
Expand Down
8 changes: 5 additions & 3 deletions src/coreclr/build-runtime.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,11 @@ for /f "delims=" %%a in ("-%__RequestedBuildComponents%-") do (
set __CMakeTarget=!__CMakeTarget! nativeaot

if "%__TargetArch%"=="wasm" (
if not defined EMSDK (
echo %__ErrMsgPrefix%%__MsgPrefix%Error: The EMSDK environment variable pointing to emsdk root must be set.
goto ExitWithError
if "%__TargetOS%"=="browser" (
if not defined EMSDK (
echo %__ErrMsgPrefix%%__MsgPrefix%Error: The EMSDK environment variable pointing to emsdk root must be set.
goto ExitWithError
)
)
)
)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9537,7 +9537,7 @@ void dumpConvertedVarSet(Compiler* comp, VARSET_VALARG_TP vars)
{
printf(" ");
}
printf("V%02u", varNum);
printf("V%02u", (unsigned int) varNum);
first = false;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/llvmlssa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1689,6 +1689,7 @@ class ShadowStackAllocator
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-security"
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif // __clang__
if (pBuffer == nullptr)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ public partial class ConsoleLifetime : IHostLifetime

private partial void RegisterShutdownHandlers()
{
Action<PosixSignalContext> handler = HandlePosixSignal;
_sigIntRegistration = PosixSignalRegistration.Create(PosixSignal.SIGINT, handler);
_sigQuitRegistration = PosixSignalRegistration.Create(PosixSignal.SIGQUIT, handler);
_sigTermRegistration = PosixSignalRegistration.Create(PosixSignal.SIGTERM, handler);
if (!OperatingSystem.IsWasi())
{
Action<PosixSignalContext> handler = HandlePosixSignal;
_sigIntRegistration = PosixSignalRegistration.Create(PosixSignal.SIGINT, handler);
_sigQuitRegistration = PosixSignalRegistration.Create(PosixSignal.SIGQUIT, handler);
_sigTermRegistration = PosixSignalRegistration.Create(PosixSignal.SIGTERM, handler);
}
}

private void HandlePosixSignal(PosixSignalContext context)
Expand All @@ -31,9 +34,12 @@ private void HandlePosixSignal(PosixSignalContext context)

private partial void UnregisterShutdownHandlers()
{
_sigIntRegistration?.Dispose();
_sigQuitRegistration?.Dispose();
_sigTermRegistration?.Dispose();
if (!OperatingSystem.IsWasi())
{
_sigIntRegistration?.Dispose();
_sigQuitRegistration?.Dispose();
_sigTermRegistration?.Dispose();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
private WasiRequestWrapper wrapper; // owned by this instance
private IncomingBody body; // owned by this instance
private InputStream stream; // owned by this instance
private HttpResponseMessage response;

private int offset;
private byte[]? buffer;
Expand All @@ -28,11 +29,16 @@
public override bool CanWrite => false;
public override bool CanSeek => false;

public WasiInputStream(WasiRequestWrapper wrapper, IncomingBody body)
public WasiInputStream(
WasiRequestWrapper wrapper,
IncomingBody body,
HttpResponseMessage response
)
{
this.wrapper = wrapper;
this.body = body;
this.stream = body.Stream();
this.response = response;
}

~WasiInputStream()
Expand Down Expand Up @@ -111,6 +117,7 @@
if (((StreamError)e.Value).Tag == StreamError.CLOSED)
{
otherSideClosed = true;
await ReadTrailingHeaders(cancellationToken).ConfigureAwait(false);
return 0;
}
else
Expand Down Expand Up @@ -158,6 +165,56 @@
return result;
}

private async Task ReadTrailingHeaders(CancellationToken cancellationToken)
{
isClosed = true;
stream.Dispose();
using var futureTrailers = IncomingBody.Finish(body);
while (true)
{
var trailers = futureTrailers.Get();
if (trailers is null)
{
cancellationToken.ThrowIfCancellationRequested();
await WasiHttpInterop
.RegisterWasiPollable(futureTrailers.Subscribe(), cancellationToken)
.ConfigureAwait(false);
}
else
{
var inner = ((Result<Result<Fields?, ErrorCode>, None>)trailers!).AsOk;
if (inner.IsOk)
{
using var headers = inner.AsOk;
if (headers is not null)
{
response.StoreReceivedTrailingHeaders(
WasiHttpInterop.ConvertTrailingResponseHeaders(headers)

Check failure on line 192 in src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiInputStream.cs

View check run for this annotation

Azure Pipelines / runtimelab (Build wasi-wasm linux debug)

src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiInputStream.cs#L192

src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiInputStream.cs(192,49): error CS0117: (NETCORE_ENGINEERING_TELEMETRY=Build) 'WasiHttpInterop' does not contain a definition for 'ConvertTrailingResponseHeaders'

Check failure on line 192 in src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiInputStream.cs

View check run for this annotation

Azure Pipelines / runtimelab (Build wasi-wasm linux release)

src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiInputStream.cs#L192

src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiInputStream.cs(192,49): error CS0117: (NETCORE_ENGINEERING_TELEMETRY=Build) 'WasiHttpInterop' does not contain a definition for 'ConvertTrailingResponseHeaders'

Check failure on line 192 in src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiInputStream.cs

View check run for this annotation

Azure Pipelines / runtimelab

src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiInputStream.cs#L192

src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiInputStream.cs(192,49): error CS0117: (NETCORE_ENGINEERING_TELEMETRY=Build) 'WasiHttpInterop' does not contain a definition for 'ConvertTrailingResponseHeaders'
);
}

break;
}
else if (inner.AsErr.Tag == ErrorCode.CONNECTION_TERMINATED)
{
// TODO: As of this writing, `wasmtime-wasi-http`
// returns this error when no headers are present. I
// *think* that's a bug, since the `wasi-http` WIT docs
// say it should return `none` rather than an error in
// that case. If it turns out that, yes, it's a bug, we
// can remove this case once a fix is available.
break;
}
else
{
throw new HttpRequestException(
WasiHttpInterop.ErrorCodeToString(inner.AsErr)
);
}
}
}
}

#region PlatformNotSupported

public override void Flush()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-unix;$(NetCoreAppCurrent)-osx;$(NetCoreAppCurrent)-ios;$(NetCoreAppCurrent)-tvos;$(NetCoreAppCurrent)</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-unix;$(NetCoreAppCurrent)-wasi;$(NetCoreAppCurrent)-osx;$(NetCoreAppCurrent)-ios;$(NetCoreAppCurrent)-tvos;$(NetCoreAppCurrent)</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<!-- SYSTEM_NET_SOCKETS_DLL is required to allow source-level code sharing for types defined within the
System.Net.Internals namespace. -->
Expand Down Expand Up @@ -183,7 +183,7 @@
Link="Common\System\Net\CompletionPortHelper.Windows.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'unix' or '$(TargetPlatformIdentifier)' == 'osx' or '$(TargetPlatformIdentifier)' == 'ios' or '$(TargetPlatformIdentifier)' == 'tvos'">
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'unix' or '$(TargetPlatformIdentifier)' == 'osx' or '$(TargetPlatformIdentifier)' == 'ios' or '$(TargetPlatformIdentifier)' == 'tvos' or '$(TargetPlatformIdentifier)' == 'wasi'">
<Compile Include="System\Net\Sockets\SafeSocketHandle.Unix.cs" />
<Compile Include="System\Net\Sockets\Socket.Unix.cs" />
<Compile Include="System\Net\Sockets\SocketAsyncContext.Unix.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,10 @@ public bool Wait(int millisecondsTimeout)
#endif
public bool Wait(int millisecondsTimeout, CancellationToken cancellationToken)
{
#if TARGET_WASI
_ = s_cancellationTokenCallback;
throw new PlatformNotSupportedException("ManualResetEventSlim.Wait not supported on WASI");
#else // not TARGET_WASI
ObjectDisposedException.ThrowIf(IsDisposed, this);
cancellationToken.ThrowIfCancellationRequested(); // an early convenience check

Expand Down Expand Up @@ -595,6 +599,7 @@ public bool Wait(int millisecondsTimeout, CancellationToken cancellationToken)
} // automatically disposes (and unregisters) the callback

return true; // done. The wait was satisfied.
#endif // not TARGET_WASI
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions src/tests/nativeaot/SmokeTests/SharedLibrary/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry=https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public-npm/npm/registry/
Loading
Loading