Skip to content

Commit 4c1ac85

Browse files
committed
Just forget it
1 parent 5098593 commit 4c1ac85

27 files changed

+1140
-28
lines changed

Borz.Cli/Commands/CompileCommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public override int Execute([NotNull] CommandContext context, [NotNull] Settings
8484
catch (Exception ex)
8585
{
8686
// Ignore
87+
Log.error(ex.ToString());
8788
return 1;
8889
}
8990

Borz.Cli/Commands/GenerateCommand.cs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using System.ComponentModel;
2+
using System.Diagnostics.CodeAnalysis;
3+
using AkoSharp;
4+
using Borz.Lua;
5+
using Spectre.Console.Cli;
6+
7+
namespace Borz.Cli.Commands;
8+
9+
[SuppressMessage("ReSharper", "RedundantNullableFlowAttribute")]
10+
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")]
11+
public class GenerateCommand : Command<GenerateCommand.Settings>
12+
{
13+
public sealed class Settings : CommandSettings
14+
{
15+
[CommandArgument(0, "<generator>")] public string Generator { get; set; }
16+
17+
[LocalDesc("Compile.Desc.Target")]
18+
[CommandOption("-t|--target")]
19+
[DefaultValue(null)]
20+
public string? Target { get; init; } = null;
21+
22+
[CommandArgument(0, "[config]")] public string? Config { get; init; }
23+
}
24+
25+
public override int Execute([NotNull] CommandContext context, [NotNull] Settings settings)
26+
{
27+
var opt = new Options()
28+
{
29+
};
30+
31+
if (settings.Target != null)
32+
{
33+
var parsedTarget = MachineInfo.Parse(settings.Target);
34+
if (parsedTarget == null)
35+
{
36+
MugiLog.Error($"Unknown target: {settings.Target} known targets are:");
37+
foreach (var machine in MachineInfo.GetKnownMachines())
38+
{
39+
MugiLog.Error(machine.ToString());
40+
}
41+
42+
return 1;
43+
}
44+
45+
opt.Target = parsedTarget;
46+
}
47+
48+
CmdUtils.LoadWorkspaceSettings(opt);
49+
50+
if (settings.Config != null)
51+
{
52+
if (!opt.ValidConfigs.Contains(settings.Config))
53+
{
54+
MugiLog.Error($"{settings.Config} isn't valid.");
55+
return 1;
56+
}
57+
58+
opt.Config = settings.Config;
59+
}
60+
61+
var ws = new Workspace(".");
62+
63+
var script = ScriptRunner.CreateScript();
64+
script.Globals["ws"] = ws;
65+
script.Globals["opt"] = opt;
66+
67+
var scriptPath = Utils.GetBorzScriptFilePath(ws.Location);
68+
if (!File.Exists(scriptPath))
69+
{
70+
MugiLog.Error($"No borz script found in {ws.Location}, need build.borz or borz.lua in root directory");
71+
return 1;
72+
}
73+
74+
ScriptRunner.Eval(script, scriptPath);
75+
76+
var generator = GeneratorFactory.TryGetGenerator(settings.Generator);
77+
if (generator == null)
78+
{
79+
MugiLog.Error($"No generator found for {settings.Generator}");
80+
return 1;
81+
}
82+
83+
try
84+
{
85+
var (success, error) = generator.Generate(ws, opt);
86+
if (!success)
87+
{
88+
MugiLog.Error(error);
89+
return 1;
90+
}
91+
}
92+
catch (Exception ex)
93+
{
94+
// Ignore
95+
Log.error(ex.ToString());
96+
return 1;
97+
}
98+
99+
return 0;
100+
}
101+
102+
103+
}

Borz.Cli/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
{
99
config.Settings.ApplicationName = "Borz";
1010
config.AddCommand<CompileCommand>("compile").WithAlias("c");
11+
config.AddCommand<GenerateCommand>("generate").WithAlias("g");
1112
});
1213

1314
var res = 1;

Borz.Linux/LinuxPlatform.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@ public string GetUserConfigPath()
1616
return xdgConfigHome;
1717
}
1818

19+
public void Init()
20+
{
21+
//add mingw
22+
var mingw = MachineInfo.NewOrGet("windows", "x86_64");
23+
mingw.Binaries = new()
24+
{
25+
{"gcc", "x86_64-w64-mingw32-gcc"},
26+
{"g++", "x86_64-w64-mingw32-g++"},
27+
};
28+
mingw.Compilers = new()
29+
{
30+
{"c", "gcc"},
31+
{"cpp", "gcc"}
32+
};
33+
}
34+
1935
public MemoryInfo GetMemoryInfo()
2036
{
2137
var info = File.ReadAllText("/proc/meminfo");

Borz/Borz.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public static void Init()
2020
SetupDefaults(); //Load defaults into Config
2121
LoadUserConfig(); //Load user config into Config
2222

23+
IPlatform.Instance.Init();
24+
2325
//safe to assume that the users preferred log level is set in Config.
2426
//but the environment variable is always preferred over the config.
2527
var loglevel = Environment.GetEnvironmentVariable("BORZ_LL");

Borz/BuildFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ static BuildFactory()
1111
var cBuilder = new CBuilder();
1212
_knownBuilders.Add(Lang.C, cBuilder);
1313
_knownBuilders.Add(Lang.Cpp, cBuilder);
14+
_knownBuilders.Add(Lang.D, cBuilder);
1415
}
1516

