Skip to content

Commit

Permalink
Generate datafusion.h automatically (#12)
Browse files Browse the repository at this point in the history
fix #11
  • Loading branch information
kou committed Jun 15, 2022
1 parent ac74977 commit 8b0882c
Show file tree
Hide file tree
Showing 11 changed files with 523 additions and 296 deletions.
63 changes: 49 additions & 14 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ jobs:
- uses: actions-rs/toolchain@v1
id: rust-toolchain
with:
toolchain: stable
override: true
components: rustfmt, clippy
override: true
toolchain: stable
- name: Cache Cargo
uses: actions/cache@v3
with:
Expand Down Expand Up @@ -107,15 +107,18 @@ jobs:
- uses: actions-rs/toolchain@v1
id: rust-toolchain
with:
# For cargo's --out-dir option
# toolchain: stable
toolchain: nightly
override: true
toolchain: stable
- name: Cache Cargo
uses: actions/cache@v2
with:
path: ~/.cargo
key: cargo-test-${{ matrix.runs-on }}-${{ steps.rust-toolchain.outputs.rustc_hash }}-${{ hashFiles('Cargo.lock') }}
- name: Install cargo-c
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-c
- name: Prepare on Ubuntu
if: |
matrix.runs-on == 'ubuntu-latest'
Expand All @@ -140,46 +143,78 @@ jobs:
# run: |
# pip install meson
- name: Setup on non-Windows
# Enable this once https://github.com/mesonbuild/meson/pull/10476
# is fixed.
# if: |
# matrix.runs-on != 'windows-latest'
if: |
matrix.runs-on != 'windows-latest'
matrix.runs-on == 'ubuntu-latest'
run: |
meson setup -Ddoc=true -Dvala=true -Dwerror=true build .
- name: Build on non-Windows
# Enable this once https://github.com/mesonbuild/meson/pull/10476
# is fixed.
# if: |
# matrix.runs-on != 'windows-latest'
if: |
matrix.runs-on != 'windows-latest'
matrix.runs-on == 'ubuntu-latest'
run: |
ninja -C build
- name: Build on Windows
# Enable this once https://github.com/mesonbuild/meson/pull/10476
# is fixed.
# if: |
# matrix.runs-on == 'windows-latest'
if: |
matrix.runs-on == 'windows-latest'
matrix.runs-on == 'windows-latest' || matrix.runs-on == 'macos-latest'
uses: actions-rs/cargo@v1
with:
command: build
command: cbuild
- name: Test
# Enable this once https://github.com/mesonbuild/meson/pull/10476
# is fixed.
# if: |
# matrix.runs-on != 'windows-latest'
if: |
matrix.runs-on != 'windows-latest'
matrix.runs-on == 'ubuntu-latest'
run: |
cd build
bundle exec ../test/run.sh
- name: Run C example
# Enable this once https://github.com/mesonbuild/meson/pull/10476
# is fixed.
# if: |
# matrix.runs-on != 'windows-latest'
if: |
matrix.runs-on != 'windows-latest'
matrix.runs-on == 'ubuntu-latest'
run: |
build/examples/sql-c
- name: Run Vala example
# Enable this once https://github.com/mesonbuild/meson/pull/10476
# is fixed.
# if: |
# matrix.runs-on != 'windows-latest'
if: |
matrix.runs-on != 'windows-latest'
matrix.runs-on == 'ubuntu-latest'
run: |
build/examples/sql-vala
- name: Run Python example
# Enable this once https://github.com/mesonbuild/meson/pull/10476
# is fixed.
# if: |
# matrix.runs-on != 'windows-latest'
if: |
matrix.runs-on != 'windows-latest'
matrix.runs-on == 'ubuntu-latest'
run: |
cd build
../examples/sql.py
- name: Run Ruby example
# Enable this once https://github.com/mesonbuild/meson/pull/10476
# is fixed.
# if: |
# matrix.runs-on != 'windows-latest'
if: |
matrix.runs-on != 'windows-latest'
matrix.runs-on == 'ubuntu-latest'
run: |
cd build
../examples/sql.rb
9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
[package]
name = "datafusion-c"
description = "DataFusion C API"
version = "1.0.0"
version = "8.0.0"
homepage = "https://github.com/datafusion-contrib/datafusion-c"
repository = "https://github.com/datafusion-contrib/datafusion-c"
readme = "README.md"
Expand All @@ -36,10 +36,13 @@ crate-type = ["cdylib"]
name = "datafusion"

[features]
default = []
default = ["capi"]
capi = []

[dependencies]
datafusion = "8"
libc = "0.2"
tokio = "1"
# { version = "1.0" , features = ["macros", "rt", "rt-multi-thread", "sync", "fs", "parking_lot"] }

[package.metadata.capi.header]
subdirectory = false
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ C language bindings for DataFusion.

## How to build

Install dependencies:

```bash
cargo install cargo-c
```

### Without GLib API

```bash
Expand Down
70 changes: 70 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!#/usr/bin/env python3
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

import argparse
import os
import platform
import shutil
import subprocess

parser = argparse.ArgumentParser(description='Build and copy artifacts '
'to the current directory')
parser.add_argument('--version',
action='store',
dest='version',
help='Shared object version',
metavar='VERSION',
required=True)
parser.add_argument('--shared-object',
dest='shared_object',
help='Path to shared object',
metavar='SHARED_OBJECT',
required=True)
parser.add_argument('--file',
action='append',
dest='files',
help='Path to not shared object file '
'(can be used multiple times)',
metavar='DATA')
parser.add_argument('command_line', nargs='*')
args = parser.parse_args()


subprocess.run(args.command_line, check=True)


shared_object_base = os.path.basename(args.shared_object)
if platform.system() == 'Linux':
version_major = args.version.split('.')[0]
shutil.copy2(args.shared_object, f'{shared_object_base}.{args.version}')
def ln_fs(src, dest):
try:
os.remove(dest)
except FileNotFoundError:
pass
os.symlink(src, dest)
ln_fs(f'{shared_object_base}.{args.version}',
f'{shared_object_base}.{version_major}')
ln_fs(f'{shared_object_base}.{version_major}',
f'{shared_object_base}')
else:
shutil.copy2(args.shared_object, '.')

for file in args.files:
shutil.copy2(file, '.')
20 changes: 20 additions & 0 deletions cbindgen.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

language = "C"

pragma_once = true
4 changes: 2 additions & 2 deletions datafusion-glib/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ enums = gnome.mkenums('enums',
symbol_prefix: 'gdf',
c_template: 'enums.c.template',
h_template: 'enums.h.template',
install_dir: join_paths(include_dir, 'datafusion-glib'),
install_dir: include_dir / 'datafusion-glib',
install_header: true)
enums_source = enums[0]
enums_header = enums[1]
Expand Down Expand Up @@ -80,7 +80,7 @@ pkgconfig.generate(libdatafusion_glib,
filebase: 'datafusion-glib',
name: 'DataFusion GLib',
requires: ['gobject-2.0', 'datafusion'],
version: meson.project_version())
version: version)

if have_gi
datafusion_glib_gir = \
Expand Down
20 changes: 10 additions & 10 deletions doc/datafusion-glib/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,36 @@ entities_conf.set('PACKAGE_BUGREPORT',
'https://github.com/datafusion-contrib/datafusion-c/issues')
entities_conf.set('PACKAGE_NAME', package_name)
entities_conf.set('PACKAGE_STRING',
' '.join([package_name, meson.project_version()]))
' '.join([package_name, version]))
entities_conf.set('PACKAGE_URL',
'https://github.com/datafusion-contrib/datafusion-c')
entities_conf.set('PACKAGE_VERSION', meson.project_version())
entities_conf.set('PACKAGE_VERSION', version)
configure_file(input: 'entities.xml.in',
output: 'entities.xml',
configuration: entities_conf)

glib_prefix = dependency('glib-2.0').get_pkgconfig_variable('prefix')
glib_doc_path = join_paths(glib_prefix, 'share', 'gtk-doc', 'html')
doc_path = join_paths(data_dir, 'gtk-doc', 'html', package_id)
glib_doc_path = glib_prefix / 'share' / 'gtk-doc' / 'html'
doc_path = data_dir / 'gtk-doc' / 'html' / package_id

dependencies = [
datafusion_glib,
]
html_images = []
ignore_headers = [
join_paths(meson.source_root(), 'datafusion-glib', 'data-frame-raw.h'),
join_paths(meson.source_root(), 'datafusion-glib', 'session-context-raw.h'),
meson.source_root() / 'datafusion-glib' / 'data-frame-raw.h',
meson.source_root() / 'datafusion-glib' / 'session-context-raw.h',
]
source_directories = [
join_paths(meson.source_root(), package_id),
join_paths(meson.build_root(), package_id),
meson.source_root() / package_id,
meson.build_root() / package_id,
]
gnome.gtkdoc(package_id,
dependencies: dependencies,
fixxref_args: [
'--html-dir=' + doc_path,
'--extra-dir=' + join_paths(glib_doc_path, 'glib'),
'--extra-dir=' + join_paths(glib_doc_path, 'gobject'),
'--extra-dir=' + (glib_doc_path / 'glib'),
'--extra-dir=' + (glib_doc_path / 'gobject'),
],
gobject_typesfile: package_id + '.types',
html_assets: html_images,
Expand Down
4 changes: 1 addition & 3 deletions examples/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,4 @@ install_data('sql.c',
'sql.py',
'sql.rb',
'sql.vala',
install_dir: join_paths(data_dir,
meson.project_name(),
'example'))
install_dir: data_dir / meson.project_name() / 'example')
Loading

0 comments on commit 8b0882c

Please sign in to comment.