Debian Codegraph @

book/src/config/ffi.md

raw
1 # FFI Options
2
3 In FFI (`-m sys`) mode, `gir` generates as much as it can.
4 So in this mode, the TOML file is mostly used to ignore some objects.
5 To do so, you need to add its fullname to an `ignore` array.
6 Example:
7
8 ```toml
9 ignore = ["Gtk.Widget", "Gtk.Window"]
10 ```
11
12 And that's all.
13 Neither `GtkWidget` nor `GtkWindow` (alongside with their functions) will be generated.
14
15 You also need to add any needed external libraries in the "external_libraries" parameter.
16 Example:
17
18 ```toml
19 [options]
20 external_libraries = [
21 "GLib",
22 "GObject",
23 ]
24 ```
25
26 You can specify a few other options:
27
28 ```toml
29 [options]
30 girs_directories = ["../gir-files"]
31 library = "GtkSource"
32 version = "3.0"
33 min_cfg_version = "3.0"
34 target_path = "."
35 # Path where lib.rs generated (defaults to <target_path>/src)
36 # auto_path = "src"
37 work_mode = "sys"
38 # If true then build.rs will be split into 2 parts:
39 # always generated build_version.rs,
40 # and build.rs that generated only if not exists.
41 # Defaults to false
42 split_build_rs = false
43 # Adds extra versions to features
44 extra_versions = [
45 "3.15",
46 "3.17",
47 ]
48 # Change library version for version
49 [[lib_version_overrides]]
50 version = "3.16"
51 lib_version = "3.16.1"
52 # Add extra dependencies to feature
53 [[feature_dependencies]]
54 version = "3.16"
55 dependencies = [
56 "glib-sys/v3_16"
57 ]
58 ```
59
60 Also, you can add rust cfg conditions on objects, functions and constants, for example, when flagging for conditional compilation:
61
62 ```toml
63 [[object]]
64 name = "GstGL.GLDisplayEGL"
65 status = "generate"
66 cfg_condition = "feature = \"egl\""
67 [[object.function]]
68 pattern = ".*"
69 cfg_condition = "feature = \"egl\""
70 ```
71
72 ## Generation in FFI mode
73
74 When you're ready, let's generate the FFI part.
75 In the command we'll execute, `../gir-files` is where the directory with your `.gir` files is.
76 (But again, you can just clone the [gir-files repository](https://github.com/gtk-rs/gir-files) and add your file(s) in it).
77 Then let's run the command:
78
79 ```sh
80 cargo run --release -- -c YourSysGirFile.toml -d ../gir-files -m sys -o the-output-directory-sys
81 ```
82
83 The generated files will be placed in `the-output-directory-sys`.
84 Just take care about the dependencies and the crate's name generated in the `Cargo.toml` file (update them if they don't work as expected).
85
86 You now have the sys part of your binding!