Skip to content

Commit

Permalink
Begin native tools CLI as example program for native volatile process
Browse files Browse the repository at this point in the history
This project builds an executable file for each supported OS that we can use with the planned new (native) volatile process model.
  • Loading branch information
Viir committed Jun 30, 2023
1 parent 72c2d29 commit 74c0bbc
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/build-native-tools.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: build-native-tools

on: [push,workflow_dispatch]

jobs:
build:

strategy:
fail-fast: false
matrix:
environment: [ubuntu-22.04, windows-2022, macos-13]
include:
- environment: ubuntu-22.04
publish-runtime-id: linux-x64
- environment: windows-2022
publish-runtime-id: win10-x64
- environment: macos-13
publish-runtime-id: osx-x64

runs-on: ${{ matrix.environment }}

steps:

- name: Avoid git mutating files on checkout
run: |
git config --global core.autocrlf false
- uses: actions/checkout@v3
- uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.304'

- name: Try use dotnet
run: dotnet --info

- name: Clean package cache as a temporary workaround for https://github.com/actions/setup-dotnet/issues/155
run: dotnet clean ./implement/native-tools/native-tools.csproj && dotnet nuget locals all --clear

- name: dotnet publish
run: dotnet publish -c Debug -r ${{ matrix.publish-runtime-id }} --output ./dotnet-build ./implement/native-tools

- name: Copy artifacts to publish
shell: pwsh
run: |
New-Item -ItemType Directory -Force -Path "./publish";
Get-ChildItem -Path "./dotnet-build/" -Filter "native-tools*" | ForEach-Object { Copy-Item -Path $_.FullName -Destination "./publish/" }
- name: Publish artifacts
uses: actions/upload-artifact@v3
with:
name: native-tools-bin-${{ github.sha }}-${{ matrix.publish-runtime-id }}
path: ./publish
31 changes: 31 additions & 0 deletions implement/native-tools/EchoJson.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Text.Json;

namespace native_tools;

public class EchoJson
{
public static int EchoJsonLoop()
{
while (true)
{
var lineText = Console.ReadLine()?.Trim();

if (string.IsNullOrEmpty(lineText))
{
continue;
}

try
{
var json = JsonSerializer.Deserialize<JsonElement>(lineText);
Console.WriteLine(JsonSerializer.Serialize(json) + "\n");
}
catch (Exception ex)
{
Console.Error.WriteLine("Failed with runtime exception:\n" + ex);
return 1;
}
}
}
}
23 changes: 23 additions & 0 deletions implement/native-tools/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.CommandLine;
using System.Threading.Tasks;

namespace native_tools;

public class Program
{
static async Task<int> Main(string[] args)
{
var rootCommand = new RootCommand("Collection of native tools");

var echoJsonCommand = new Command("echo-json", "Echoes the JSON string to the console.");

echoJsonCommand.SetHandler(() =>
{
EchoJson.EchoJsonLoop();
});

rootCommand.Add(echoJsonCommand);

return await rootCommand.InvokeAsync(args);
}
}
17 changes: 17 additions & 0 deletions implement/native-tools/native-tools.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>native_tools</RootNamespace>
<Nullable>enable</Nullable>
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
</ItemGroup>

</Project>

0 comments on commit 74c0bbc

Please sign in to comment.