Skip to content

Commit

Permalink
build(c/driver-manager): Add support to build Vala bindings
Browse files Browse the repository at this point in the history
Vala VAPI file is generated for current GADBC 1.0 API version.

It is disable by default, but recommended to be enable when
a development package is distributed.

This commit force a 1.0 API versioning, replacing the old one
where 0 were used for GIR API version (gir_version), so now
shows '1.0' instead of '0.0'.

Also examples are provided.
  • Loading branch information
esodan committed Oct 4, 2023
1 parent 213cb41 commit 46da11d
Show file tree
Hide file tree
Showing 9 changed files with 282 additions and 2 deletions.
10 changes: 9 additions & 1 deletion glib/adbc-glib/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ pkgconfig.generate(libadbc_glib,
variables: pkgconfig_variables,
version: meson.project_version())

adbc_glib_gir = gnome.generate_gir(libadbc_glib,
if have_gi
adbc_glib_gir = gnome.generate_gir(libadbc_glib,
export_packages: 'adbc-glib',
extra_args: [
'--warn-all',
Expand All @@ -102,3 +103,10 @@ adbc_glib_gir = gnome.generate_gir(libadbc_glib,
nsversion: api_version,
sources: sources + definition_headers + enums,
symbol_prefix: 'gadbc')
if generate_vapi
adbc_glib_vapi = gnome.generate_vapi('adbc-glib',
install: true,
packages: ['gobject-2.0'],
sources: [adbc_glib_gir[0]])
endif
endif
48 changes: 48 additions & 0 deletions glib/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!---
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.
-->

# Arrow GLib example

There are example codes in this directory.

C example codes exist in this directory. Language bindings example
codes exists in sub directories. For example, Lua example codes exists
in `lua/` sub directory.

## C example codes

Here are example codes in this directory:

* `build.c`: It shows how to create an array by array builder.

<!---
* `write-file.c`: It shows how to write Arrow array to file in file
format.
-->

* `read-file.c`: It shows how to read Arrow array from file in file
format.

<!---
* `write-stream.c`: It shows how to write Arrow array to file in
stream format.
-->

* `read-stream.c`: It shows how to read Arrow array from file in
stream format.
27 changes: 27 additions & 0 deletions glib/example/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- indent-tabs-mode: nil -*-
#
# 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.

executable('sqlite', 'sqlite.c',
dependencies: [adbc_glib],
link_language: 'c')

install_data('README.md',
install_dir: join_paths(data_dir, meson.project_name(), 'example'))

subdir('vala')
72 changes: 72 additions & 0 deletions glib/example/sqlite.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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.
*/

#include <stdlib.h>

#include <adbc-glib/adbc-glib.h>

int main(int argc, char** argv) {
GADBCDatabase* database;
GADBCConnection* conn;
GError* error = NULL;

database = gadbc_database_new(&error);

if (error != NULL) {
g_print("Error creating a Database: %s", error->message);
return 1;
}

gadbc_database_set_option(database, "driver", "adbc_driver_sqlite", &error);

if (error != NULL) {
g_print("Error initializing the database: %s", error->message);
return 1;
}

gadbc_database_set_option(database, "uri", "test.db", &error);

if (error != NULL) {
g_print("Error initializing the database: %s", error->message);
return 1;
}

gadbc_database_init(database, &error);

if (error != NULL) {
g_print("Error initializing the database: %s", error->message);
return 1;
}

conn = gadbc_connection_new(&error);

if (error != NULL) {
g_print("Error creating a Connection: %s", error->message);
return 1;
}

gadbc_connection_init(conn, database, &error);

if (error != NULL) {
g_print("Error initializing a Connection: %s", error->message);
return 1;
}

return EXIT_SUCCESS;
}
36 changes: 36 additions & 0 deletions glib/example/vala/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!---
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.
-->

# ADBC Vala example

There are Vala example codes in this directory.

## How to build

Here is a command line to build an example in this directory:

```console
$ valac --pkg adbc-glib --pkg posix XXX.vala
```

## Vala example codes

Here are example codes in this directory:

* `build.vala`: It shows how to create an array by array builder.
42 changes: 42 additions & 0 deletions glib/example/vala/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- indent-tabs-mode: nil -*-
#
# 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.

if generate_vapi
vala_example_executable_kwargs = {
'c_args': [
'-I' + meson.build_root(),
'-I' + meson.source_root(),
],
'dependencies': [
adbc_glib_vapi,
dependency('gobject-2.0'),
],
'vala_args': [
'--pkg', 'posix',
],
}
executable('sqlite', 'sqlite.vala',
kwargs: vala_example_executable_kwargs)
endif

install_data('README.md',
install_dir: join_paths(data_dir,
meson.project_name(),
'example',
'vala'))
33 changes: 33 additions & 0 deletions glib/example/vala/sqlite.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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.


int main (string[] args) {
try {
var database = new GADBC.Database ();
database.set_option ("driver", "adbc_driver_sqlite");
database.set_option ("uri", "test.db");
database.init ();
var conn = new GADBC.Connection ();
conn.init (database);
}
catch (GLib.Error e) {
GLib.message ("Error: %s", e.message);
}

return Posix.EXIT_SUCCESS;
}
11 changes: 10 additions & 1 deletion glib/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ version_major = version_numbers[0].to_int()
version_minor = version_numbers[1].to_int()
version_micro = version_numbers[2].to_int()

api_version = '@0@.0'.format(version_major)
api_version = '1.0'
so_version = version_major
library_version = '.'.join(version_numbers)

Expand All @@ -39,6 +39,7 @@ include_dir = get_option('includedir')
project_include_sub_dir = meson.project_name()
data_dir = get_option('datadir')
gir_dir = prefix / data_dir / 'gir-1.0'
vapi_dir = data_dir / 'vala' / 'vapi'

gnome = import('gnome')
pkgconfig = import('pkgconfig')
Expand Down Expand Up @@ -67,7 +68,15 @@ else
dirs: [adbc_build_dir])
endif

have_gi = dependency('gobject-introspection-1.0', required: false).found()
generate_vapi = have_gi and get_option('vapi')
if generate_vapi
pkgconfig_variables += ['vapidir=@0@'.format(vapi_dir)]
add_languages('vala')
endif

subdir('adbc-glib')
subdir('example')

install_data('../LICENSE.txt',
'README.md',
Expand Down
5 changes: 5 additions & 0 deletions glib/meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ option('adbc_build_dir',
type: 'string',
value: '',
description: 'Use this option to build with not installed ADBC')

option('vapi',
type: 'boolean',
value: false,
description: 'Build Vala API')

0 comments on commit 46da11d

Please sign in to comment.