From 3bef1b4ddac11c83ce8b34afe5acbdab63f4683b Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Sat, 21 Feb 2026 17:14:42 +0000 Subject: [PATCH] native build? --- .github/workflows/cli-native.yml | 67 ++++++++++++++++++++++++++++++++ build/Program.cs | 48 +++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 .github/workflows/cli-native.yml diff --git a/.github/workflows/cli-native.yml b/.github/workflows/cli-native.yml new file mode 100644 index 00000000..9809413e --- /dev/null +++ b/.github/workflows/cli-native.yml @@ -0,0 +1,67 @@ +name: CLI Native Build + +on: + push: + branches: + - "master" + - "release" + paths: + - "src/SharpCompress.Cli/**" + - "src/SharpCompress/**" + - "build/**" + - "tests/SharpCompress.Test/Cli/**" + - "tests/SharpCompress.Test/SharpCompress.Test.csproj" + - "Directory.Build.props" + - "Directory.Packages.props" + - "global.json" + - ".github/workflows/cli-native.yml" + pull_request: + branches: + - "master" + - "release" + paths: + - "src/SharpCompress.Cli/**" + - "src/SharpCompress/**" + - "build/**" + - "tests/SharpCompress.Test/Cli/**" + - "tests/SharpCompress.Test/SharpCompress.Test.csproj" + - "Directory.Build.props" + - "Directory.Packages.props" + - "global.json" + - ".github/workflows/cli-native.yml" + workflow_dispatch: + +permissions: + contents: read + +jobs: + native-aot: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + rid: linux-x64 + - os: macos-14 + rid: osx-arm64 + - os: windows-latest + rid: win-x64 + + steps: + - uses: actions/checkout@v6 + + - uses: actions/setup-dotnet@v5 + with: + dotnet-version: 10.0.x + + - name: Build Native AOT CLI + run: dotnet run --project build/build.csproj -- cli-native + env: + CLI_RID: ${{ matrix.rid }} + + - name: Upload CLI Native Artifact + uses: actions/upload-artifact@v6 + with: + name: sharpcompress-cli-${{ matrix.rid }} + path: src/SharpCompress.Cli/bin/Release/net10.0/${{ matrix.rid }}/publish/ diff --git a/build/Program.cs b/build/Program.cs index 1c36e0a9..1cf2dd2e 100644 --- a/build/Program.cs +++ b/build/Program.cs @@ -23,6 +23,7 @@ const string PushToNuGet = "push-to-nuget"; const string DisplayBenchmarkResults = "display-benchmark-results"; const string CompareBenchmarkResults = "compare-benchmark-results"; const string GenerateBaseline = "generate-baseline"; +const string CliNative = "cli-native"; Target( Clean, @@ -466,6 +467,40 @@ Target( } ); +Target( + CliNative, + () => + { + var rid = GetRequiredEnvironmentVariable("CLI_RID"); + var configuration = Environment.GetEnvironmentVariable("CLI_CONFIGURATION") ?? "Release"; + var framework = Environment.GetEnvironmentVariable("CLI_FRAMEWORK") ?? "net10.0"; + const string project = "src/SharpCompress.Cli/SharpCompress.Cli.csproj"; + + Run("dotnet", $"restore {project} -r {rid}"); + Run( + "dotnet", + $"publish {project} -c {configuration} -f {framework} -r {rid} -p:PublishAot=true --no-restore" + ); + + var binaryName = rid.StartsWith("win-", StringComparison.OrdinalIgnoreCase) + ? "SharpCompress.Cli.exe" + : "SharpCompress.Cli"; + var binaryPath = Path.Combine( + "src", + "SharpCompress.Cli", + "bin", + configuration, + framework, + rid, + "publish", + binaryName + ); + + Console.WriteLine($"Smoke testing native binary: {binaryPath}"); + Run(binaryPath, "formats --format json"); + } +); + Target("default", [Publish], () => Console.WriteLine("Done!")); await RunTargetsAndExitAsync(args); @@ -702,6 +737,19 @@ static double CalculateChange(double baseline, double current) return ((current - baseline) / baseline) * 100; } +static string GetRequiredEnvironmentVariable(string variableName) +{ + var value = Environment.GetEnvironmentVariable(variableName); + if (string.IsNullOrWhiteSpace(value)) + { + throw new InvalidOperationException( + $"Environment variable '{variableName}' must be set for this target." + ); + } + + return value; +} + record BenchmarkMetric { public string Method { get; init; } = "";