Skip to content

Commit

Permalink
Added varies of runtime configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
kekyo committed Jan 20, 2024
1 parent 11886e2 commit 31b47b3
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 15 deletions.
27 changes: 26 additions & 1 deletion chibias.core/Assembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -356,7 +370,7 @@ private bool Run(
},
});

if (options.ProduceRuntimeConfigurationIfRequired &&
if (options.RuntimeConfiguration != RuntimeConfigurationOptions.Omit &&
produceExecutable &&
targetFramework.Identifier == TargetFrameworkIdentifiers.NETCoreApp)
{
Expand All @@ -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));
Expand Down
38 changes: 30 additions & 8 deletions chibias.core/AssemblerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>();
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<string>();
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;
}
2 changes: 1 addition & 1 deletion chibias.core/Internal/runtimeconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"runtimeOptions": {
"tfm": "{tfm}",
"framework": {
{rollForward}"framework": {
"name": "Microsoft.NETCore.App",
"version": "{tfv}"
}
Expand Down
75 changes: 70 additions & 5 deletions chibias/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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}");
}
Expand All @@ -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 <version> Apply assembly version (defaulted: 1.0.0.0)");
tw.WriteLine($" -f <tfm> Target framework moniker (defaulted: {ThisAssembly.AssemblyMetadata.TargetFrameworkMoniker})");
tw.WriteLine(" -w <arch> Target Windows architecture [AnyCPU|Preferred32Bit|X86|X64|IA64|ARM|ARMv7|ARM64]");
Expand Down

0 comments on commit 31b47b3

Please sign in to comment.