Skip to content

Commit 297da36

Browse files
committed
readme
1 parent d7810ac commit 297da36

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

README.md

+45-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,51 @@ Unfortunately, there are many [restrictions](https://learn.microsoft.com/dotnet/
1515
This is where the code generator, that is at the core of Beyond.NET comes in.
1616
The generator can target any compiled .NET assembly and generate native code bindings for all public types and APIs contained within it. It does this by loading the targeted assembly and reflecting over all of its types. Next, wrapper functions for all publicly available APIs are generated and decorated with the `UnmanagedCallersOnly` attribute which makes them callable from native code.
1717
From there, bindings for other languages can be generated. Which language bindings are generated can be controlled by various settings but the C bindings form the basis for all other languages.
18-
So if you're, for instance targeting Swift the call tree looks like this: Swift -> C -> C# APIs marked with the `UnmanagedCallersOnly` attribute -> Original C# API.
18+
So if you're, for instance targeting Swift the call tree looks like this: Swift -> C -> .NET APIs marked with the `UnmanagedCallersOnly` attribute -> Original .NET API.
19+
20+
Since new C# code is generated as part of the language bindings, it's required to either include the single generated C# source code file in the existing .NET project you're targeting or create a new project soley for the purpose of compiling a native version of the assembly. We recommend the latter as you will need to compile your project using NativeAOT to actually take advantage of the generated bindings and that way, the original assembly stays unmodified.
21+
22+
23+
## Quick Start Guide
24+
25+
- Make sure [.NET 8](https://dotnet.microsoft.com/download/dotnet/8.0) is installed.
26+
- On macOS, make sure [Xcode](https://developer.apple.com/xcode/) is installed.
27+
- Either clone the Beyond.NET repository or download one of the pre-built generator executables for your platform.
28+
- If you do not have a pre-compiled executable of the generator, compile it by either running `dotnet publish` within its directory or use one of our provided publish scripts like `publish_macos_universal` for compiling a universal macOS binary.
29+
- Open a terminal and execute the generator (`./beyonddotnetgen`).
30+
- Since you've provided no arguments, the generator should show its usage screen.
31+
- Currently, the generator takes a single required argument: `PathToConfig.json`.
32+
- Create a [config file](#generator-config).
33+
- Run the generator with the path to the config file as the first and only argument (`./beyonddotnetgen /Path/To/Config.json`).
34+
- If the generator was successful it will exit with 0 as exit code and not print anything to stdout or stderr.
35+
- If errors were encountered they'll appear in terminal.
36+
37+
38+
## Generator Config
39+
40+
**Minimal example:**
41+
42+
```
43+
{
44+
"AssemblyPath": "/Path/To/Target/.NET/Assembly.dll",
45+
46+
"CSharpUnmanagedOutputPath": "/Path/To/Generated/CSharpUnmanaged/Output.cs",
47+
"COutputPath": "/Path/To/Generated/C/Output.h",
48+
"SwiftOutputPath": "/Path/To/Generated/Swift/Output.swift"
49+
}
50+
```
51+
52+
- `AssemblyPath`: Enter the path to the compiled .NET assembly you want to generate native bindings for. (Required)
53+
- `CSharpUnmanagedOutputPath`: The generator will use this path to write the generated file containing the C# wrapper methods. (Required)
54+
- `COutputPath`: The generator will use this path to write the generated C bindings header file. (Required)
55+
- `SwiftOutputPath`: The generator will use this path to write the generated Swift bindings file. (Optional)
56+
- All paths can either be absolute or relative to the config file.
57+
58+
There are several other optional options that control the behavior of the generator:
59+
60+
- EmitUnsupported (Boolean)
61+
- GenerateTypeCheckedDestroyMethods (Boolean)
62+
- EnableGenericsSupport (Boolean)
1963

2064

2165
## Memory Management

0 commit comments

Comments
 (0)