diff --git a/pkgs/by-name/cl/clps2c-compiler/deps.nix b/pkgs/by-name/cl/clps2c-compiler/deps.nix new file mode 100644 index 0000000000000..e045ace5300ba --- /dev/null +++ b/pkgs/by-name/cl/clps2c-compiler/deps.nix @@ -0,0 +1,11 @@ +# This file was automatically generated by passthru.fetch-deps. +# Please dont edit it manually, your changes might get overwritten! + +{ fetchNuGet }: +[ + (fetchNuGet { + pname = "CommandLineParser"; + version = "2.9.1"; + hash = "sha256-ApU9y1yX60daSjPk3KYDBeJ7XZByKW8hse9NRZGcjeo="; + }) +] diff --git a/pkgs/by-name/cl/clps2c-compiler/package.nix b/pkgs/by-name/cl/clps2c-compiler/package.nix new file mode 100644 index 0000000000000..a2a46881c37cc --- /dev/null +++ b/pkgs/by-name/cl/clps2c-compiler/package.nix @@ -0,0 +1,75 @@ +{ + keystone, + fetchFromGitHub, + buildDotnetModule, + dotnetCorePackages, + lib, +}: +let + version = "1.0.1"; + pname = "CLPS2C-Compiler"; + owner = "NiV-L-A"; + keystone-rev = "MIPS-0.9.2"; + keystone-sha256 = "sha256-xLkO06ZgnmAavJMP1kjDwXT1hc5eSDXv+4MUkOz6xeo="; + keystone-src = ( + fetchFromGitHub { + name = "keystone"; + inherit owner; + repo = "keystone"; + rev = keystone-rev; + sha256 = keystone-sha256; + } + ); + keystone-override = keystone.overrideAttrs (old: { + src = keystone-src; + }); +in +buildDotnetModule rec { + inherit version pname; + + srcs = [ + (fetchFromGitHub { + name = pname; + inherit owner; + repo = pname; + rev = "CLPS2C-Compiler-${version}"; + sha256 = "sha256-4gLdrIxyw9BFSxF+EXZqTgUf9Kik6oK7eO9HBUzk4QM="; + }) + keystone-src + ]; + + sourceRoot = "."; + + patches = [ + ./patches/dont_trim_leading_newline.patch + ./patches/build_fixes.patch + ./patches/remove_platformtarget.patch + ./patches/use_compiled_keystone.patch + ./patches/set_langversion.patch + ./patches/set_runtimeidentifiers.patch + ./patches/keystone_set_targetframework.patch + ]; + + dotnet-sdk = dotnetCorePackages.sdk_8_0; + dotnet-runtime = dotnetCorePackages.runtime_8_0; + + dotnetFlags = [ + "-p:TargetFramework=net8.0" + ]; + + nugetDeps = ./deps.nix; + + runtimeDeps = [ + keystone-override + ]; + + projectFile = "CLPS2C-Compiler/CLPS2C-Compiler/CLPS2C-Compiler.csproj"; + + meta = { + homepage = "https://github.com/NiV-L-A/CLPS2C-Compiler"; + description = "Compiler for CLPS2C, a domain-specific language built specifically for writing PS2 cheat codes"; + mainProgram = "CLPS2C-Compiler"; + maintainers = [ lib.maintainers.gigahawk ]; + license = lib.licenses.gpl3Only; + }; +} diff --git a/pkgs/by-name/cl/clps2c-compiler/patches/build_fixes.patch b/pkgs/by-name/cl/clps2c-compiler/patches/build_fixes.patch new file mode 100644 index 0000000000000..62c0c96a76ebc --- /dev/null +++ b/pkgs/by-name/cl/clps2c-compiler/patches/build_fixes.patch @@ -0,0 +1,193 @@ +diff --git a/CLPS2C-Compiler/Program.cs b/CLPS2C-Compiler/Program.cs +index 6991896..a086433 100644 +--- a/CLPS2C-Compiler/CLPS2C-Compiler/Program.cs ++++ b/CLPS2C-Compiler/CLPS2C-Compiler/Program.cs +@@ -1166,7 +1166,7 @@ namespace CLPS2C_Compiler + string Value_1 = ""; + string Value_2 = ""; + // Handle a bit differently in case there's a label at the start +- if (command.Type.EndsWith(':')) ++ if (command.Type.EndsWith(":")) + { + OpCode = command.Data[0].ToUpper(); + Register = command.Data[1]; +@@ -1201,7 +1201,7 @@ namespace CLPS2C_Compiler + } + + Output = $"lui {Register},0x{Value_1}; {OpCode} {Register},{Value_2}({Register})"; +- if (command.Type.EndsWith(':')) ++ if (command.Type.EndsWith(":")) + { + Output = $"{command.FullLine.Substring(0, command.FullLine.IndexOf(':'))}: {Output}"; + } +@@ -1589,7 +1589,7 @@ namespace CLPS2C_Compiler + + while (IfIndex != -1) + { +- int ExtraIfCount = commands[IfIndex].FullLine.Split("&&", StringSplitOptions.None).Length - 1; ++ int ExtraIfCount = commands[IfIndex].FullLine.Split(new string[] { "&&" }, StringSplitOptions.None).Length - 1; + for (int i = 0; i < ExtraIfCount; i++) + { + // Add more IF commands +@@ -1807,7 +1807,7 @@ namespace CLPS2C_Compiler + for (int j = 0; j < commands[i].Data.Count; j++) + { + string Target = commands[i].Data[j]; +- if (Target.StartsWith('+') || Target.StartsWith(',')) ++ if (Target.StartsWith("+") || Target.StartsWith(",")) + { + Target = Target.Substring(1).TrimStart(); + } +@@ -1815,14 +1815,14 @@ namespace CLPS2C_Compiler + if (IsVarDeclared(Target, listSets)) + { + List ListValues = GetSetValueFromTarget(Target, commands[i].ID, listSets); +- if (commands[i].Data[j].StartsWith('+') || commands[i].Data[j].StartsWith(',')) ++ if (commands[i].Data[j].StartsWith("+") || commands[i].Data[j].StartsWith(",")) + { + ListValues[0] = commands[i].Data[j][0] + ListValues[0]; + } + + for (int k = 1; k < ListValues.Count; k++) + { +- if (ListValues[k].StartsWith('+') || ListValues[k].StartsWith(',')) ++ if (ListValues[k].StartsWith("+") || ListValues[k].StartsWith(",")) + { + ListValues[k] = ListValues[k][0] + ListValues[k].Substring(1).TrimStart(); + } +@@ -1834,7 +1834,7 @@ namespace CLPS2C_Compiler + continue; + } + +- if (commands[i].Data[j].StartsWith('+') || commands[i].Data[j].StartsWith(',')) ++ if (commands[i].Data[j].StartsWith("+") || commands[i].Data[j].StartsWith(",")) + { + commands[i].Data[j] = commands[i].Data[j][0] + Target; + } +@@ -1912,7 +1912,7 @@ namespace CLPS2C_Compiler + + for (i = i + 1; i < command.Data.Count; i++) + { +- if (!command.Data[i].StartsWith('+')) ++ if (!command.Data[i].StartsWith("+")) + { + break; + } +@@ -1940,12 +1940,12 @@ namespace CLPS2C_Compiler + + for (i = i + 1; i < command.Data.Count; i++) + { +- if (command.Data[i].StartsWith(',')) ++ if (command.Data[i].StartsWith(",")) + { + ListOffs.Add(TmpAddress.ToString("X8")); + TmpAddress = 0; + } +- else if (!command.Data[i].StartsWith('+')) ++ else if (!command.Data[i].StartsWith("+")) + { + ListOffs.Add(TmpAddress.ToString("X8")); + TmpAddress = 0; +@@ -1980,7 +1980,7 @@ namespace CLPS2C_Compiler + + for (i = i + 1; i < command.Data.Count; i++) + { +- if (!command.Data[i].StartsWith('+')) ++ if (!command.Data[i].StartsWith("+")) + { + break; + } +@@ -2008,7 +2008,7 @@ namespace CLPS2C_Compiler + + for (i = i + 1; i < command.Data.Count; i++) + { +- if (!command.Data[i].StartsWith('+')) ++ if (!command.Data[i].StartsWith("+")) + { + break; + } +@@ -2040,7 +2040,7 @@ namespace CLPS2C_Compiler + { + string Value = ""; + uint Sum = 0; +- if (command.Data[i].StartsWith('"')) ++ if (command.Data[i].StartsWith("\"")) + { + // string + Value = command.Data[i]; +@@ -2059,7 +2059,7 @@ namespace CLPS2C_Compiler + for (i = i + 1; i < command.Data.Count; i++) + { + string Element = command.Data[i]; +- if (!Element.StartsWith('+') || Element == "+") ++ if (!Element.StartsWith("+") || Element == "+") + { + // without +, or just '+' + SetError(ERROR.WRONG_SYNTAX, command); +@@ -2072,7 +2072,7 @@ namespace CLPS2C_Compiler + // string + if (Sum > 0) + { +- if (Value.EndsWith('"')) ++ if (Value.EndsWith("\"")) + { + Value = Value.TrimEnd('"') + Sum.ToString() + '"'; + } +@@ -2089,7 +2089,7 @@ namespace CLPS2C_Compiler + return ""; + } + string Tmp = GetSubstringInQuotes(Element, false); +- if (Value.EndsWith('"')) ++ if (Value.EndsWith("\"")) + { + Value = Value.TrimEnd('"') + Tmp + '"'; + } +@@ -2112,7 +2112,7 @@ namespace CLPS2C_Compiler + + if (Sum > 0) + { +- if (Value.EndsWith('"')) ++ if (Value.EndsWith("\"")) + { + Value = Value.TrimEnd('"') + Sum.ToString() + '"'; + } +diff --git a/CLPS2C-Compiler/Util.cs b/CLPS2C-Compiler/Util.cs +index 4560c73..7f82ae6 100644 +--- a/CLPS2C-Compiler/CLPS2C-Compiler/Util.cs ++++ b/CLPS2C-Compiler/CLPS2C-Compiler/Util.cs +@@ -48,7 +48,7 @@ namespace CLPS2C_Compiler + // ([^ \t\n\r\f\v(+,]+) - Any other word. This is \S, and '(', '+', ',' + MatchCollection Matches = Regex.Matches(line, @"(\(.*\))|(""(?:\\.|[^""])*""?)|(\+\s*((""(?:\\.|[^""])*""?)|([^+""]+?))?(?=\+|$| |,))|(,(""?)([^,""]+?)\8(?=,|$| |\+))|([^ \t\n\r\f\v(+,]+)"); + Type = Matches[0].Value.ToUpper(); +- Data = Matches.Skip(1).Take(Matches.Count - 1).Select(item => item.Value).ToList(); // Data has every word except first ++ Data = Matches.Cast().Skip(1).Take(Matches.Count - 1).Select(item => item.Value).ToList(); // Data has every word except first + } + + public void AppendToTraceback(string file, string fullLine, int lineIdx) +@@ -165,7 +165,7 @@ namespace CLPS2C_Compiler + else + { + // It's a comment, count new lines +- int newLinesCount = match.Value.Split(Program._newLine).Length - 1; ++ int newLinesCount = match.Value.Split(new string[] { Program._newLine }, StringSplitOptions.None).Length - 1; + return string.Concat(Enumerable.Repeat(Program._newLine, newLinesCount)); + } + }); +@@ -486,7 +486,7 @@ namespace CLPS2C_Compiler + for (int i = 0; i < Output.Count; i++) + { + string Element = Output[i]; +- if (Element.StartsWith('+')) ++ if (Element.StartsWith("+")) + { + Element = Element.Substring(1).TrimStart(); + } +@@ -496,7 +496,7 @@ namespace CLPS2C_Compiler + List RecursiveValues = GetSetValueFromTarget(Element, SetID, listSets); + if (RecursiveValues.Count != 0) + { +- if (Output[i].StartsWith('+')) ++ if (Output[i].StartsWith("+")) + { + RecursiveValues[0] = "+" + RecursiveValues[0]; + } diff --git a/pkgs/by-name/cl/clps2c-compiler/patches/dont_trim_leading_newline.patch b/pkgs/by-name/cl/clps2c-compiler/patches/dont_trim_leading_newline.patch new file mode 100644 index 0000000000000..bce6826db7fd0 --- /dev/null +++ b/pkgs/by-name/cl/clps2c-compiler/patches/dont_trim_leading_newline.patch @@ -0,0 +1,15 @@ +diff --git a/CLPS2C-Compiler/Program.cs b/CLPS2C-Compiler/Program.cs +index 6991896..fe8cd5f 100644 +--- a/CLPS2C-Compiler/CLPS2C-Compiler/Program.cs ++++ b/CLPS2C-Compiler/CLPS2C-Compiler/Program.cs +@@ -90,10 +90,6 @@ namespace CLPS2C_Compiler + } + else if (OutputLines.Count != 0) + { +- if (OutputLines[0].StartsWith(_newLine)) +- { +- OutputLines[0] = OutputLines[0].Substring(2); +- } + Output += string.Join("", OutputLines); + + // Convert to PNACH Format diff --git a/pkgs/by-name/cl/clps2c-compiler/patches/keystone_set_targetframework.patch b/pkgs/by-name/cl/clps2c-compiler/patches/keystone_set_targetframework.patch new file mode 100644 index 0000000000000..150da411af270 --- /dev/null +++ b/pkgs/by-name/cl/clps2c-compiler/patches/keystone_set_targetframework.patch @@ -0,0 +1,13 @@ +diff --git a/bindings/csharp/Keystone.Net/Keystone.Net.csproj b/bindings/csharp/Keystone.Net/Keystone.Net.csproj +index 04801b4..4c6fe15 100644 +--- a/keystone/bindings/csharp/Keystone.Net/Keystone.Net.csproj ++++ b/keystone/bindings/csharp/Keystone.Net/Keystone.Net.csproj +@@ -1,7 +1,7 @@ + + + +- netstandard2.0 ++ net8.0 + Keystone + + 1.1.0 diff --git a/pkgs/by-name/cl/clps2c-compiler/patches/remove_platformtarget.patch b/pkgs/by-name/cl/clps2c-compiler/patches/remove_platformtarget.patch new file mode 100644 index 0000000000000..82b8708231bdb --- /dev/null +++ b/pkgs/by-name/cl/clps2c-compiler/patches/remove_platformtarget.patch @@ -0,0 +1,12 @@ +diff --git a/CLPS2C-Compiler/CLPS2C-Compiler.csproj b/CLPS2C-Compiler/CLPS2C-Compiler.csproj +index 867533e..80f7923 100644 +--- a/CLPS2C-Compiler/CLPS2C-Compiler/CLPS2C-Compiler.csproj ++++ b/CLPS2C-Compiler/CLPS2C-Compiler/CLPS2C-Compiler.csproj +@@ -6,7 +6,6 @@ + CLPS2C_Compiler + enable + enable +- x86 + 256x256.ico + 1.0.1 + diff --git a/pkgs/by-name/cl/clps2c-compiler/patches/set_langversion.patch b/pkgs/by-name/cl/clps2c-compiler/patches/set_langversion.patch new file mode 100644 index 0000000000000..3814118d11b72 --- /dev/null +++ b/pkgs/by-name/cl/clps2c-compiler/patches/set_langversion.patch @@ -0,0 +1,12 @@ +diff --git a/CLPS2C-Compiler/CLPS2C-Compiler.csproj b/CLPS2C-Compiler/CLPS2C-Compiler.csproj +index 867533e..34b30a4 100644 +--- a/CLPS2C-Compiler/CLPS2C-Compiler/CLPS2C-Compiler.csproj ++++ b/CLPS2C-Compiler/CLPS2C-Compiler/CLPS2C-Compiler.csproj +@@ -5,6 +5,7 @@ + net8.0 + CLPS2C_Compiler + enable ++ 10.0 + enable + x86 + 256x256.ico diff --git a/pkgs/by-name/cl/clps2c-compiler/patches/set_runtimeidentifiers.patch b/pkgs/by-name/cl/clps2c-compiler/patches/set_runtimeidentifiers.patch new file mode 100644 index 0000000000000..8d1bfeec616b9 --- /dev/null +++ b/pkgs/by-name/cl/clps2c-compiler/patches/set_runtimeidentifiers.patch @@ -0,0 +1,12 @@ +diff --git a/CLPS2C-Compiler/CLPS2C-Compiler.csproj b/CLPS2C-Compiler/CLPS2C-Compiler.csproj +index 867533e..ab44095 100644 +--- a/CLPS2C-Compiler/CLPS2C-Compiler/CLPS2C-Compiler.csproj ++++ b/CLPS2C-Compiler/CLPS2C-Compiler/CLPS2C-Compiler.csproj +@@ -3,6 +3,7 @@ + + Exe + net8.0 ++ win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64 + CLPS2C_Compiler + enable + enable diff --git a/pkgs/by-name/cl/clps2c-compiler/patches/use_compiled_keystone.patch b/pkgs/by-name/cl/clps2c-compiler/patches/use_compiled_keystone.patch new file mode 100644 index 0000000000000..809281993cd5d --- /dev/null +++ b/pkgs/by-name/cl/clps2c-compiler/patches/use_compiled_keystone.patch @@ -0,0 +1,20 @@ +diff --git a/CLPS2C-Compiler/CLPS2C-Compiler.csproj b/CLPS2C-Compiler/CLPS2C-Compiler.csproj +index 867533e..17a3aca 100644 +--- a/CLPS2C-Compiler/CLPS2C-Compiler/CLPS2C-Compiler.csproj ++++ b/CLPS2C-Compiler/CLPS2C-Compiler/CLPS2C-Compiler.csproj +@@ -28,16 +29,7 @@ + + + +- +- Keystone.Net.dll +- True +- +- +- +- +- +- PreserveNewest +- ++ +