From b5fa9d36e001252b22bd438c8c807f15e0f05ed7 Mon Sep 17 00:00:00 2001 From: Theodore Tsirpanis Date: Mon, 21 Nov 2022 13:21:00 +0200 Subject: [PATCH 1/3] Add an MSBuild script that downloads the C headers from GitHub Releases and generates bindings. --- .gitignore | 2 +- .../GenerateBindings/GenerateBindings.csproj | 20 --- scripts/GenerateBindings/Program.cs | 2 - .../generate-bindings/GenerateBindings.proj | 105 +++++++++++ .../header.txt | 0 scripts/generate/README.md | 165 ------------------ scripts/generate/generate.rsp | 35 ---- 7 files changed, 106 insertions(+), 223 deletions(-) delete mode 100644 scripts/GenerateBindings/GenerateBindings.csproj delete mode 100644 scripts/GenerateBindings/Program.cs create mode 100644 scripts/generate-bindings/GenerateBindings.proj rename scripts/{generate => generate-bindings}/header.txt (100%) delete mode 100644 scripts/generate/README.md delete mode 100644 scripts/generate/generate.rsp diff --git a/.gitignore b/.gitignore index be28747e..9d20bca9 100644 --- a/.gitignore +++ b/.gitignore @@ -52,7 +52,7 @@ tiledb.pc .DS_Store include -scripts/nuget/temp +temp *.binlog *.nupkg packages diff --git a/scripts/GenerateBindings/GenerateBindings.csproj b/scripts/GenerateBindings/GenerateBindings.csproj deleted file mode 100644 index 97e74736..00000000 --- a/scripts/GenerateBindings/GenerateBindings.csproj +++ /dev/null @@ -1,20 +0,0 @@ - - - - Exe - net5.0 - enable - enable - - - - $(NETCoreSdkRuntimeIdentifier) - - - - - - - - - diff --git a/scripts/GenerateBindings/Program.cs b/scripts/GenerateBindings/Program.cs deleted file mode 100644 index 39946ea1..00000000 --- a/scripts/GenerateBindings/Program.cs +++ /dev/null @@ -1,2 +0,0 @@ -// See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); diff --git a/scripts/generate-bindings/GenerateBindings.proj b/scripts/generate-bindings/GenerateBindings.proj new file mode 100644 index 00000000..f497af75 --- /dev/null +++ b/scripts/generate-bindings/GenerateBindings.proj @@ -0,0 +1,105 @@ + + + ./header.txt + Methods + TileDB.Interop + tiledb + ../../sources/TileDB.CSharp/Interop + ./temp + $(TempDir)/download/include + $(TempDir)/generate.rsp + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + https://github.com/TileDB-Inc/TileDB/releases/download/$(Version)/TileDB-windows-x86_64-$(Version)-$(VersionTag).zip + $(TempDir)/download + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scripts/generate/header.txt b/scripts/generate-bindings/header.txt similarity index 100% rename from scripts/generate/header.txt rename to scripts/generate-bindings/header.txt diff --git a/scripts/generate/README.md b/scripts/generate/README.md deleted file mode 100644 index a2e167ae..00000000 --- a/scripts/generate/README.md +++ /dev/null @@ -1,165 +0,0 @@ -## Generating LibTileDB.cs on macOS: - -Note: prerequisite installation instructions below if needed. - -```sh -export DYLD_LIBRARY_PATH=/path/to/libclang/runtimes/osx-x64/native/ -export TILEDB_DIR=/path/to/TileDB/dist - -dotnet tool restore -dotnet ClangSharpPInvokeGenerator -I /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I $TILEDB_DIR/include/ --file $TILEDB_DIR/include/tiledb/tiledb.h $TILEDB_DIR/include/tiledb/tiledb_experimental.h @scripts/generate/generate.rsp -``` - -## Generating on Windows (PowerShell): - -We assume that the TileDB Core repository is in the same folder with the C# repository's folder, and has been installed. - -```powershell -$TILEDB_DIR=..\TileDB\dist\include - -dotnet tool restore -dotnet ClangSharpPInvokeGenerator -F $TILEDB_DIR -I $TILEDB_DIR "@.\scripts\generate\generate.rsp" -``` - -# Generator Installation - -## macOS - -- Follow instructions [here](https://github.com/dotnet/ClangSharp#building-native) but skip first step (LLVM build) and install from homebrew instead. - - note: if you have macOS 11+, you can use the release builds from LLVM upstream linked [here](https://releases.llvm.org/download.html) to [github release page](https://github.com/llvm/llvm-project/releases). - -- Build `ClangSharpPInvokeGenerator` locally: - - ``` - cd /ClangSharp/sources/ClangSharpPInvokeGenerator - dotnet build - ``` - -- Set DYLD_LIBRARY_PATH for the native `libClangSharp` lib directory: - - ``` - export DYLD_LIBRARY_PATH=/ClangSharp/artifacts/bin/native/lib - ``` - -- Now verify the build with: - - ``` - /ClangSharp/artifacts/bin/sources/ClangSharpPInvokeGenerator/Debug/net6.0/ClangSharpPInvokeGenerator --version - ``` - - (should output 13.0) - -## linux - -Install `dotnet` core SDK - -```bash -sudo apt-get update; \ - sudo apt-get install -y apt-transport-https && \ - sudo apt-get update && \ - sudo apt-get install -y dotnet-sdk-6.0 -``` - -Install Generator - -```bash -dotnet tool install --local ClangSharpPInvokeGenerator --version 14.0.0-beta2 -``` - -Make an alias in `~/.zshrc` - -```bash -vi ~/.zshrc -... -alias csgen=~/.dotnet/tools/ClangSharpPInvokeGenerator -... -source ~/.zshrc -``` - -Install specific version of TileDB in `/usr/local` - -```bash -git clone https://github.com/TileDB-Inc/TileDB.git -b 2.12.0 -mv TileDB TileDB_2.12.0 -cd TileDB_2.12.0 -mkdir build && cd build -#cmake 3.22.2 -cmake -DTILEDB_VERBOSE=OFF -DTILEDB_S3=ON -DTILEDB_SERIALIZATION=ON -DTILEDB_AZURE=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/usr/local .. -make -j12 -sudo make -C tiledb install -``` - -```bash -sudo ldconfig -``` - -Add to `~/.zshrc` - -```python -vi ~/.zshrc -... -export TILEDB_DIR=/usr/local -... -source ~/.zshrc -``` - -Build `libClangSharp` - -ClangSharp provides a helper library, `libClangSharp`, that exposes additional functionality that is not available in `libClang` - -Building this requires [CMake 3.13 or later](https://cmake.org/download/) as well as a version of MSVC or Clang that supports C++ 17. - -Get `clang` - -```bash -cd ~/workspace/tiledb -wget https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.0/clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz -tar -xvf clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz -rm clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz -``` - -Clone generator - -```bash -cd ~/workspace/tiledb -git clone https://github.com/dotnet/clangsharp -cd clangsharp -mkdir artifacts/bin/native -cd artifacts/bin/native -``` - -Build - -```bash -cmake -DPATH_TO_LLVM=~/workspace/tiledb/clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04 ../../.. -make -#cd lib -#sudo cp libClangSharp.so libClangSharp.so.14.0.0 /usr/lib -sudo make install -``` - -```bash -sudo ldconfig -``` - -```bash -sudo cp ~/workspace/tiledb/clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04/lib/libclang.so /usr/local/lib -``` - -```bash -sudo ldconfig -``` - -```bash -cd ~/workspace/tiledb/TileDB-CSharp-tmp -csgen -I $TILEDB_DIR/include/ -I ~/workspace/tiledb/clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04/lib/clang/14.0.0/include/ --file $TILEDB_DIR/include/tiledb/tiledb.h $TILEDB_DIR/include/tiledb/tiledb_experimental.h @scripts/generate/generate.rsp -l libtiledb -``` - -`~/workspace/tiledb/TileDB-CSharp-tmp/sources/TileDB.CSharp/Interop/Methods.cs` should be updated - -In `~/workspace/tiledb/TileDB-CSharp-tmp/sources/TileDB.CSharp/Interop/Methods.cs` do - -```bash -- Comment all *_dump functions -- Remove duplicate signatures From `MethodsExperimental.cs` (currently all signatures are duplicated) -``` diff --git a/scripts/generate/generate.rsp b/scripts/generate/generate.rsp deleted file mode 100644 index 40f83b96..00000000 --- a/scripts/generate/generate.rsp +++ /dev/null @@ -1,35 +0,0 @@ ---config -latest-codegen -unix-types -multi-file -generate-helper-types ---methodClassName -Methods ---namespace -TileDB.Interop ---file -tiledb/api/c_api/api_external_common.h -tiledb/api/c_api/config/config_api_external.h -tiledb/api/c_api/context/context_api_external.h -tiledb/api/c_api/error/error_api_external.h -tiledb/api/c_api/filter/filter_api_external.h -tiledb/tiledb_experimental.h -tiledb/tiledb.h ---output -sources/TileDB.CSharp/Interop ---headerFile -./scripts/generate/header.txt ---exclude -tiledb_attribute_dump -tiledb_domain_dump -tiledb_dimension_dump -tiledb_array_schema_dump -tiledb_stats_dump -tiledb_stats_raw_dump -tiledb_fragment_info_dump -tiledb_status ---remap -tiledb_experimental_query_status_details_t=tiledb_query_status_details_t -tiledb_ctx_handle_t=tiledb_ctx_t -tiledb_filter_handle_t=tiledb_filter_t --ltiledb From c906650baa47fe76408a9ecc4fff21b04c51f09b Mon Sep 17 00:00:00 2001 From: Theodore Tsirpanis Date: Mon, 21 Nov 2022 17:09:34 +0200 Subject: [PATCH 2/3] Add a CI workflow that updates the bindings. --- .github/workflows/generate-bindings.yml | 45 +++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/generate-bindings.yml diff --git a/.github/workflows/generate-bindings.yml b/.github/workflows/generate-bindings.yml new file mode 100644 index 00000000..9f5cd4da --- /dev/null +++ b/.github/workflows/generate-bindings.yml @@ -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}}' From ec09c088532d29f6377b249d7395be166ecfd08e Mon Sep 17 00:00:00 2001 From: Theodore Tsirpanis Date: Mon, 5 Dec 2022 10:54:06 +0200 Subject: [PATCH 3/3] Add a README of the binding generation script. --- scripts/generate-bindings/README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 scripts/generate-bindings/README.md diff --git a/scripts/generate-bindings/README.md b/scripts/generate-bindings/README.md new file mode 100644 index 00000000..75ababde --- /dev/null +++ b/scripts/generate-bindings/README.md @@ -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= -p:VersionTag= /restore` command. + +Only Windows is supported.