Skip to content

Commit eb37008

Browse files
committed
fix: enforce correct order of arguments to compiler and linker
1 parent 3992b09 commit eb37008

26 files changed

+151
-66
lines changed

.github/workflows/CI.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
arch: x86
3030
os: windows-latest
3131

32-
- lua-version: 5.4.7
32+
- lua-version: 5.4.8
3333
arch: x86
3434
os: windows-latest
3535

@@ -45,7 +45,7 @@ jobs:
4545
arch: x64
4646
os: windows-latest
4747

48-
- lua-version: 5.4.7
48+
- lua-version: 5.4.8
4949
arch: x64
5050
os: windows-latest
5151

@@ -61,7 +61,7 @@ jobs:
6161
arch: arm64
6262
os: windows-11-arm
6363

64-
- lua-version: 5.4.7
64+
- lua-version: 5.4.8
6565
arch: arm64
6666
os: windows-11-arm
6767

@@ -79,7 +79,7 @@ jobs:
7979
- 5.1.5
8080
- 5.2.4
8181
- 5.3.6
82-
- 5.4.7
82+
- 5.4.8
8383
gtk-major-version:
8484
- 3
8585
- 4

.github/workflows/lfs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414
type: string
1515

1616
env:
17-
LUAROCKS_VERSION: 3.11.1
17+
LUAROCKS_VERSION: 3.12.2
1818

1919
jobs:
2020
build:

LuaInstaller.Console/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,12 @@ source code matching the architecture (x86, x64 or ARM64)
135135
136136
LuaInstaller.Console.exe install
137137
138-
2) Installs Lua 5.4.7 in the current directory,
138+
2) Installs Lua 5.4.8 in the current directory,
139139
using the latest versions of Visual Studio and
140140
Windows SDK, building the source code for x64
141141
platforms:
142142
143-
LuaInstaller.Console.exe install version=5.4.7 arch=x64
143+
LuaInstaller.Console.exe install version=5.4.8 arch=x64
144144
145145
3) Installs Lua 5.1.5 in the folder
146146
'C:\Program Files (x86)\Lua',
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
1-
namespace LuaInstaller.Core
1+
using System;
2+
3+
namespace LuaInstaller.Core
24
{
35
/// <summary>
46
/// Represents an option for a
57
/// given compiler.
68
/// </summary>
7-
public abstract class CompilerOption
9+
public abstract class CompilerOption : IComparable<CompilerOption>
810
{
11+
public const int SortOrderCFLAGS = 0;
12+
public const int SortOrderPREPROCESSORMACRO = 1;
13+
public const int SortOrderINCLUDEDIR = 2;
14+
public const int SortOrderSOURCEFILE = 3;
15+
16+
public abstract int CommandLineSortOrder { get; }
17+
18+
public int CompareTo(CompilerOption other)
19+
{
20+
return ((other == null) ? 1 : (CommandLineSortOrder - other.CommandLineSortOrder));
21+
}
22+
923
public override abstract string ToString();
1024
}
1125
}

LuaInstaller.Core/ILinker.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public interface ILinker
66
string BuildDirectory { get; set; }
77
void AddLibPath(string path);
88
void AddInputFile(string path);
9+
void AddLibInputFile(string path);
910
void AddLinkerOption(LinkerOption option);
1011

1112
int Execute();

LuaInstaller.Core/InstallationManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ private void BuildDll(string executionDir, string srcDir, string outputFile, Vis
194194
}
195195

196196
DirectoryInfo srcDirInfo = new DirectoryInfo(srcDir);
197-
foreach (string srcFile in srcDirInfo.EnumerateFiles("*.c").Where(f => f.Name != "luac.c" && f.Name != "lua.c").Select(f => f.FullName))
197+
foreach (string srcFile in srcDirInfo.EnumerateFiles("l*.c").Where(f => f.Name != "luac.c" && f.Name != "lua.c").Select(f => f.FullName))
198198
{
199199
_compiler.AddSourceFile(srcFile);
200200
}

LuaInstaller.Core/LinkerOption.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
1-
namespace LuaInstaller.Core
1+
using System;
2+
3+
namespace LuaInstaller.Core
24
{
35
/// <summary>
46
/// Represents an option for a
57
/// given linker.
68
/// </summary>
7-
public abstract class LinkerOption
9+
public abstract class LinkerOption : IComparable<LinkerOption>
810
{
11+
public const int SortOrderLDFLAGS = 0;
12+
public const int SortOrderLIBDIR = 1;
13+
public const int SortOrderOUTPUTFILE = 2;
14+
public const int SortOrderOBJECTFILE = 3;
15+
public const int SortOrderLIBFILE = 4;
16+
public const int SortOrderDEPENDENTLIB = 5;
17+
18+
public abstract int CommandLineSortOrder { get; }
19+
20+
public int CompareTo(LinkerOption other)
21+
{
22+
return ((other == null) ? 1 : (CommandLineSortOrder - other.CommandLineSortOrder));
23+
}
24+
925
public override abstract string ToString();
1026
}
1127
}

