Initial commit

This commit is contained in:
Beef Bindings
2026-03-11 15:48:30 +00:00
commit 97e8446b96
9 changed files with 322 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
build
recovery
BeefSpace_User.toml
CxxBuilderPath.txt

66
BeefProj.toml Normal file
View File

@@ -0,0 +1,66 @@
FileVersion = 1
[Project]
Name = "<ProjectName>"
TargetType = "BeefLib"
StartupObject = "<ProjectName>.Program"
[Configs.Debug.Win32]
PreBuildCmds = ["ReadFile(\"$(ProjectDir)/CxxBuilderPath.txt\", \"CxxBuilderPath\")"]
[Configs.Debug.Win64]
PreBuildCmds = ["ReadFile(\"$(ProjectDir)/CxxBuilderPath.txt\", \"CxxBuilderPath\")"]
[Configs.Debug.Linux32]
PreBuildCmds = ["ReadFile(\"$(ProjectDir)/CxxBuilderPath.txt\", \"CxxBuilderPath\")"]
[Configs.Debug.Linux64]
PreBuildCmds = ["ReadFile(\"$(ProjectDir)/CxxBuilderPath.txt\", \"CxxBuilderPath\")"]
[Configs.Debug.macOS]
PreBuildCmds = ["ReadFile(\"$(ProjectDir)/CxxBuilderPath.txt\", \"CxxBuilderPath\")"]
[Configs.Release.Win32]
PreBuildCmds = ["ReadFile(\"$(ProjectDir)/CxxBuilderPath.txt\", \"CxxBuilderPath\")"]
[Configs.Release.Win64]
PreBuildCmds = ["ReadFile(\"$(ProjectDir)/CxxBuilderPath.txt\", \"CxxBuilderPath\")"]
[Configs.Release.Linux32]
PreBuildCmds = ["ReadFile(\"$(ProjectDir)/CxxBuilderPath.txt\", \"CxxBuilderPath\")"]
[Configs.Release.Linux64]
PreBuildCmds = ["ReadFile(\"$(ProjectDir)/CxxBuilderPath.txt\", \"CxxBuilderPath\")"]
[Configs.Release.macOS]
PreBuildCmds = ["ReadFile(\"$(ProjectDir)/CxxBuilderPath.txt\", \"CxxBuilderPath\")"]
[Configs.Paranoid.Win32]
PreBuildCmds = ["ReadFile(\"$(ProjectDir)/CxxBuilderPath.txt\", \"CxxBuilderPath\")"]
[Configs.Paranoid.Win64]
PreBuildCmds = ["ReadFile(\"$(ProjectDir)/CxxBuilderPath.txt\", \"CxxBuilderPath\")"]
[Configs.Paranoid.Linux32]
PreBuildCmds = ["ReadFile(\"$(ProjectDir)/CxxBuilderPath.txt\", \"CxxBuilderPath\")"]
[Configs.Paranoid.Linux64]
PreBuildCmds = ["ReadFile(\"$(ProjectDir)/CxxBuilderPath.txt\", \"CxxBuilderPath\")"]
[Configs.Paranoid.macOS]
PreBuildCmds = ["ReadFile(\"$(ProjectDir)/CxxBuilderPath.txt\", \"CxxBuilderPath\")"]
[Configs.Test.Win32]
PreBuildCmds = ["ReadFile(\"$(ProjectDir)/CxxBuilderPath.txt\", \"CxxBuilderPath\")"]
[Configs.Test.Win64]
PreBuildCmds = ["ReadFile(\"$(ProjectDir)/CxxBuilderPath.txt\", \"CxxBuilderPath\")"]
[Configs.Test.Linux32]
PreBuildCmds = ["ReadFile(\"$(ProjectDir)/CxxBuilderPath.txt\", \"CxxBuilderPath\")"]
[Configs.Test.Linux64]
PreBuildCmds = ["ReadFile(\"$(ProjectDir)/CxxBuilderPath.txt\", \"CxxBuilderPath\")"]
[Configs.Test.macOS]
PreBuildCmds = ["ReadFile(\"$(ProjectDir)/CxxBuilderPath.txt\", \"CxxBuilderPath\")"]

6
BeefSpace.toml Normal file
View File

@@ -0,0 +1,6 @@
FileVersion = 1
Projects = {"<ProjectName>" = {Path = "."}}
ExtraPlatforms = ["Linux32", "Linux64", "macOS"]
[Workspace]
StartupProject = "<ProjectName>"

15
README.md Normal file
View File

