{"id":17694332,"url":"https://github.com/sdroege/gobject-example-rs","last_synced_at":"2025-06-26T12:31:50.930Z","repository":{"id":24458459,"uuid":"101659481","full_name":"sdroege/gobject-example-rs","owner":"sdroege","description":"Example for exporting a GObject/C API from Rust","archived":false,"fork":false,"pushed_at":"2024-08-28T07:13:24.000Z","size":116,"stargazers_count":43,"open_issues_count":5,"forks_count":6,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-06-21T13:56:19.401Z","etag":null,"topics":["glib","gnome","gobject","gobject-introspection","gtk","rust","rust-crate"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sdroege.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-28T15:44:50.000Z","updated_at":"2025-02-09T08:12:12.000Z","dependencies_parsed_at":"2024-08-28T08:33:00.460Z","dependency_job_id":"d46bc17f-6d6d-46be-a997-7a980c9428fe","html_url":"https://github.com/sdroege/gobject-example-rs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sdroege/gobject-example-rs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sdroege%2Fgobject-example-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sdroege%2Fgobject-example-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sdroege%2Fgobject-example-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sdroege%2Fgobject-example-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sdroege","download_url":"https://codeload.github.com/sdroege/gobject-example-rs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sdroege%2Fgobject-example-rs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262068020,"owners_count":23253711,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["glib","gnome","gobject","gobject-introspection","gtk","rust","rust-crate"],"created_at":"2024-10-24T13:48:27.557Z","updated_at":"2025-06-26T12:31:50.911Z","avatar_url":"https://github.com/sdroege.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Example for exporting a GObject/C API from Rust\n\nThis repository contains an example [Rust](https://www.rust-lang.org/) crate\nthat can compile to a C-compatible shared library and that exports a\n[GObject](https://developer.gnome.org/gobject/stable) C API.\n\nAt the same time the API provided by this crate can be used directly from Rust\nby statically linking this crate as well as by dynamically linking against the\nC-compatible library. Both variants provide exactly the same Rust API.\n\nIn addition it provides a way to generate [GObject-Introspection](https://gitlab.gnome.org/GNOME/gobject-introspection/)\nmetadata that allows usage from other languages, like [Python](https://gitlab.gnome.org/GNOME/pygobject/) and\n[JavaScript](https://gitlab.gnome.org/GNOME/gjs).\n\n## Implemented Example APIs\n\n### General Structure\n\nEach type comes with 3 Rust modules\n\n  * `mod.rs`: Contains a Rust wrapper of the API. This is basically the same\n    as what [gir](https://github.com/gtk-rs/gir) would autogenerate, and\n    follows the same patterns as the GLib, GTK, etc. bindings.\n  * `imp.rs`: Contains the definition of the types together with the actual\n    private implementation, plus an inline FFI module that exports\n    C-compatible FFI functions.\n  * `ffi.rs`: Contains Rust FFI definitions of the exported C types. This is\n    only used in combination with the `bindings` cargo feature (see below).\n\nand a C header that is (for now, see [issue 6](https://github.com/sdroege/gobject-example-rs/pull/6))\nmanually written.\n\n### Details\n\nPending refactoring in [issue 10](https://github.com/sdroege/gobject-example-rs/issues/10).\n\n## Usage\n\n### Usage from Rust\n\nThe API from the `mod.rs` can directly be used from Rust code and follows the\nsame patterns as the GLib, GTK, etc. bindings.\n\nThere is example usage in the inline tests inside the `mod.rs` of each type.\n\n#### Statically linked crate\n\nThe crate can be directly added as a dependency in some other projects\n`Cargo.toml` and then the API from the individual `mod.rs` is available.\n\nThis statically links the implementation into the application.\n\nRunning `make check` would run tests in this mode.\n\n#### Dynamically linked C library (`bindings` feature)\n\nWhen adding the crate as a dependency and enabling the `bindings` cargo\nfeature then the actual implementation of all the types is omitted. Instead\ndynamic linking against the implementation from the C-compatible shared\nlibrary will happen.\n\nThe API is otherwise exactly the same.\n\nRunning `make check-bindings` would run tests in this mode.\n\n### Usage from C\n\nRunning `cargo build` will create a C-compatible shared library in\n`target/debug/libgobject_example.so`. The corresponding headers for the API\ncan be found in the `include` directory.\n\n`test.c` contains some example usage of the API and `make run-c` compiles and\nruns this.\n\n### Usage from Python\n\nVia [gobject-introspection](https://gitlab.gnome.org/GNOME/gobject-introspection/)\na `Ex-0.1.typelib` file is created. This can be used by [pygobject](https://gitlab.gnome.org/GNOME/pygobject/)\nto expose the API directly to Python.\n\n`test.py` contains some example usage of the API and `make run-python` runs this.\n\n### Usage from JavaScript/GJS\n\nVia [gobject-introspection](https://gitlab.gnome.org/GNOME/gobject-introspection/)\na `Ex-0.1.typelib` file is created. This can be used by [gjs](https://gitlab.gnome.org/GNOME/gjs)\nto expose the API directly to JavaScript. An alternative for [node.js](https://nodejs.org) would\nbe [node-gtk](https://github.com/romgrk/node-gtk).\n\n`test.js` contains some example usage of the API and `make run-gjs` runs this.\n\n### Usage from Vala\n\nVia [gobject-introspection](https://gitlab.gnome.org/GNOME/gobject-introspection/)\na `Ex-0.1.gir` file is created that contains an XML representation of the API.\n[Vala](https://wiki.gnome.org/Projects/Vala) can directly make use of this.\n\n`test.vala` contains some example usage of the API and `make run-vala` runs this.\n\n### Usage from other languages\n\nThe [gobject-introspection](https://gitlab.gnome.org/GNOME/gobject-introspection/)\n`.gir` and `.typelib` files can be used to autogenerate bindings for dozens of\ndifferent languages.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsdroege%2Fgobject-example-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsdroege%2Fgobject-example-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsdroege%2Fgobject-example-rs/lists"}