Debian Codegraph @

book/src/tutorial/preparation.md

raw
1 # Preparation
2 In order to install gir and nicely structure the project, there are a few things to set up.
3
4 ## Set up the project folder
5 In order to keep the project folder nicely organized, let's create a folder where we will work in and initialize the repo.
6 We will create two library crates.
7 pango will contain the safe wrapper crate and because it is a wrapper for the unsafe bindings, we create the pango-sys crate within the pango crate.
8 If no Cargo.toml file is present in the sys create, a new one will be generated, so let's be safe and delete the automatically created file before we begin.
9 The following commands will set up the project folder as described.
10
11 ```sh
12 mkdir gir-tutorial
13 cd gir-tutorial/
14 git init
15 cargo new pango --lib
16 cd pango
17 cargo new pango-sys --lib
18 rm pango-sys/Cargo.toml
19 ```
20 We will also create a file called "Gir.toml" in each of the crates.
21 ```sh
22 touch Gir.toml
23 touch pango-sys/Gir.toml
24 cd ..
25 ```
26
27 ## Installing gir
28 Of course we also need to download and install [gir].
29 ```sh
30 git submodule add https://github.com/gtk-rs/gir
31 git config -f .gitmodules submodule.gir.update none
32 git submodule set-branch --branch main -- gir
33 cd gir
34 cargo install --path .
35 cd ..
36 ```
37 By adding it as a submodule, we are able to fetch future updates of the tool and we always exactly know which gir version we used to generate our bindings.
38 We also change the setting so that the submodule is not automatically checked out, otherwise anyone using your library from git will have the useless submodule checked out.
39 Run `git submodule update --checkout` if you want to update the submodule.
40 Then we set the branch of the submodule to main.
41
42 If there are any updates to gir in the future, we can install them by opening our project folder `gir-tutorial` and running
43 ```sh
44 git submodule update --remote
45 cd gir
46 cargo install --path .
47 cd ..
48 ```
49
50 ## Summary
51 You should now have a folder looking like this:
52 ```text
53 gir
54 |
55 |---- ...
56 pango/
57 |
58 |---- Cargo.toml
59 |---- Gir.toml
60 |---- pango-sys/
61 | |
62 | |---- Gir.toml
63 | |---- src/
64 | |
65 | |---- lib.rs
66 |---- src/
67 |
68 |---- lib.rs
69 .git
70 |
71 |---- ...
72 .gitmodules
73 ```
74
75 Now that we installed gir and prepared our project folder, let's get the .gir files.
76
77 [gir]: https://github.com/gtk-rs/gir