1617
public static Builder GetBuilder(string language)

Borz/CompilerFactory.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ static CompilerFactory()
1414
{
1515
{ "unix", opt => new UnixCCompiler(opt) },
1616
{ "gcc", opt => new GccCompiler(opt) },
17+
{ "gdc", opt => new GdcCompiler(opt) },
1718
{ "psxgcc", opt => new PsxCompiler(opt) },
19+
{ "emcc", opt => new EmscriptCompiler(opt) },
1820
};
1921
}
2022

Borz/Compilers/CommonUnixCCompiler.cs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Runtime.InteropServices;
12
using Borz.Helpers;
23
using Borz.Languages.C;
34
using Microsoft.VisualBasic;
@@ -73,7 +74,6 @@ public override ProcUtil.RunOutput LinkProject(Project inPrj, string[] objects)
7374
if(inPrj is not CProject project)
7475
throw new Exception("Project is not a CppProject or CProject");
7576

76-
7777
var outputPath = project.GetOutputFilePath(Opt);
7878

7979
if(project.Type == BinType.StaticLib)
@@ -82,16 +82,23 @@ public override ProcUtil.RunOutput LinkProject(Project inPrj, string[] objects)
8282

8383
List<string> cmdArgs = new();
8484

85-
cmdArgs.Add("-o");
86-
cmdArgs.Add(outputPath);
85+
AddLinkOptions_Early(project, ref cmdArgs);
86+
87+
AddOutput(project, ref cmdArgs);
8788

8889
AddStdVersion(project, ref cmdArgs);
8990
AddOptimisation(project, ref cmdArgs);
9091

9192
cmdArgs.AddRange(objects);
9293

9394
foreach (var rpath in project.GetRPaths(project.GetOutputDirectory(Opt), Opt))
94-
cmdArgs.Add($"-Wl,-rpath=$ORIGIN/{rpath}");
95+
{
96+
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
97+
cmdArgs.Add($"-Wl,-rpath,@loader_path/{rpath}");
98+
else
99+
cmdArgs.Add($"-Wl,-rpath,$ORIGIN/{rpath}");
100+
}
101+
95102

96103
if (Opt.GetTarget().CompileInfo.TryGetValue(project.Language, out var info))
97104
{
@@ -177,12 +184,24 @@ public override ProcUtil.RunOutput CompilePch(CProject project)
177184
Strings.Join(cmdArgs.ToArray())!, project.Directory, Opt.JustPrint);
178185
}
179186

180-
public void AddSymbols(CProject project, ref List<string> args)
187+
public virtual void AddLinkOptions_Early(CProject project, ref List<string> args)
188+
{
189+
190+
}
191+
192+
public virtual void AddOutput(CProject project, ref List<string> args)
193+
{
194+
var outputPath = project.GetOutputFilePath(Opt);
195+
args.Add("-o");
196+
args.Add(outputPath);
197+
}
198+
199+
public virtual void AddSymbols(CProject project, ref List<string> args)
181200
{
182201
args.Add(project.Symbols ? "-g" : "-s");
183202
}
184203

185-
public void AddStdVersion(CProject project, ref List<string> args)
204+
public virtual void AddStdVersion(CProject project, ref List<string> args)
186205
{
187206
if (project.StdVersion == "none")
188207
{
@@ -193,10 +212,14 @@ public void AddStdVersion(CProject project, ref List<string> args)
193212
if (project.StdVersion != string.Empty)
194213
{
195214
if (project.StdVersion.All(char.IsDigit))
215+
{
196216
args.Add($"-std=" + (project is CppProject ? "c++" : "c") + project.StdVersion);
217+
}
197218
else
219+
{
198220
//just pass what ever they put in
199221
args.Add($"-std=" + project.StdVersion);
222+
}
200223
}
201224
}
202225

@@ -244,7 +267,7 @@ public void AddLibraryPaths(CProject project, ref List<string> args)
244267
foreach (var libraryPath in project.GetLibraryPaths(Opt)) args.Add($"-L{libraryPath}");
245268
}
246269

247-
public void AddLibraries(CProject project, ref List<string> args)
270+
public virtual void AddLibraries(CProject project, ref List<string> args)
248271
{
249272
foreach (var library in project.GetLibraries(Opt)) args.Add($"-l{library}");
250273
}

Borz/Compilers/EmscriptCompiler.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Borz.Languages.C;
2+
using Microsoft.VisualBasic;
3+
4+
namespace Borz.Compilers;
5+
6+
public class EmscriptCompiler : CommonUnixCCompiler
7+
{
8+
public override string Name => "emscript";
9+
10+
public EmscriptCompiler(Options opt) : base(opt)
11+
{
12+
CCompilerElf = Opt.GetTarget().GetBinaryPath("cc", "cc");
13+
CppCompilerElf = Opt.GetTarget().GetBinaryPath("c++", "c++");
14+
}
15+
16+
17+
public override (bool supported, string reason) IsSupported()
18+
{
19+
//cant test this.
20+
return (true, string.Empty);
21+
}
22+
23+
}

0 commit comments

Comments
 (0)