Skip to content

Commit 216204c

Browse files
committed
Add dependency packing for Windows and Linux.
1 parent b252ed9 commit 216204c

File tree

5 files changed

+58
-3
lines changed

5 files changed

+58
-3
lines changed

Algo/ALEC/ALEC.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Microsoft.CSharp;
1010
using System.Reflection;
1111
using System.Diagnostics;
12+
using ILRepacking;
1213

1314
namespace Algo
1415
{
@@ -178,6 +179,43 @@ public static void Compile(string file)
178179

179180
Log("MKBundle has finished executing.");
180181
}
182+
else
183+
{
184+
//It's Windows, use ILRepack instead.
185+
Log("Attempting to bundle dependencies into packed executable...");
186+
RepackOptions opt = new RepackOptions();
187+
opt.OutputFile = ProjectName + "_packed.exe";
188+
opt.SearchDirectories = new string[] { AppDomain.CurrentDomain.BaseDirectory, Environment.CurrentDirectory };
189+
190+
//Setting input assemblies.
191+
string[] files = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll");
192+
opt.InputAssemblies = new string[] { ProjectName + ".exe", entryasm.Location }.Concat(files).ToArray();
193+
194+
try
195+
{
196+
//Merging.
197+
ILRepack pack = new ILRepack(opt);
198+
pack.Repack();
199+
Log("Successfully merged all dependencies with the output executable.", ALECEvent.Success);
200+
201+
//Replacing the depending executable with the new one.
202+
Log("Cleaning up build files...");
203+
try
204+
{
205+
File.Delete(ProjectName + ".exe");
206+
File.Move(ProjectName + "_packed.exe", ProjectName + ".exe");
207+
}
208+
catch(Exception e)
209+
{
210+
Error.WarningCompile("File cleanup failed with error '" + e.Message + "'.");
211+
Error.WarningCompile("Failed to clean up build files, the executable to use is named '" + ProjectName + "_packed.exe' rather than '" + ProjectName + ".exe'.");
212+
}
213+
}
214+
catch(Exception e)
215+
{
216+
Error.WarningCompile("Packing the executable's dependencies failed, with error '" + e.Message + "'. You will need to include algo.exe and all it's dependencies along with the built executable for it to run.");
217+
}
218+
}
181219

182220
//Print the compile footer.
183221
PrintCompileFooter();

Algo/Algo.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
<Reference Include="Antlr4.Runtime, Version=4.6.0.0, Culture=neutral, PublicKeyToken=09abb75b9ed49849, processorArchitecture=MSIL">
5252
<HintPath>..\packages\Antlr4.Runtime.4.6.6\lib\net45\Antlr4.Runtime.dll</HintPath>
5353
</Reference>
54+
<Reference Include="ILRepack, Version=2.0.17.0, Culture=neutral, PublicKeyToken=c3e9373f1c31208e, processorArchitecture=MSIL">
55+
<HintPath>..\packages\ILRepack.Lib.2.0.17\lib\net40\ILRepack.dll</HintPath>
56+
</Reference>
5457
<Reference Include="MathNet.Numerics, Version=4.8.1.0, Culture=neutral, processorArchitecture=MSIL">
5558
<HintPath>..\packages\MathNet.Numerics.4.8.1\lib\net461\MathNet.Numerics.dll</HintPath>
5659
</Reference>

Algo/Standard Library/FunctionPluginCore.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,18 @@ public AlgoFunctionPlugins()
3333
Plugins.Add(new StandardLibrary.AlgoStd_Maths());
3434

3535
//Are there any plugin files in the /packages/ directory?
36-
string[] files = Directory.GetFiles(CPFilePath.GetPlatformFilePath(DefaultDirectories.PackagesDirectory));
37-
string[] dirs = Directory.GetDirectories(CPFilePath.GetPlatformFilePath(DefaultDirectories.PackagesDirectory));
36+
string[] files = null;
37+
string[] dirs = null;
38+
try
39+
{
40+
files = Directory.GetFiles(CPFilePath.GetPlatformFilePath(DefaultDirectories.PackagesDirectory));
41+
dirs = Directory.GetDirectories(CPFilePath.GetPlatformFilePath(DefaultDirectories.PackagesDirectory));
42+
}
43+
catch
44+
{
45+
//Failed to load, this is likely a compiled ALEC executable. Don't bother doing any more.
46+
return;
47+
}
3848

3949
List<string> dllFiles = new List<string>();
4050
foreach (var file in files)

Algo/obj/Debug/Algo.csproj.FileListAbsolute.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,7 @@ D:\Files\Programming\GitHub\algo\Algo\bin\Debug\AlgoSDK.pdb
6767
D:\Files\Programming\GitHub\algo\Algo\bin\Debug\Antlr4.Runtime.xml
6868
D:\Files\Programming\GitHub\algo\Algo\bin\Debug\MathNet.Numerics.xml
6969
D:\Files\Programming\GitHub\algo\Algo\bin\Debug\Newtonsoft.Json.xml
70-
D:\Files\Programming\GitHub\algo\Algo\obj\Debug\Algo.csprojResolveAssemblyReference.cache
70+
D:\Files\Programming\GitHub\algo\Algo\obj\Debug\Algo.csprojAssemblyReference.cache
71+
D:\Files\Programming\GitHub\algo\Algo\obj\Debug\Algo.csproj.CoreCompileInputs.cache
72+
D:\Files\Programming\GitHub\algo\Algo\bin\Debug\ILRepack.dll
73+
D:\Files\Programming\GitHub\algo\Algo\obj\Debug\Algo.csproj.CopyComplete

Algo/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<package id="Antlr4" version="4.6.6" targetFramework="net461" developmentDependency="true" />
44
<package id="Antlr4.CodeGenerator" version="4.6.6" targetFramework="net461" developmentDependency="true" />
55
<package id="Antlr4.Runtime" version="4.6.6" targetFramework="net461" />
6+
<package id="ILRepack.Lib" version="2.0.17" targetFramework="net461" />
67
<package id="MathNet.Numerics" version="4.8.1" targetFramework="net461" />
78
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net461" />
89
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net461" />

0 commit comments

Comments
 (0)