Debian Codegraph @

devel-docs/devel_environment.rst

raw
1 Setting up your development environment
2 =======================================
3
4 This chapter will help you set your development environment for librsvg.
5
6 System requirements
7 -------------------
8
9 - A 64-bit installation of Linux.
10
11 - 8 GB of RAM, or 16 GB recommended if you will be running the full
12 test suite frequently.
13
14 - Around 10 GB free of hard disk space.
15
16 - You can either use `podman <https://podman.io/>`_ to work in a
17 containerized setup (this chapter will show you how), or you can
18 install librsvg's dependencies by hand.
19
20 - Make sure you have ``git`` installed.
21
22 - Your favorite text editor. We recommend a text editor configured to
23 use the Language Server Protocol plus `rust-analyzer
24 <https://rust-analyzer.github.io/>`_ so you can get autocompletion
25 and documentation of librsvg's internals within your editor.
26
27 Downloading the source code
28 ---------------------------
29
30 .. code-block:: sh
31
32 git clone https://gitlab.gnome.org/GNOME/librsvg.git
33
34
35 .. _podman_setup:
36
37 Setting up with podman
38 ----------------------
39
40 An easy way to set up a development environment is to use `podman
41 <https://podman.io/>`_ to download and run a container image. This is
42 similar to having a ``chroot`` with all of librsvg's dependencies
43 already set up.
44
45 Install ``podman`` on your distro, and then:
46
47 .. code-block:: sh
48
49 cd librsvg # wherever you did your "git clone"
50 sh ci/pull-container-image.sh
51
52 In the librsvg source tree, ``ci/pull-container-image.sh`` is a script
53 that will invoke ``podman pull`` to download the container image that
54 you can use for development. It is the same image that librsvg uses
55 for its continuous integration pipeline (CI), so you can have exactly
56 the same setup on your own machine.
57
58 That ``pull-container-image.sh`` script will give you instructions
59 similar to these:
60
61 .. code-block:: text
62
63 You can now run this:
64 podman run --rm -ti --cap-add=SYS_PTRACE -v $(pwd):/srv/project:z -w /srv/project $image_name
65
66 Don't forget to run this once inside the container:
67 source ci/env.sh
68 source ci/setup-dependencies-env.sh
69
70 You can cut&paste those commands (from the script's output, not from
71 this document!). The first one should give you a shell prompt inside
72 the container. The second and third ones will make Rust available in
73 the shell's environment, and adjust some environment variables so that
74 the compilation process can find the installed dependencies.
75
76 What's all that magic? Let's dissect the podman command line:
77
78 - ``podman run`` - run a specific container image. The image name is
79 the last parameter in that command; it will look something like
80 ``registry.gitlab.gnome.org/gnome/librsvg/opensuse/tumbleweed:x86_64-1.60.0-2022-08-17.0-main``.
81 This is an image built on on a base of the openSUSE Tumbleweed, a
82 rolling distribution of Linux with very recent dependencies.
83
84 - ``--rm`` - Remove the container after exiting. It will terminate
85 when you ``exit`` the container's shell.
86
87 - ``-ti`` - Set up an interactive session.
88
89 - ``--cap-add=SYS_PTRACE`` - Make it possible to run ``gdb`` inside the container.
90
91 - ``-v $(pwd):/srv/project:z` - Mount the current directory as
92 ``/srv/project`` inside the container. This lets you build from
93 your current source tree without first copying it into the
94 container; it will be available in ``/srv/project``. The ``:z`` at
95 the end is so that if your host distro uses selinux, it will label
96 the mounted volume properly (it does nothing if you are not on
97 selinux).
98
99 Finally, don't forget to ``source ci/env.sh`` and ``source
100 ci/setup-dependencies-env.sh`` once you are inside ``podman run``.
101
102 You can now skip to :ref:`build`.
103
104 .. _manual_setup:
105
106 Setting up dependencies manually
107 --------------------------------
108
109 .. include:: _build_dependencies.rst
110
111 The following sections describe how to install these dependencies on
112 several systems. For fully manual builds, you can try using the
113 script in ``ci/build-dependencies.sh``. Librsvg's continuous
114 integration (CI) infrastructure uses that script to install the
115 dependencies before building.
116
117 Debian based systems
118 ~~~~~~~~~~~~~~~~~~~~
119
120 As of 2018/Feb/22, librsvg cannot be built in ``debian stable`` and
121 ``ubuntu 18.04``, as they have packages that are too old.
122
123 **Build dependencies on Debian Testing or Ubuntu 18.10:**
124
125 .. code-block:: sh
126
127 apt-get install -y gcc rustc cargo cargo-c ninja-build \
128 meson gi-docgen python3-docutils git \
129 libgdk-pixbuf2.0-dev libgirepository1.0-dev \
130 libxml2-dev libcairo2-dev libpango1.0-dev
131
132 Additionally, as of September 2018 you need to add ``gdk-pixbuf``
133 utilities to your path, see :issue:`331` for details:
134
135 .. code-block:: sh
136
137 PATH="$PATH:/usr/lib/x86_64-linux-gnu/gdk-pixbuf-2.0"
138
139 Fedora based systems
140 ~~~~~~~~~~~~~~~~~~~~
141
142 .. code-block:: sh
143
144 dnf install -y gcc rust rust-std-static cargo cargo-c ninja-build \
145 meson gi-docgen python3-docutils git redhat-rpm-config \
146 gdk-pixbuf2-devel gobject-introspection-devel \
147 libxml2-devel cairo-devel cairo-gobject-devel pango-devel
148
149 openSUSE based systems
150 ~~~~~~~~~~~~~~~~~~~~~~
151
152 .. code-block:: sh
153
154 zypper install -y gcc rust rust-std cargo cargo-c ninja \
155 meson python3-gi-docgen python38-docutils git \
156 gdk-pixbuf-devel gobject-introspection-devel \
157 libxml2-devel cairo-devel pango-devel
158
159 macOS systems
160 ~~~~~~~~~~~~~
161
162 Dependencies may be installed using `Homebrew <https://brew.sh>`_ or another
163 package manager.
164
165 .. code-block:: sh
166
167 brew install meson gi-docgen pkgconfig gobject-introspection gdk-pixbuf pango
168
169 .. _build:
170
171 Building and testing
172 --------------------
173
174 Make sure you have gone through the steps in :ref:`podman_setup` or
175 :ref:`manual_setup`. Then, do the following.
176
177 **Normal development:** You can use ``cargo build`` and
178 ``cargo test`` as for a simple Rust project; this is what
179 you will use most of the time during regular development. If you are
180 using the podman container as per above, you should do this in the
181 ``/srv/project`` directory most of the time.
182
183 After compiling with those commands, you can use the ``rsvg-convert``
184 binary to casually test rendering an SVG file, for example, one that
185 has a feature that you are developing. You can run
186 ``target/debug/rsvg-convert -o output.png my_test_file.svg``.
187
188 If you do a release build with ``cargo build --release``, which includes
189 optimizations, the binary will be in ``target/release/rsvg-convert``.
190 This version is *much* faster than the debug version.
191
192 **Doing a full build:** You can use the following:
193
194 .. code-block:: sh
195
196 mkdir -p _build
197 meson setup _build -Ddocs=enabled -Dintrospection=enabled -Dvala=enabled
198 meson compile -C _build
199 meson test -C _build
200
201 You should only have to do that if you need to run the full test
202 suite, for the C API tests and the tests for limiting memory
203 consumption.
204
205
206
207 .. _podman: https://podman.io/