|
| 1 | +#!/usr/bin/env bash |
| 2 | +. "$(dirname "$0")"/common.sh |
| 3 | + |
| 4 | +# Downloads the C library source files of a specific release from GitHub, |
| 5 | +# copies the header files, makes some required modifications |
| 6 | +# and runs the ffigen binding generator on them. |
| 7 | + |
| 8 | +cLibVersion=0.20.0 |
| 9 | +echo "Downloading C library source files from GitHub..." |
| 10 | + |
| 11 | +# Note: the release archives do not contain objectbox-dart.h, so get the full sources. |
| 12 | +archiveExt="zip" |
| 13 | +downloadUrl="https://github.com/objectbox/objectbox-c/archive/refs/tags/v${cLibVersion}.${archiveExt}" |
| 14 | +echo "Download URL: ${downloadUrl}" |
| 15 | + |
| 16 | +targetDir="objectbox/download" |
| 17 | +archiveFile="${targetDir}/objectbox-c-${cLibVersion}.${archiveExt}" |
| 18 | +mkdir -p "$(dirname "${archiveFile}")" |
| 19 | + |
| 20 | +# Support both curl and wget because their availability is platform dependent |
| 21 | +if [ -x "$(command -v curl)" ]; then |
| 22 | + curl --location --fail --output "${archiveFile}" "${downloadUrl}" |
| 23 | +else |
| 24 | + wget --no-verbose --output-document="${archiveFile}" "${downloadUrl}" |
| 25 | +fi |
| 26 | + |
| 27 | +if [[ ! -s ${archiveFile} ]]; then |
| 28 | + echo "Error: download failed (file ${archiveFile} does not exist or is empty)" |
| 29 | + exit 1 |
| 30 | +fi |
| 31 | + |
| 32 | +echo |
| 33 | +echo "Downloaded:" |
| 34 | +du -h "${archiveFile}" |
| 35 | + |
| 36 | +echo |
| 37 | +echo "Extracting into ${targetDir}..." |
| 38 | +unzip "${archiveFile}" -d "${targetDir}" |
| 39 | + |
| 40 | +headerBuildDir="objectbox/lib/src/native/bindings" |
| 41 | +echo |
| 42 | +echo "Copying to ${headerBuildDir}..." |
| 43 | +mkdir -p "${headerBuildDir}" |
| 44 | +cp "${targetDir}/objectbox-c-${cLibVersion}"/include/*.h "${headerBuildDir}" |
| 45 | +ls -l "${headerBuildDir}" |
| 46 | + |
| 47 | +# Replace `const void*` by `const uint8_t*` in all objectbox*.h files |
| 48 | +# (see ffigen note in ../objectbox/pubspec.yaml). |
| 49 | +echo |
| 50 | +echo "Replacing 'const void*' by 'const uint8_t*'..." |
| 51 | +replaceVoidExpr="s/const void\*/const uint8_t*/g" |
| 52 | +update objectbox/lib/src/native/bindings/objectbox.h "${replaceVoidExpr}" |
| 53 | +update objectbox/lib/src/native/bindings/objectbox-dart.h "${replaceVoidExpr}" |
| 54 | +update objectbox/lib/src/native/bindings/objectbox-sync.h "${replaceVoidExpr}" |
| 55 | + |
| 56 | +# This requires LLVM libraries |
| 57 | +# (see ffigen docs https://pub.dev/packages/ffigen#installing-llvm |
| 58 | +# and the ffigen section in ../objectbox/pubspec.yaml). |
| 59 | +echo |
| 60 | +echo "Generating bindings with ffigen (requires LLVM libraries)..." |
| 61 | +cd objectbox |
| 62 | +dart run ffigen |
0 commit comments