Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically generate bindings. #147

Merged
merged 3 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/generate-bindings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Generate-Bindings

run-name: 'Update bindings to version ${{inputs.version}}-${{inputs.commit_id}}'

on:
workflow_dispatch:
inputs:
version:
description: 'TileDB version to generate bindings for'
required: true
type: string
commit_id:
description: 'Commit ID of the version'
required: true
type: string

jobs:
Generate-Bindings:
runs-on: windows-latest
steps:
# Checks out repository
- uses: actions/checkout@v3

- name: Remove existing .NET versions
shell: bash
run: |
rm -rf $DOTNET_ROOT

- name: Set up .NET SDK from global.json
uses: actions/setup-dotnet@v3

- name: Display .NET versions
run: dotnet --info

- name: Run the binding generation script
run: dotnet msbuild ./scripts/generate-bindings/GenerateBindings.proj -p:Version=${{ inputs.version }} -p:VersionTag=${{ inputs.commit_id }} /restore

- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
branch: bindings-update/${{ inputs.version }}
draft: true
assignees: teo-tsirpanis
title: 'Update bindings to version ${{inputs.version}}-${{inputs.commit_id}}'
commit-message: 'Update bindings to version ${{inputs.version}}-${{inputs.commit_id}}'
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ tiledb.pc

.DS_Store
include
scripts/nuget/temp
temp
*.binlog
*.nupkg
packages
20 changes: 0 additions & 20 deletions scripts/GenerateBindings/GenerateBindings.csproj

This file was deleted.

2 changes: 0 additions & 2 deletions scripts/GenerateBindings/Program.cs

This file was deleted.

105 changes: 105 additions & 0 deletions scripts/generate-bindings/GenerateBindings.proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="GenerateBindings">
<PropertyGroup>
<HeaderFile>./header.txt</HeaderFile>
<MethodClass>Methods</MethodClass>
<Namespace>TileDB.Interop</Namespace>
<LibraryName>tiledb</LibraryName>
<OutDir>../../sources/TileDB.CSharp/Interop</OutDir>
<TempDir>./temp</TempDir>
<InputDir>$(TempDir)/download/include</InputDir>
<RspFile>$(TempDir)/generate.rsp</RspFile>
</PropertyGroup>

<ItemGroup>
<ConfigOption Include="latest-codegen" />
<ConfigOption Include="unix-types" />
<ConfigOption Include="multi-file" />
<ConfigOption Include="generate-helper-types" />
<InputFileBefore Include="tiledb/api/c_api/api_external_common.h" />
<InputFile Include="tiledb/tiledb_experimental.h" />
<InputFile Include="tiledb/tiledb.h" />
<RemapHandleType Include="config" />
<RemapHandleType Include="config_iter" />
<RemapHandleType Include="ctx" />
<RemapHandleType Include="error" />
<RemapHandleType Include="filter" />
<RemapHandleType Include="filter_list" />
<Remap Include="@(RemapHandleType->'tiledb_%(Identity)_handle_t=tiledb_%(Identity)_t')" />
<Remap Include="tiledb_experimental_query_status_details_t=tiledb_query_status_details_t" />
<ExcludeDump Include="attribute" />
<ExcludeDump Include="domain" />
<ExcludeDump Include="dimension" />
<ExcludeDump Include="array_schema" />
<ExcludeDump Include="stats" />
<ExcludeDump Include="stats_raw" />
<ExcludeDump Include="fragment_info" />
<ExcludeMethod Include="@(ExcludeDump->'tiledb_%(Identity)_dump')" />
<ExcludeMethod Include="tiledb_status" />
</ItemGroup>

<Target Name="CleanOutput">
<RemoveDir Directories="$(OutDir)" />
</Target>
<Target Name="Clean"
DependsOnTargets="CleanOutput">
<RemoveDir Directories="$(TempDir)" />
</Target>

<Target Name="Restore">
<Exec Command="dotnet tool restore" />
</Target>

<Target Name="DownloadHeaders">
<Error
Condition="'$(Version)' == '' AND '$(VersionTag)' == ''"
Text="Version and VersionTag must be specified." />

<PropertyGroup>
<DownloadUrl>https://github.com/TileDB-Inc/TileDB/releases/download/$(Version)/TileDB-windows-x86_64-$(Version)-$(VersionTag).zip</DownloadUrl>
<ExtractDir>$(TempDir)/download</ExtractDir>
</PropertyGroup>
<DownloadFile
SourceUrl="$(DownloadUrl)"
DestinationFolder="$(TempDir)">
<Output TaskParameter="DownloadedFile" ItemName="DownloadedFile" />
</DownloadFile>
<MakeDir Directories="$(ExtractDir)" />
<Unzip SourceFiles="@(DownloadedFile)" DestinationFolder="$(ExtractDir)" />

<ItemGroup>
<ApiExternalHeaders Include="$(ExtractDir)/include/tiledb/api/c_api/**/*_api_external.h" />
</ItemGroup>
</Target>

<Target Name="GenerateRspFile"
DependsOnTargets="CleanOutput">
<ItemGroup>
<PInvokeGeneratorArg Remove="@(PInvokeGeneratorArg)" />
<PInvokeGeneratorArg Include="--config;@(ConfigOption)" />
<PInvokeGeneratorArg Include="--methodClassName;$(MethodClass)" />
<PInvokeGeneratorArg Include="--namespace;$(Namespace)" />
<PInvokeGeneratorArg Include="--file" />
<PInvokeGeneratorArg Condition="'@(InputFileBefore)' != ''" Include="@(InputFileBefore)" />
<PInvokeGeneratorArg Condition="'@(ApiExternalHeaders)' != ''" Include="@(ApiExternalHeaders->'%(FullPath)')" />
<PInvokeGeneratorArg Include="@(InputFile)" />
<PInvokeGeneratorArg Include="--output;$(OutDir)" />
<PInvokeGeneratorArg Include="--headerFile;$(HeaderFile)" />
<PInvokeGeneratorArg Include="--exclude;@(ExcludeMethod)" />
<PInvokeGeneratorArg Include="--remap;@(Remap)" />
<PInvokeGeneratorArg Include="-l$(LibraryName)" />
<PInvokeGeneratorArg Include="-F;$(InputDir)" />
<PInvokeGeneratorArg Include="-I;$(InputDir)" />
</ItemGroup>

<WriteLinesToFile
File="$(RspFile)"
Lines="@(PInvokeGeneratorArg)"
Overwrite="true"
WriteOnlyWhenDifferent="true" />
</Target>

<Target Name="GenerateBindings"
DependsOnTargets="DownloadHeaders;GenerateRspFile">
<Exec Command="dotnet tool run ClangSharpPInvokeGenerator @&quot;$(RspFile)&quot;" />
</Target>
</Project>
17 changes: 17 additions & 0 deletions scripts/generate-bindings/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generating TileDB native bindings

`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.

## Prerequisites

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.

## Automatic generation

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.

## Manual generation

The script can be ran locally with the `dotnet msbuild ./scripts/generate-bindings/GenerateBindings.proj -p:Version=<version> -p:VersionTag=<commit-id> /restore` command.

Only Windows is supported.
File renamed without changes.
165 changes: 0 additions & 165 deletions scripts/generate/README.md

This file was deleted.

Loading