diff --git a/chibias.core/Assembler.cs b/chibias.core/Assembler.cs index 1a78d85..261ba33 100644 --- a/chibias.core/Assembler.cs +++ b/chibias.core/Assembler.cs @@ -210,6 +210,20 @@ private void AssembleFromSource( this.logger.Trace($"Stat: {sourcePathDebuggerHint}: Parse: Total={parseTotal}, Average={parseAverage}, Count={parseLap.Count}"); } + private static string GetRollForwardValue(RuntimeConfigurationOptions option) => + option switch + { + RuntimeConfigurationOptions.ProduceCoreCLRMajorRollForward => "major", + RuntimeConfigurationOptions.ProduceCoreCLRMinorRollForward => "minor", + RuntimeConfigurationOptions.ProduceCoreCLRFeatureRollForward => "feature", + RuntimeConfigurationOptions.ProduceCoreCLRPatchRollForward => "patch", + RuntimeConfigurationOptions.ProduceCoreCLRLatestMajorRollForward => "latestMajor", + RuntimeConfigurationOptions.ProduceCoreCLRLatestMinorRollForward => "latestMinor", + RuntimeConfigurationOptions.ProduceCoreCLRLatestFeatureRollForward => "latestFeature", + RuntimeConfigurationOptions.ProduceCoreCLRDisableRollForward => "disable", + _ => throw new ArgumentException(), + }; + private bool Run( string outputAssemblyPath, AssemblerOptions options, @@ -356,7 +370,7 @@ private bool Run( }, }); - if (options.ProduceRuntimeConfigurationIfRequired && + if (options.RuntimeConfiguration != RuntimeConfigurationOptions.Omit && produceExecutable && targetFramework.Identifier == TargetFrameworkIdentifiers.NETCoreApp) { @@ -371,6 +385,17 @@ private bool Run( var sb = new StringBuilder(runtimeConfigJsonTemplate); sb.Replace("{tfm}", options.TargetFrameworkMoniker); + if (options.RuntimeConfiguration == + RuntimeConfigurationOptions.ProduceCoreCLR) + { + sb.Replace("{rollForward}", ""); + } + else + { + sb.Replace( + "{rollForward}", + $"\"rollForward\": \"{GetRollForwardValue(options.RuntimeConfiguration)}\",{Environment.NewLine} "); + } if (targetFramework.Version.Build >= 0) { sb.Replace("{tfv}", targetFramework.Version.ToString(3)); diff --git a/chibias.core/AssemblerOptions.cs b/chibias.core/AssemblerOptions.cs index 4a27b75..e2b724c 100644 --- a/chibias.core/AssemblerOptions.cs +++ b/chibias.core/AssemblerOptions.cs @@ -49,14 +49,36 @@ public enum AssembleOptions DisableJITOptimization = 0x04, } +public enum RuntimeConfigurationOptions +{ + Omit, + ProduceCoreCLR, + ProduceCoreCLRMajorRollForward, + ProduceCoreCLRMinorRollForward, + ProduceCoreCLRFeatureRollForward, + ProduceCoreCLRPatchRollForward, + ProduceCoreCLRLatestMajorRollForward, + ProduceCoreCLRLatestMinorRollForward, + ProduceCoreCLRLatestFeatureRollForward, + ProduceCoreCLRLatestPatchRollForward, + ProduceCoreCLRDisableRollForward, +} + public sealed class AssemblerOptions { - public string[] ReferenceAssemblyPaths = Utilities.Empty(); - public AssemblyTypes AssemblyType = AssemblyTypes.Exe; - public TargetWindowsArchitectures TargetWindowsArchitecture = TargetWindowsArchitectures.AnyCPU; - public DebugSymbolTypes DebugSymbolType = DebugSymbolTypes.Embedded; - public AssembleOptions Options = AssembleOptions.Deterministic | AssembleOptions.DisableJITOptimization; - public Version Version = new Version(1, 0, 0, 0); - public string TargetFrameworkMoniker = ThisAssembly.AssemblyMetadata.TargetFrameworkMoniker; - public bool ProduceRuntimeConfigurationIfRequired = true; + public string[] ReferenceAssemblyPaths = + Utilities.Empty(); + public AssemblyTypes AssemblyType = + AssemblyTypes.Exe; + public TargetWindowsArchitectures TargetWindowsArchitecture = + TargetWindowsArchitectures.AnyCPU; + public DebugSymbolTypes DebugSymbolType = + DebugSymbolTypes.Embedded; + public AssembleOptions Options = + AssembleOptions.Deterministic | AssembleOptions.DisableJITOptimization; + public Version Version = new(1, 0, 0, 0); + public string TargetFrameworkMoniker = + ThisAssembly.AssemblyMetadata.TargetFrameworkMoniker; + public RuntimeConfigurationOptions RuntimeConfiguration = + RuntimeConfigurationOptions.ProduceCoreCLRMajorRollForward; } diff --git a/chibias.core/Internal/runtimeconfig.json b/chibias.core/Internal/runtimeconfig.json index acf414f..cd83eeb 100644 --- a/chibias.core/Internal/runtimeconfig.json +++ b/chibias.core/Internal/runtimeconfig.json @@ -1,7 +1,7 @@ { "runtimeOptions": { "tfm": "{tfm}", - "framework": { + {rollForward}"framework": { "name": "Microsoft.NETCore.App", "version": "{tfv}" } diff --git a/chibias/Options.cs b/chibias/Options.cs index c4b0cb0..4596c82 100644 --- a/chibias/Options.cs +++ b/chibias/Options.cs @@ -142,9 +142,64 @@ public static Options Parse(string[] args) continue; } break; - case 's': - options.AssemblerOptions.ProduceRuntimeConfigurationIfRequired = false; - continue; + case 'p': + if (arg.Length == 3) + { + switch (arg[2]) + { + case '0': + options.AssemblerOptions.RuntimeConfiguration = + RuntimeConfigurationOptions.ProduceCoreCLRMajorRollForward; + continue; + case '1': + options.AssemblerOptions.RuntimeConfiguration = + RuntimeConfigurationOptions.ProduceCoreCLRMinorRollForward; + continue; + case '2': + options.AssemblerOptions.RuntimeConfiguration = + RuntimeConfigurationOptions.ProduceCoreCLRFeatureRollForward; + continue; + case '3': + options.AssemblerOptions.RuntimeConfiguration = + RuntimeConfigurationOptions.ProduceCoreCLRPatchRollForward; + continue; + case '4': + options.AssemblerOptions.RuntimeConfiguration = + RuntimeConfigurationOptions.ProduceCoreCLRLatestMajorRollForward; + continue; + case '5': + options.AssemblerOptions.RuntimeConfiguration = + RuntimeConfigurationOptions.ProduceCoreCLRLatestMinorRollForward; + continue; + case '6': + options.AssemblerOptions.RuntimeConfiguration = + RuntimeConfigurationOptions.ProduceCoreCLRLatestFeatureRollForward; + continue; + case '7': + options.AssemblerOptions.RuntimeConfiguration = + RuntimeConfigurationOptions.ProduceCoreCLRLatestPatchRollForward; + continue; + case '8': + options.AssemblerOptions.RuntimeConfiguration = + RuntimeConfigurationOptions.ProduceCoreCLRDisableRollForward; + continue; + case 'n': + options.AssemblerOptions.RuntimeConfiguration = + RuntimeConfigurationOptions.ProduceCoreCLR; + continue; + case 'o': + options.AssemblerOptions.RuntimeConfiguration = + RuntimeConfigurationOptions.Omit; + continue; + } + } + else if (arg.Length == 2) + { + options.AssemblerOptions.RuntimeConfiguration = + RuntimeConfigurationOptions.ProduceCoreCLRMajorRollForward; + continue; + } + break; case 'v': if (arg.Length >= 2 && Version.TryParse(args[index + 1], out var version)) @@ -277,7 +332,7 @@ public void Write(ILogger logger) logger.Information($"TargetWindowsArchitecture={this.AssemblerOptions.TargetWindowsArchitecture}"); logger.Information($"DebugSymbolType={this.AssemblerOptions.DebugSymbolType}"); logger.Information($"Options={this.AssemblerOptions.Options}"); - logger.Information($"ProduceRuntimeConfigurationIfRequired={this.AssemblerOptions.ProduceRuntimeConfigurationIfRequired}"); + logger.Information($"RuntimeConfiguration={this.AssemblerOptions.RuntimeConfiguration}"); logger.Information($"Version={this.AssemblerOptions.Version}"); logger.Information($"TargetFrameworkMoniker={this.AssemblerOptions.TargetFrameworkMoniker}"); } @@ -303,7 +358,17 @@ public static void WriteUsage(TextWriter tw) tw.WriteLine(" -g0 Omit debug symbol file"); tw.WriteLine(" -O, -O1 Apply optimization"); tw.WriteLine(" -O0 Disable optimization (defaulted)"); - tw.WriteLine(" -s Suppress runtime configuration file"); + tw.WriteLine(" -p, -p0 Produce CoreCLR runtime configuration (rollForward: major) (defaulted)"); + tw.WriteLine(" -p1 Produce CoreCLR runtime configuration (rollForward: minor)"); + tw.WriteLine(" -p2 Produce CoreCLR runtime configuration (rollForward: feature)"); + tw.WriteLine(" -p3 Produce CoreCLR runtime configuration (rollForward: patch)"); + tw.WriteLine(" -p4 Produce CoreCLR runtime configuration (rollForward: latest major)"); + tw.WriteLine(" -p5 Produce CoreCLR runtime configuration (rollForward: latest minor)"); + tw.WriteLine(" -p6 Produce CoreCLR runtime configuration (rollForward: latest feature)"); + tw.WriteLine(" -p7 Produce CoreCLR runtime configuration (rollForward: latest patch)"); + tw.WriteLine(" -p8 Produce CoreCLR runtime configuration (rollForward: disable)"); + tw.WriteLine(" -pn Produce CoreCLR runtime configuration"); + tw.WriteLine(" -po Omit CoreCLR runtime configuration"); tw.WriteLine(" -v Apply assembly version (defaulted: 1.0.0.0)"); tw.WriteLine($" -f Target framework moniker (defaulted: {ThisAssembly.AssemblyMetadata.TargetFrameworkMoniker})"); tw.WriteLine(" -w Target Windows architecture [AnyCPU|Preferred32Bit|X86|X64|IA64|ARM|ARMv7|ARM64]");