Nuke.Cola
Loading...
Searching...
No Matches
XMakeTasks.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Runtime.CompilerServices;
5using System.Runtime.InteropServices;
6using System.Threading.Tasks;
7using Microsoft.CodeAnalysis;
8using Nuke.Common;
9using Nuke.Common.IO;
10using Nuke.Common.Tooling;
11using Nuke.Common.Tools.PowerShell;
12using Serilog;
13using static Nuke.Cola.Cola;
14
15namespace Nuke.Cola.Tooling;
16
17/// <summary>
18/// XMake is a versatile build tool for many languages https://xmake.io/#/?id=supported-languages
19/// scriptable in Lua
20/// </summary>
21public static class XMakeTasks
22{
23 public const string LatestVersion = "3.0.4";
24 internal static string GetBundleAppName(string version = LatestVersion)
25 => (plat: EnvironmentInfo.Platform, arch: RuntimeInformation.OSArchitecture) switch
26 {
27 (PlatformFamily.Windows, Architecture.X64) => $"xmake-bundle-v{version}.win64.exe",
28 (PlatformFamily.Windows, Architecture.X86) => $"xmake-bundle-v{version}.win32.exe",
29 (PlatformFamily.Windows, Architecture.Arm64) => $"xmake-bundle-v{version}.arm64.exe",
30 (PlatformFamily.Linux, Architecture.X64) => $"xmake-bundle-v{version}.linux.x86_64",
31 (PlatformFamily.OSX, Architecture.Arm64) => $"xmake-bundle-v{version}.macos.arm64",
32 (PlatformFamily.OSX, Architecture.X64) => $"xmake-bundle-v{version}.macos.x86_64",
33 var other => throw new Exception($"Trying to use XMake on an unsupported platform: {other.plat} {other.arch}")
34 };
35
36 /// <summary>
37 /// Get XMake or an error if downloading it has failed.
38 /// </summary>
39 public static ValueOrError<Tool> TryGetXMake(string version = LatestVersion) => ErrorHandling.TryGet(() =>
40 {
41 var bundleAppName = GetBundleAppName(version);
42 var xmakePath = NukeBuild.TemporaryDirectory / bundleAppName;
43 if (!xmakePath.FileExists())
44 {
45 Log.Information("Downloading XMake {0}", bundleAppName);
46 HttpTasks.HttpDownloadFile(
47 $"https://github.com/xmake-io/xmake/releases/download/v{LatestVersion}/{bundleAppName}",
48 xmakePath
49 );
50 }
51 return ToolResolver.GetTool(xmakePath);
52 });
53
54 public static ValueOrError<Tool> EnsureXMake => TryGetXMake();
55
56 /// <summary>
57 /// Get XMake. It throws an exception if setup has failed.
58 /// </summary>
59 public static Tool XMake => EnsureXMake.Get();
60}
XMake is a versatile build tool for many languages https://xmake.io/#/?id=supported-languages scripta...
Definition XMakeTasks.cs:22
static Tool XMake
Get XMake. It throws an exception if setup has failed.
Definition XMakeTasks.cs:59
static ValueOrError< Tool > TryGetXMake(string version=LatestVersion)
Get XMake or an error if downloading it has failed.