@@ -0,0 +1,15 @@
# Cpp2Beef Template
Template for [Cpp2Beef](https://git.unicon-gmbh.de/BeefBindings/Cpp2Beef) Bindings
## Usage
```sh
# fork the repo
git clone --depth 1 https://git.unicon-gmbh.de/BeefBindings/Cpp2Beef.Template.git <path>
cd <path>
git remote rename origin upstream
git remote add origin <url>
# replace all occurences of <ProjectName> with <name>
python ./replace.py <name>
rm replace.py
```

6
Setup/.gitignore vendored Normal file
View File

@@ -0,0 +1,6 @@
build
recovery
BeefSpace_User.toml
# lock ignored by default to make template is always on the latest version
BeefSpace_Lock.toml

67
Setup/BeefProj.toml Normal file
View File

@@ -0,0 +1,67 @@
FileVersion = 1
Dependencies = {corlib = "*", "Clang-C.git" = "*", "Cpp2Beef.git" = {Git = "https://git.unicon-gmbh.de/BeefBindings/Cpp2Beef.git"}}
[Project]
Name = "<ProjectName>.Setup"
StartupObject = "<ProjectName>.Setup.Program"
DefaultNamespace = "<ProjectName>.Setup"
[Configs.Debug.Win32]
PreBuildCmds = ["cp $(ProjectDir Cpp2Beef.git)/CxxBuilder/dist/CxxBuilderPath.txt ../CxxBuilderPath.txt"]
[Configs.Debug.Win64]
PreBuildCmds = ["cp $(ProjectDir Cpp2Beef.git)/CxxBuilder/dist/CxxBuilderPath.txt ../CxxBuilderPath.txt"]
[Configs.Debug.Linux32]
PreBuildCmds = ["cp $(ProjectDir Cpp2Beef.git)/CxxBuilder/dist/CxxBuilderPath.txt ../CxxBuilderPath.txt"]
[Configs.Debug.Linux64]
PreBuildCmds = ["cp $(ProjectDir Cpp2Beef.git)/CxxBuilder/dist/CxxBuilderPath.txt ../CxxBuilderPath.txt"]
[Configs.Debug.macOS]
PreBuildCmds = ["cp $(ProjectDir Cpp2Beef.git)/CxxBuilder/dist/CxxBuilderPath.txt ../CxxBuilderPath.txt"]
[Configs.Release.Win32]
PreBuildCmds = ["cp $(ProjectDir Cpp2Beef.git)/CxxBuilder/dist/CxxBuilderPath.txt ../CxxBuilderPath.txt"]
[Configs.Release.Win64]
PreBuildCmds = ["cp $(ProjectDir Cpp2Beef.git)/CxxBuilder/dist/CxxBuilderPath.txt ../CxxBuilderPath.txt"]
[Configs.Release.Linux32]
PreBuildCmds = ["cp $(ProjectDir Cpp2Beef.git)/CxxBuilder/dist/CxxBuilderPath.txt ../CxxBuilderPath.txt"]
[Configs.Release.Linux64]
PreBuildCmds = ["cp $(ProjectDir Cpp2Beef.git)/CxxBuilder/dist/CxxBuilderPath.txt ../CxxBuilderPath.txt"]
[Configs.Release.macOS]
PreBuildCmds = ["cp $(ProjectDir Cpp2Beef.git)/CxxBuilder/dist/CxxBuilderPath.txt ../CxxBuilderPath.txt"]
[Configs.Paranoid.Win32]
PreBuildCmds = ["cp $(ProjectDir Cpp2Beef.git)/CxxBuilder/dist/CxxBuilderPath.txt ../CxxBuilderPath.txt"]
[Configs.Paranoid.Win64]
PreBuildCmds = ["cp $(ProjectDir Cpp2Beef.git)/CxxBuilder/dist/CxxBuilderPath.txt ../CxxBuilderPath.txt"]
[Configs.Paranoid.Linux32]
PreBuildCmds = ["cp $(ProjectDir Cpp2Beef.git)/CxxBuilder/dist/CxxBuilderPath.txt ../CxxBuilderPath.txt"]
[Configs.Paranoid.Linux64]
PreBuildCmds = ["cp $(ProjectDir Cpp2Beef.git)/CxxBuilder/dist/CxxBuilderPath.txt ../CxxBuilderPath.txt"]
[Configs.Paranoid.macOS]
PreBuildCmds = ["cp $(ProjectDir Cpp2Beef.git)/CxxBuilder/dist/CxxBuilderPath.txt ../CxxBuilderPath.txt"]
[Configs.Test.Win32]
PreBuildCmds = ["cp $(ProjectDir Cpp2Beef.git)/CxxBuilder/dist/CxxBuilderPath.txt ../CxxBuilderPath.txt"]
[Configs.Test.Win64]
PreBuildCmds = ["cp $(ProjectDir Cpp2Beef.git)/CxxBuilder/dist/CxxBuilderPath.txt ../CxxBuilderPath.txt"]
[Configs.Test.Linux32]
PreBuildCmds = ["cp $(ProjectDir Cpp2Beef.git)/CxxBuilder/dist/CxxBuilderPath.txt ../CxxBuilderPath.txt"]
[Configs.Test.Linux64]
PreBuildCmds = ["cp $(ProjectDir Cpp2Beef.git)/CxxBuilder/dist/CxxBuilderPath.txt ../CxxBuilderPath.txt"]
[Configs.Test.macOS]
PreBuildCmds = ["cp $(ProjectDir Cpp2Beef.git)/CxxBuilder/dist/CxxBuilderPath.txt ../CxxBuilderPath.txt"]

6
Setup/BeefSpace.toml Normal file
View File

@@ -0,0 +1,6 @@
FileVersion = 1
Projects = {"<ProjectName>.Setup" = {Path = "."}, "Cpp2Beef.git" = {Git = "https://git.unicon-gmbh.de/BeefBindings/Cpp2Beef.git"}}
ExtraPlatforms = ["Linux32", "Linux64", "macOS"]
[Workspace]
StartupProject = "<ProjectName>.Setup"

52
Setup/src/Program.bf Normal file
View File

@@ -0,0 +1,52 @@
using System;
using System.IO;
using System.Collections;
using System.Diagnostics;
using Cpp2Beef;
using LibClang;
namespace <ProjectName>.Setup;
class <ProjectName>Generator : Cpp2BeefGenerator, this(Span<char8*> args)
{
protected override Span<char8*> Args => args;
protected override Flags Flags => .None;
StreamWriter writer = new .()..Create(TODO)..Write("""
// This file was generated by Cpp2Beef
using System;
using System.Interop;
namespace <ProjectName>;
""");
protected override StreamWriter GetWriterForHeader(StringView header)
{
if (header.EndsWith(TODO))
return writer;
return null;
}
}
class Program
{
[CLink] static extern int32 system(char8*);
private static mixin RunCommand(char8* cmd)
{
Console.WriteLine($"> {StringView(cmd)}");
int32 rcode = system(cmd);
if (rcode != 0)
return rcode;
}
public static int Main(String[] args)
{
scope <ProjectName>Generator(char8*[?]("--language=c")).Generate(TODO, null);
return 0;
}
}

99
replace.py Normal file
View File

@@ -0,0 +1,99 @@
#!/usr/bin/env python3
import os
import sys
import argparse
import shutil
def find_files_with_project_name(root_dir="."):
"""Find all files that contain <ProjectName> but exclude specified files"""
target_files = []
ignored_dirs = {".git", ".svn", ".hg", ".vscode", "__pycache__"}
ignored_files = {
"./README.md",
"./replace.py"
}
# Normalize ignored files for comparison
normalized_ignored = set()
for f in ignored_files:
normalized_ignored.add(os.path.normpath(f).replace("\\", "/"))
for dirpath, dirnames, filenames in os.walk(root_dir):
# Filter out hidden directories
dirnames[:] = [d for d in dirnames if d not in ignored_dirs and not d.startswith('.')]
for filename in filenames:
if filename.startswith('.') or filename.endswith(('.pyc', '.pyo', '~')):
continue
filepath = os.path.join(dirpath, filename)
rel_path = os.path.relpath(filepath).replace("\\", "/")
# Skip ignored files
if rel_path in normalized_ignored:
continue
try:
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()
if '<ProjectName>' in content:
target_files.append(filepath)
except (UnicodeDecodeError, PermissionError):
# Skip unreadable or binary files
pass
return sorted(target_files)
def main():
parser = argparse.ArgumentParser(description='Replace <ProjectName> with custom project name')
parser.add_argument('project_name', help='The new project name to replace <ProjectName> with')
args = parser.parse_args()
if len(sys.argv) != 2:
print("Usage: python replace_project_name.py <NewProjectName>")
sys.exit(1)
project_name = args.project_name
if not project_name:
print("Error: Project name cannot be empty")
sys.exit(1)
# Find all files containing <ProjectName>
files_with_project_name = find_files_with_project_name()
if not files_with_project_name:
print("No files found containing <ProjectName>")
sys.exit(1)
print(f"Found {len(files_with_project_name)} file(s) containing <ProjectName>:")
for f in files_with_project_name:
print(f"{f}")
# Perform replacements
modified_count = 0
for file_path in files_with_project_name:
try:
# Read the file
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()
# Check if replacement is needed
if '<ProjectName>' in content:
# Replace all occurrences
new_content = content.replace('<ProjectName>', project_name)
# Write back to file
with open(file_path, 'w', encoding='utf-8') as f:
f.write(new_content)
print(f"Updated: {file_path}")
modified_count += 1
except Exception as e:
print(f"Error processing {file_path}: {e}")
print(f"\nSuccessfully replaced <ProjectName> with '{project_name}' in {modified_count} file(s)")
if __name__ == "__main__":
main()