unlock
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
build
|
||||
recovery
|
||||
BeefSpace_User.toml
|
||||
BeefSpace_Lock.toml
|
||||
@@ -0,0 +1,70 @@
|
||||
FileVersion = 1
|
||||
|
||||
[Project]
|
||||
Name = "ENet"
|
||||
TargetType = "BeefLib"
|
||||
StartupObject = "ENet.Program"
|
||||
|
||||
[Dependencies]
|
||||
corlib = "*"
|
||||
"CxxBuildTool.git" = {Git = "https://git.unicon-gmbh.de/Rune/CxxBuildTool.git"}
|
||||
|
||||
[Configs.Debug.Win32]
|
||||
LibPaths = ["$(BuildDir)/enet.lib"]
|
||||
|
||||
[Configs.Debug.Win64]
|
||||
LibPaths = ["$(BuildDir)/enet.lib"]
|
||||
|
||||
[Configs.Debug.Linux32]
|
||||
LibPaths = ["$(BuildDir)/enet.a"]
|
||||
|
||||
[Configs.Debug.Linux64]
|
||||
LibPaths = ["$(BuildDir)/enet.a"]
|
||||
|
||||
[Configs.Debug.macOS]
|
||||
LibPaths = ["$(BuildDir)/enet.a"]
|
||||
|
||||
[Configs.Release.Win32]
|
||||
LibPaths = ["$(BuildDir)/enet.lib"]
|
||||
|
||||
[Configs.Release.Win64]
|
||||
LibPaths = ["$(BuildDir)/enet.lib"]
|
||||
|
||||
[Configs.Release.Linux32]
|
||||
LibPaths = ["$(BuildDir)/enet.a"]
|
||||
|
||||
[Configs.Release.Linux64]
|
||||
LibPaths = ["$(BuildDir)/enet.a"]
|
||||
|
||||
[Configs.Release.macOS]
|
||||
LibPaths = ["$(BuildDir)/enet.a"]
|
||||
|
||||
[Configs.Paranoid.Win32]
|
||||
LibPaths = ["$(BuildDir)/enet.lib"]
|
||||
|
||||
[Configs.Paranoid.Win64]
|
||||
LibPaths = ["$(BuildDir)/enet.lib"]
|
||||
|
||||
[Configs.Paranoid.Linux32]
|
||||
LibPaths = ["$(BuildDir)/enet.a"]
|
||||
|
||||
[Configs.Paranoid.Linux64]
|
||||
LibPaths = ["$(BuildDir)/enet.a"]
|
||||
|
||||
[Configs.Paranoid.macOS]
|
||||
LibPaths = ["$(BuildDir)/enet.a"]
|
||||
|
||||
[Configs.Test.Win32]
|
||||
LibPaths = ["$(BuildDir)/enet.lib"]
|
||||
|
||||
[Configs.Test.Win64]
|
||||
LibPaths = ["$(BuildDir)/enet.lib"]
|
||||
|
||||
[Configs.Test.Linux32]
|
||||
LibPaths = ["$(BuildDir)/enet.a"]
|
||||
|
||||
[Configs.Test.Linux64]
|
||||
LibPaths = ["$(BuildDir)/enet.a"]
|
||||
|
||||
[Configs.Test.macOS]
|
||||
LibPaths = ["$(BuildDir)/enet.a"]
|
||||
@@ -0,0 +1,9 @@
|
||||
FileVersion = 1
|
||||
ExtraPlatforms = ["Linux32", "Linux64", "macOS"]
|
||||
|
||||
[Workspace]
|
||||
StartupProject = "ENet"
|
||||
|
||||
[Projects]
|
||||
ENet = {Path = "."}
|
||||
"CxxBuildTool.git" = {Git = "https://git.unicon-gmbh.de/Rune/CxxBuildTool.git"}
|
||||
@@ -0,0 +1,9 @@
|
||||
FileVersion = 1
|
||||
|
||||
[Project]
|
||||
Name = "ENet.Setup"
|
||||
StartupObject = "ENet.Setup.Program"
|
||||
|
||||
[Dependencies]
|
||||
corlib = "*"
|
||||
"Cpp2Beef.git" = {Git = "https://git.unicon-gmbh.de/Rune/Cpp2Beef.git"}
|
||||
@@ -0,0 +1,8 @@
|
||||
FileVersion = 1
|
||||
|
||||
[Workspace]
|
||||
StartupProject = "ENet.Setup"
|
||||
|
||||
[Projects]
|
||||
"ENet.Setup" = {Path = "."}
|
||||
"Cpp2Beef.git" = {Git = "https://git.unicon-gmbh.de/Rune/Cpp2Beef.git"}
|
||||
@@ -0,0 +1,155 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Diagnostics;
|
||||
|
||||
using Cpp2Beef;
|
||||
using LibClang;
|
||||
|
||||
namespace ENet.Setup;
|
||||
|
||||
class ENetGenerator : Cpp2BeefGenerator, this(Span<char8*> args)
|
||||
{
|
||||
protected override Span<char8*> Args => args;
|
||||
protected override Flags Flags => .None;
|
||||
|
||||
StreamWriter writer = new .()..Create("../src/ENet.bf")..Write("""
|
||||
// This file was generated by Cpp2Beef
|
||||
|
||||
using System;
|
||||
using System.Interop;
|
||||
|
||||
namespace ENet;
|
||||
|
||||
|
||||
""") ~ delete _;
|
||||
|
||||
protected override StreamWriter GetWriterForHeader(StringView header)
|
||||
{
|
||||
if (header.EndsWith("enet.h"))
|
||||
return writer;
|
||||
return null;
|
||||
}
|
||||
|
||||
const String[?] handles = .("socket_", "host_", "address_", "peer_");
|
||||
const String[?] handleBlocks = .("ENetSocket", "ENetHost", "ENetAddress", "ENetPeer");
|
||||
|
||||
protected override Block GetCursorBlock(CXCursor cursor)
|
||||
{
|
||||
if (cursor.kind == .FunctionDecl) do
|
||||
{
|
||||
StringView spelling = GetCursorSpelling!(cursor);
|
||||
if (!spelling.StartsWith("enet_")) break;
|
||||
spelling.RemoveFromStart(5);
|
||||
for (let i < handles.Count)
|
||||
if (spelling.StartsWith(handles[i]))
|
||||
return .CustomBlock(handleBlocks[i]);
|
||||
return .CustomBlock("ENet");
|
||||
}
|
||||
if (cursor.kind == .EnumDecl && Clang.Cursor_IsAnonymous(cursor) != 0)
|
||||
return .StaticBlock;
|
||||
if (cursor.kind == .EnumConstantDecl)
|
||||
return .StaticBlock;
|
||||
return base.GetCursorBlock(cursor);
|
||||
}
|
||||
|
||||
protected override void HandleCursor(CXCursor cursor)
|
||||
{
|
||||
switch (cursor.kind)
|
||||
{
|
||||
case .MacroDefinition:
|
||||
StringView spelling = GetCursorSpelling!(cursor);
|
||||
if (spelling == "CLOCK_MONOTONIC" || spelling == "ENET_CALLBACK" || spelling == "ENET_API" || spelling.StartsWith("enet_address_"))
|
||||
return;
|
||||
case .TypedefDecl:
|
||||
StringView spelling = GetCursorSpelling!(cursor);
|
||||
if (spelling == "ENetSocketSet" || spelling == "ENetSocket")
|
||||
return;
|
||||
case .StructDecl:
|
||||
StringView spelling = GetCursorSpelling!(cursor);
|
||||
if (spelling == "_ENetHost")
|
||||
return;
|
||||
case .EnumDecl:
|
||||
if (Clang.Cursor_IsAnonymous(cursor) != 0)
|
||||
{
|
||||
BeginCursor(cursor);
|
||||
Clang.VisitChildren(cursor, (cursor, parent, client_data) =>
|
||||
{
|
||||
Self self = (.)Internal.UnsafeCastToObject(client_data);
|
||||
Runtime.Assert(cursor.kind == .EnumConstantDecl);
|
||||
self.BeginCursor(cursor);
|
||||
self.str.Append("public const let ");
|
||||
self.WriteCustomAttributes(cursor);
|
||||
self.str.Append(GetCursorSpelling!(cursor));
|
||||
self.WriteTokensAfterEquals(cursor);
|
||||
self.str.Append(';');
|
||||
return .Continue;
|
||||
}, Internal.UnsafeCastToPtr(this));
|
||||
return;
|
||||
}
|
||||
default:
|
||||
}
|
||||
base.HandleCursor(cursor);
|
||||
if (cursor.kind == .VarDecl)
|
||||
{
|
||||
str.Replace("{{{", ".(");
|
||||
str.Replace("}}}", ")");
|
||||
}
|
||||
}
|
||||
|
||||
protected override void GetNameInBindings(LibClang.CXCursor cursor, String outString)
|
||||
{
|
||||
switch (cursor.kind)
|
||||
{
|
||||
case .FunctionDecl:
|
||||
StringView spelling = GetCursorSpelling!(cursor);
|
||||
if (spelling.StartsWith("enet_")) spelling.RemoveFromStart(5);
|
||||
for (let handle in handles)
|
||||
if (spelling.StartsWith(handle))
|
||||
{
|
||||
spelling.RemoveFromStart(handle.Length);
|
||||
break;
|
||||
}
|
||||
UpperSnakeCase2PascalCase(spelling, outString);
|
||||
return;
|
||||
case .StructDecl, .UnionDecl, .EnumDecl:
|
||||
StringView spelling = GetCursorSpelling!(cursor);
|
||||
if (spelling.StartsWith('_')) spelling.RemoveFromStart(1);
|
||||
outString.Append(spelling);
|
||||
return;
|
||||
case .MacroDefinition:
|
||||
StringView spelling = GetCursorSpelling!(cursor);
|
||||
if (spelling == "INVALID_SOCKET")
|
||||
{
|
||||
outString.Append('0');
|
||||
return;
|
||||
}
|
||||
case .EnumConstantDecl:
|
||||
StringView spelling = UpperSnakeCase2PascalCase(GetCursorSpelling!(cursor), ..scope .());
|
||||
StringView parent = GetCursorSpelling!(Clang.GetCursorSemanticParent(cursor));
|
||||
if (parent.StartsWith('_')) parent.RemoveFromStart(1);
|
||||
if (parent == "ENetProtocolFlag") parent.RemoveFromEnd(4);
|
||||
if (parent == "ENetSocketOption") parent = "EnetSockopt";
|
||||
if (spelling.StartsWith(parent, .OrdinalIgnoreCase))
|
||||
spelling.RemoveFromStart(parent.Length);
|
||||
outString.Append(spelling);
|
||||
return;
|
||||
default:
|
||||
}
|
||||
base.GetNameInBindings(cursor, outString);
|
||||
}
|
||||
}
|
||||
|
||||
class Program
|
||||
{
|
||||
[CLink] static extern int32 system(char8*);
|
||||
|
||||
public static int Main(String[] args)
|
||||
{
|
||||
if (system("wget -O ../src/enet.h https://raw.githubusercontent.com/zpl-c/enet/refs/heads/master/include/enet.h") != 0)
|
||||
Runtime.FatalError("Failed to download enet.h");
|
||||
|
||||
scope ENetGenerator(char8*[?]("--language=c")).Generate("../src/enet.h");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
+6306
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Interop;
|
||||
|
||||
using CxxBuildTool;
|
||||
|
||||
namespace ENet;
|
||||
|
||||
static
|
||||
{
|
||||
public static enet_uint32 ENET_VERSION_CREATE(enet_uint32 major, enet_uint32 minor, enet_uint32 patch) => (((major)<<16) | ((minor)<<8) | (patch));
|
||||
public static enet_uint32 ENET_VERSION_GET_MAJOR(enet_uint32 version) => (((version)>>16)&0xFF);
|
||||
public static enet_uint32 ENET_VERSION_GET_MINOR(enet_uint32 version) => (((version)>>8)&0xFF);
|
||||
public static enet_uint32 ENET_VERSION_GET_PATCH(enet_uint32 version) => ((version)&0xFF);
|
||||
|
||||
private const in6_addr in6addr_any = default;
|
||||
}
|
||||
|
||||
/** IPv6 address, 16 bytes */
|
||||
[CRepr] struct in6_addr
|
||||
{
|
||||
public uint8[16] s6_addr;
|
||||
|
||||
public this() { s6_addr = default; }
|
||||
public this(
|
||||
uint8 a0, uint8 a1, uint8 a2, uint8 a3,
|
||||
uint8 a4, uint8 a5, uint8 a6, uint8 a7,
|
||||
uint8 a8, uint8 a9, uint8 a10, uint8 a11,
|
||||
uint8 a12, uint8 a13, uint8 a14, uint8 a15
|
||||
)
|
||||
{
|
||||
s6_addr = .(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15);
|
||||
}
|
||||
}
|
||||
|
||||
#if BF_PLATFORM_WINDOWS
|
||||
public struct ENetSocket : int {}
|
||||
#else
|
||||
public struct ENetSocket : c_int {}
|
||||
#endif
|
||||
|
||||
public struct ENetSocketSet;
|
||||
public struct ENetHost;
|
||||
|
||||
static class ENet
|
||||
{
|
||||
[OnCompile(.TypeDone)]
|
||||
private static void Build()
|
||||
{
|
||||
if (!Compiler.IsBuilding) return;
|
||||
CxxBuildTool.Ninja(Compiler.ProjectDir + "/src", Compiler.BuildDir + "/" + Compiler.ProjectName, "enet", "", "enet.c");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
#define ENET_IMPLEMENTATION
|
||||
#include "enet.h"
|
||||
+6257
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user