Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
37 changes: 35 additions & 2 deletions src/libraries/System.Console/src/System/ConsolePal.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,53 @@

using System.IO;
using System.Text;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace System
{
internal sealed unsafe class LogcatStream : ConsoleStream
{
private readonly StringBuilder _buffer = new StringBuilder();

public LogcatStream() : base(FileAccess.Write) {}

public override int Read(byte[] buffer, int offset, int count) => throw Error.GetReadNotSupported();

public override unsafe void Write(byte[] buffer, int offset, int count)
{
string log = ConsolePal.OutputEncoding.GetString(buffer, offset, count);
Interop.Logcat.AndroidLogPrint(Interop.Logcat.LogLevel.Info, "DOTNET", log);
ValidateWrite(buffer, offset, count);

Span<byte> bufferSpan = buffer.AsSpan(offset, count);

Debug.Assert(ConsolePal.OutputEncoding == Encoding.Unicode);
Debug.Assert(bufferSpan.Length % 2 == 0);

Span<char> charSpan = MemoryMarshal.Cast<byte, char>(bufferSpan);

lock (_buffer)
{
if (charSpan.Contains('\n'))
{
string logLine;
if (_buffer.Length > 0)
{
_buffer.Append(charSpan);
logLine = _buffer.ToString();
_buffer.Clear();
}
else
{
logLine = charSpan.ToString();
}
Interop.Logcat.AndroidLogPrint(Interop.Logcat.LogLevel.Info, "DOTNET", logLine);
}
else
{
// accumulate results until "\n" is written
_buffer.Append(charSpan);
}
}
}
}

Expand Down
42 changes: 39 additions & 3 deletions src/libraries/System.Console/src/System/ConsolePal.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

using System.IO;
using System.Text;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace System
{
internal sealed class NSLogStream : ConsoleStream
{
private readonly StringBuilder _buffer = new StringBuilder();

public NSLogStream() : base(FileAccess.Write) {}

public override int Read(byte[] buffer, int offset, int count) => throw Error.GetReadNotSupported();
Expand All @@ -17,9 +21,41 @@ public override unsafe void Write(byte[] buffer, int offset, int count)
{
ValidateWrite(buffer, offset, count);

fixed (byte* ptr = buffer)
Span<byte> bufferSpan = buffer.AsSpan(offset, count);

Debug.Assert(ConsolePal.OutputEncoding == Encoding.Unicode);
Debug.Assert(bufferSpan.Length % 2 == 0);

Span<char> charSpan = MemoryMarshal.Cast<byte, char>(bufferSpan);

lock (_buffer)
{
Interop.Sys.Log(ptr + offset, count);
if (charSpan.Contains('\n'))
{
string logLine;
if (_buffer.Length > 0)
{
_buffer.Append(charSpan);
logLine = _buffer.ToString();
_buffer.Clear();
fixed (char* ptr = logLine)
{
Interop.Sys.Log((byte*)ptr, logLine.Length * 2);
}
}
else
{
fixed (byte* ptr = buffer)
{
Interop.Sys.Log(ptr + offset, count);
}
}
}
else
{
// accumulate results until "\n" is written
_buffer.Append(charSpan);
}
}
}
}
Expand Down Expand Up @@ -170,4 +206,4 @@ internal sealed class ControlCHandlerRegistrar
internal void Unregister() => throw new PlatformNotSupportedException();
}
}
}
}
6 changes: 3 additions & 3 deletions src/mono/netcore/sample/iOS/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ all: runtimepack run

TOOLS_DIR=../../../../../tools-local/tasks/mobile.tasks
appbuilder:
$(DOTNET) build -c Release $(TOOLS_DIR)/AotCompilerTask/MonoAOTCompiler.csproj
$(DOTNET) build -c Release $(TOOLS_DIR)/AppleAppBuilder/AppleAppBuilder.csproj
$(DOTNET) build -c $(MONO_ARCH) $(TOOLS_DIR)/AotCompilerTask/MonoAOTCompiler.csproj
$(DOTNET) build -c $(MONO_ARCH) $(TOOLS_DIR)/AppleAppBuilder/AppleAppBuilder.csproj

runtimepack:
../../../../.././build.sh Mono+Libs -os iOS -arch $(MONO_ARCH) -c $(MONO_CONFIG)

run: clean appbuilder
$(DOTNET) publish -c $(MONO_CONFIG) /p:TargetArchitecture=$(MONO_ARCH) \
/p:UseLLVM=$(USE_LLVM) /p:UseAotForSimulator=true
/p:UseLLVM=$(USE_LLVM) /p:UseAotForSimulator=false

clean:
rm -rf bin
2 changes: 1 addition & 1 deletion src/mono/netcore/sample/iOS/Program.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<Import Project="/Users/egorbo/prj/runtime/tools-local/tasks/mobile.tasks/AotCompilerTask/MonoAOTCompiler.props" />
<UsingTask TaskName="AppleAppBuilderTask"
AssemblyFile="$(ArtifactsBinDir)AppleAppBuilder\$(Configuration)\$(NetCoreAppCurrent)\AppleAppBuilder.dll" />
AssemblyFile="$(ArtifactsBinDir)AppleAppBuilder\$(Platform)\$(NetCoreAppCurrent)\AppleAppBuilder.dll" />

<UsingTask TaskName="MonoAOTCompiler"
AssemblyFile="$(ArtifactsBinDir)MonoAOTCompiler\$(Configuration)\$(NetCoreAppCurrent)\MonoAOTCompiler.dll" />
Expand Down