Skip to content

Commit 90f901e

Browse files
Automatically generate bindings. (#147)
* Add an MSBuild script that downloads the C headers from GitHub Releases and generates bindings. * Add a CI workflow that updates the bindings. * Add a README of the binding generation script.
1 parent 51eecd7 commit 90f901e

File tree

9 files changed

+168
-223
lines changed

9 files changed

+168
-223
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Generate-Bindings
2+
3+
run-name: 'Update bindings to version ${{inputs.version}}-${{inputs.commit_id}}'
4+
5+
on:
6+
workflow_dispatch:
7+
inputs:
8+
version:
9+
description: 'TileDB version to generate bindings for'
10+
required: true
11+
type: string
12+
commit_id:
13+
description: 'Commit ID of the version'
14+
required: true
15+
type: string
16+
17+
jobs:
18+
Generate-Bindings:
19+
runs-on: windows-latest
20+
steps:
21+
# Checks out repository
22+
- uses: actions/checkout@v3
23+
24+
- name: Remove existing .NET versions
25+
shell: bash
26+
run: |
27+
rm -rf $DOTNET_ROOT
28+
29+
- name: Set up .NET SDK from global.json
30+
uses: actions/setup-dotnet@v3
31+
32+
- name: Display .NET versions
33+
run: dotnet --info
34+
35+
- name: Run the binding generation script
36+
run: dotnet msbuild ./scripts/generate-bindings/GenerateBindings.proj -p:Version=${{ inputs.version }} -p:VersionTag=${{ inputs.commit_id }} /restore
37+
38+
- name: Create Pull Request
39+
uses: peter-evans/create-pull-request@v4
40+
with:
41+
branch: bindings-update/${{ inputs.version }}
42+
draft: true
43+
assignees: teo-tsirpanis
44+
title: 'Update bindings to version ${{inputs.version}}-${{inputs.commit_id}}'
45+
commit-message: 'Update bindings to version ${{inputs.version}}-${{inputs.commit_id}}'

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ tiledb.pc
5252

5353
.DS_Store
5454
include
55-
scripts/nuget/temp
55+
temp
5656
*.binlog
5757
*.nupkg
5858
packages

scripts/GenerateBindings/GenerateBindings.csproj

Lines changed: 0 additions & 20 deletions
This file was deleted.

scripts/GenerateBindings/Program.cs

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="GenerateBindings">
2+
<PropertyGroup>
3+
<HeaderFile>./header.txt</HeaderFile>
4+
<MethodClass>Methods</MethodClass>
5+
<Namespace>TileDB.Interop</Namespace>
6+
<LibraryName>tiledb</LibraryName>
7+
<OutDir>../../sources/TileDB.CSharp/Interop</OutDir>
8+
<TempDir>./temp</TempDir>
9+
<InputDir>$(TempDir)/download/include</InputDir>
10+
<RspFile>$(TempDir)/generate.rsp</RspFile>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<ConfigOption Include="latest-codegen" />
15+
<ConfigOption Include="unix-types" />
16+
<ConfigOption Include="multi-file" />
17+
<ConfigOption Include="generate-helper-types" />
18+
<InputFileBefore Include="tiledb/api/c_api/api_external_common.h" />
19+
<InputFile Include="tiledb/tiledb_experimental.h" />
20+
<InputFile Include="tiledb/tiledb.h" />
21+
<RemapHandleType Include="config" />
22+
<RemapHandleType Include="config_iter" />
23+
<RemapHandleType Include="ctx" />
24+
<RemapHandleType Include="error" />
25+
<RemapHandleType Include="filter" />
26+
<RemapHandleType Include="filter_list" />
27+
<Remap Include="@(RemapHandleType->'tiledb_%(Identity)_handle_t=tiledb_%(Identity)_t')" />
28+
<Remap Include="tiledb_experimental_query_status_details_t=tiledb_query_status_details_t" />
29+
<ExcludeDump Include="attribute" />
30+
<ExcludeDump Include="domain" />
31+
<ExcludeDump Include="dimension" />
32+
<ExcludeDump Include="array_schema" />
33+
<ExcludeDump Include="stats" />
34+
<ExcludeDump Include="stats_raw" />
35+
<ExcludeDump Include="fragment_info" />
36+
<ExcludeMethod Include="@(ExcludeDump->'tiledb_%(Identity)_dump')" />
37+
<ExcludeMethod Include="tiledb_status" />
38+
</ItemGroup>
39+
40+
<Target Name="CleanOutput">
41+
<RemoveDir Directories="$(OutDir)" />
42+
</Target>
43+
<Target Name="Clean"
44+
DependsOnTargets="CleanOutput">
45+
<RemoveDir Directories="$(TempDir)" />
46+
</Target>
47+
48+
<Target Name="Restore">
49+
<Exec Command="dotnet tool restore" />
50+
</Target>
51+
52+
<Target Name="DownloadHeaders">
53+
<Error
54+
Condition="'$(Version)' == '' AND '$(VersionTag)' == ''"
55+
Text="Version and VersionTag must be specified." />
56+
57+
<PropertyGroup>
58+
<DownloadUrl>https://github.com/TileDB-Inc/TileDB/releases/download/$(Version)/TileDB-windows-x86_64-$(Version)-$(VersionTag).zip</DownloadUrl>
59+
<ExtractDir>$(TempDir)/download</ExtractDir>
60+
</PropertyGroup>
61+
<DownloadFile
62+
SourceUrl="$(DownloadUrl)"
63+
DestinationFolder="$(TempDir)">
64+
<Output TaskParameter="DownloadedFile" ItemName="DownloadedFile" />
65+
</DownloadFile>
66+
<MakeDir Directories="$(ExtractDir)" />
67+
<Unzip SourceFiles="@(DownloadedFile)" DestinationFolder="$(ExtractDir)" />
68+
69+
<ItemGroup>
70+
<ApiExternalHeaders Include="$(ExtractDir)/include/tiledb/api/c_api/**/*_api_external.h" />
71+
</ItemGroup>
72+
</Target>
73+
74+
<Target Name="GenerateRspFile"
75+
DependsOnTargets="CleanOutput">
76+
<ItemGroup>
77+
<PInvokeGeneratorArg Remove="@(PInvokeGeneratorArg)" />
78+
<PInvokeGeneratorArg Include="--config;@(ConfigOption)" />
79+
<PInvokeGeneratorArg Include="--methodClassName;$(MethodClass)" />
80+
<PInvokeGeneratorArg Include="--namespace;$(Namespace)" />
81+
<PInvokeGeneratorArg Include="--file" />
82+
<PInvokeGeneratorArg Condition="'@(InputFileBefore)' != ''" Include="@(InputFileBefore)" />
83+
<PInvokeGeneratorArg Condition="'@(ApiExternalHeaders)' != ''" Include="@(ApiExternalHeaders->'%(FullPath)')" />
84+
<PInvokeGeneratorArg Include="@(InputFile)" />
85+
<PInvokeGeneratorArg Include="--output;$(OutDir)" />
86+
<PInvokeGeneratorArg Include="--headerFile;$(HeaderFile)" />
87+
<PInvokeGeneratorArg Include="--exclude;@(ExcludeMethod)" />
88+
<PInvokeGeneratorArg Include="--remap;@(Remap)" />
89+
<PInvokeGeneratorArg Include="-l$(LibraryName)" />
90+
<PInvokeGeneratorArg Include="-F;$(InputDir)" />
91+
<PInvokeGeneratorArg Include="-I;$(InputDir)" />
92+
</ItemGroup>
93+
94+
<WriteLinesToFile
95+
File="$(RspFile)"
96+
Lines="@(PInvokeGeneratorArg)"
97+
Overwrite="true"
98+
WriteOnlyWhenDifferent="true" />
99+
</Target>
100+
101+
<Target Name="GenerateBindings"
102+
DependsOnTargets="DownloadHeaders;GenerateRspFile">
103+
<Exec Command="dotnet tool run ClangSharpPInvokeGenerator @&quot;$(RspFile)&quot;" />
104+
</Target>
105+
</Project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Generating TileDB native bindings
2+
3+
`GenerateBindings.proj` contains an MSBuild script that downloads the header files for a given version and uses `ClangSharpPInvokeGenerator` to generate the C# bindings to the TileDB C API.
4+
5+
## Prerequisites
6+
7+
You need to go to [TileDB's GitHub Releases page](https://github.com/TileDB-Inc/TileDB/releases) and find the version and 7-digit commit ID for your release.
8+
9+
## Automatic generation
10+
11+
The easiest way to generate bindings is by dispatching the [`generate-bindings` workflow](../../.github/workflows/generate-bindings.yml). It will run the script and submit a Pull Request with the changes.
12+
13+
## Manual generation
14+
15+
The script can be ran locally with the `dotnet msbuild ./scripts/generate-bindings/GenerateBindings.proj -p:Version=<version> -p:VersionTag=<commit-id> /restore` command.
16+
17+
Only Windows is supported.
File renamed without changes.

scripts/generate/README.md

Lines changed: 0 additions & 165 deletions
This file was deleted.

0 commit comments

Comments
 (0)