LuaInstaller.Core/LuaInstaller.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
</PropertyGroup>
2323

2424
<ItemGroup>
25-
<PackageReference Include="Microsoft.VisualStudio.Setup.Configuration.Interop" Version="3.11.2177" />
25+
<PackageReference Include="Microsoft.VisualStudio.Setup.Configuration.Interop" Version="3.14.2075" />
2626
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
2727
<PackageReference Include="SharpZipLib" Version="1.4.2" />
2828
</ItemGroup>

LuaInstaller.Core/VisualStudioCompileOnlyCompilerOption.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
/// </summary>
66
public sealed class VisualStudioCompileOnlyCompilerOption : CompilerOption
77
{
8+
public override int CommandLineSortOrder { get { return CompilerOption.SortOrderCFLAGS; } }
89
public override string ToString()
910
{
1011
return "/c";

LuaInstaller.Core/VisualStudioCompiler.cs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
using System.Collections.Generic;
33
using System.Diagnostics;
44
using System.Linq;
5+
using System.Text;
56

67
namespace LuaInstaller.Core
78
{
89
public sealed class VisualStudioCompiler : ICompiler
910
{
1011
private string _buildDirectory;
1112
private readonly string _path;
12-
private readonly ICollection<CompilerOption> _options;
13-
private readonly ICollection<CompilerOption> _sourceFiles;
13+
private readonly IDictionary<int, Queue<CompilerOption>> _options;
1414

1515
public VisualStudioCompiler(string path)
1616
{
@@ -20,8 +20,7 @@ public VisualStudioCompiler(string path)
2020
}
2121

2222
_path = path;
23-
_options = new List<CompilerOption>();
24-
_sourceFiles = new List<CompilerOption>();
23+
_options = new Dictionary<int, Queue<CompilerOption>>();
2524
}
2625

2726
public string BuildDirectory
@@ -78,15 +77,13 @@ public void AddCompilerOption(CompilerOption option)
7877
{
7978
throw new ArgumentNullException();
8079
}
81-
82-
if (option is VisualStudioSourceFileCompilerOption)
83-
{
84-
_sourceFiles.Add(option);
85-
}
86-
else
80+
Queue<CompilerOption> queue;
81+
if (!_options.TryGetValue(option.CommandLineSortOrder, out queue))
8782
{
88-
_options.Add(option);
83+
queue = new Queue<CompilerOption>();
84+
_options.Add(option.CommandLineSortOrder, queue);
8985
}
86+
queue.Enqueue(option);
9087
}
9188

9289
private static string FormatCompilerOption(CompilerOption option)
@@ -98,11 +95,22 @@ public int Execute()
9895
{
9996
int result = 1;
10097

101-
string arguments = string.Format(
102-
"{0} {1}",
103-
string.Join(" ", _options.Select(FormatCompilerOption).ToArray()),
104-
string.Join(" ", _sourceFiles.Select(FormatCompilerOption).ToArray())
105-
);
98+
int key;
99+
ICollection<int> keys = _options.Keys;
100+
int[] orderedKeys = new int[keys.Count];
101+
keys.CopyTo(orderedKeys, 0);
102+
Array.Sort<int>(orderedKeys);
103+
StringBuilder argumentsBuilder = new StringBuilder(Math.Max(2 * orderedKeys.Length - 1, 4));
104+
for (int i = 0; i < orderedKeys.Length; i++)
105+
{
106+
key = orderedKeys[i];
107+
argumentsBuilder.Append(string.Join(" ", _options[key].Select(FormatCompilerOption)));
108+
if (i < orderedKeys.Length - 1)
109+
{
110+
argumentsBuilder.Append(" ");
111+
}
112+
}
113+
string arguments = argumentsBuilder.ToString();
106114

107115
ProcessStartInfo compilePsi = new ProcessStartInfo();
108116
compilePsi.UseShellExecute = false;
@@ -127,7 +135,6 @@ public void Reset()
127135
{
128136
_buildDirectory = null;
129137
_options.Clear();
130-
_sourceFiles.Clear();
131138
}
132139
}
133140
}

0 commit comments

Comments
 (0)