| 1 |
How to contribute |
| 2 |
================= |
| 3 |
|
| 4 |
Thank you for looking in this document! There are different ways of |
| 5 |
contributing to librsvg, and we appreciate all of them. |
| 6 |
|
| 7 |
All librsvg contributors are expected to follow `GNOME's Code of |
| 8 |
Conduct <https://conduct.gnome.org>`_. |
| 9 |
|
| 10 |
Source repository |
| 11 |
----------------- |
| 12 |
|
| 13 |
Librsvg’s main source repository is at ``gitlab.gnome.org``. You can view |
| 14 |
the web interface here: |
| 15 |
|
| 16 |
https://gitlab.gnome.org/GNOME/librsvg |
| 17 |
|
| 18 |
Development happens in the ``main`` branch. There are also branches for |
| 19 |
stable releases. |
| 20 |
|
| 21 |
Alternatively, you can use the mirror at GitHub: |
| 22 |
|
| 23 |
https://github.com/GNOME/librsvg |
| 24 |
|
| 25 |
Note that we don’t do bug tracking in the GitHub mirror; see the next |
| 26 |
section. |
| 27 |
|
| 28 |
If you need to publish a branch, feel free to do it at any |
| 29 |
publicly-accessible Git hosting service, although ``gitlab.gnome.org`` |
| 30 |
makes things easier for the maintainers of librsvg. |
| 31 |
|
| 32 |
Hacking on librsvg |
| 33 |
------------------ |
| 34 |
|
| 35 |
See the rest of this development guide, especially the chapter on |
| 36 |
:doc:`architecture`, and the tutorial on :doc:`adding_a_property`. |
| 37 |
|
| 38 |
The library’s internals are being documented at |
| 39 |
https://gnome.pages.gitlab.gnome.org/librsvg/internals/rsvg/index.html |
| 40 |
|
| 41 |
What can you hack on? |
| 42 |
|
| 43 |
- `Bugs for |
| 44 |
newcomers <https://gitlab.gnome.org/GNOME/librsvg/-/issues?label_name%5B%5D=4.+Newcomers>`__. |
| 45 |
- `Bugs for intermediate developers, once you are a bit familiar with |
| 46 |
the code |
| 47 |
<https://gitlab.gnome.org/GNOME/librsvg/-/issues/?label_name%5B%5D=Intermediate>`__. |
| 48 |
- Pick something from the `development |
| 49 |
roadmap <https://gnome.pages.gitlab.gnome.org/librsvg/devel-docs/roadmap.html>`__. |
| 50 |
- Tackle one of the `bigger projects |
| 51 |
<https://gitlab.gnome.org/GNOME/librsvg/-/issues/?label_name%5B%5D=project>`_. |
| 52 |
|
| 53 |
Working on the source |
| 54 |
~~~~~~~~~~~~~~~~~~~~~ |
| 55 |
|
| 56 |
Make sure you have read the chapter on :doc:`devel_environment`. |
| 57 |
|
| 58 |
A typical development cycle goes like this: |
| 59 |
|
| 60 |
- Make some changes to the code; hopefully adding a test first. |
| 61 |
- Build and run the tests. Use ``cargo test --workspace``. |
| 62 |
- Repeat until you and the tests are happy. |
| 63 |
|
| 64 |
Most of the time you can just work on the Rust source code and use |
| 65 |
``cargo test --workspace``. This will run the Rust-based tests, which |
| 66 |
are usually enough to test bug fixes in the SVG rendering code. |
| 67 |
|
| 68 |
However, sometimes you'll want to do a full build and run the full |
| 69 |
test suite, which includes the tests for the C API. |
| 70 |
|
| 71 |
To do a full build, you can use something like this: |
| 72 |
|
| 73 |
.. code-block:: sh |
| 74 |
|
| 75 |
mkdir -p _build |
| 76 |
meson setup _build -Ddocs=enabled -Dintrospection=enabled -Dvala=enabled |
| 77 |
meson compile -C _build |
| 78 |
meson test -C _build |
| 79 |
|
| 80 |
Alternatively, you can make a merge request and wait for the |
| 81 |
Continuous Integration machinery (CI) do the full build for you. The |
| 82 |
CI will run all the tests on multiple platforms. |
| 83 |
|
| 84 |
For a full build, librsvg uses the `Meson <https://mesonbuild.com>`_ |
| 85 |
build system. If you need to **add a new source file**, you need to |
| 86 |
do it in ``rsvg/meson.build``. This is so that Meson can know when a |
| 87 |
Rust file changed so it can call ``cargo`` as appropriate. |
| 88 |
|
| 89 |
It is perfectly fine to ask the maintainer if you have questions about |
| 90 |
the Meson setup; it’s a tricky bit of machinery, and we are glad |
| 91 |
to help. |
| 92 |
|
| 93 |
Continuous Integration |
| 94 |
~~~~~~~~~~~~~~~~~~~~~~ |
| 95 |
|
| 96 |
If you fork librsvg in ``gitlab.gnome.org`` and push commits to your |
| 97 |
forked version, the Continuous Integration machinery (CI) will run |
| 98 |
automatically. |
| 99 |
|
| 100 |
The CI infrastructure is documented in the :doc:`ci` chapter. |
| 101 |
|
| 102 |
When you create a merge request, or push to a branch in a fork of |
| 103 |
librsvg, GitLab's CI will run a *pipeline* on the contents of your |
| 104 |
push: it will run the test suite, linters, try to build the |
| 105 |
documentation, and generally see if everything that makes |
| 106 |
:doc:`product` is working as intended. If any tests fail, the |
| 107 |
pipeline will fail and you can then examine the build artifacts of |
| 108 |
failed jobs to fix things. |
| 109 |
|
| 110 |
**Automating the code formatting:** You may want to enable a |
| 111 |
`client-side git |
| 112 |
hook <https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks>`__ to |
| 113 |
run ``rustfmt`` before you can commit something; otherwise the ``lint`` |
| 114 |
stage of CI pipelines will fail: |
| 115 |
|
| 116 |
1. ``cd librsvg`` |
| 117 |
|
| 118 |
2. ``mv .git/hooks/pre-commit.sample .git/hooks/pre-commit`` |
| 119 |
|
| 120 |
3. Edit ``.git/hooks/pre-commit`` and put in one of the following |
| 121 |
commands: |
| 122 |
|
| 123 |
- If you want code reformatted automatically, no questions asked: |
| 124 |
``cargo fmt``. |
| 125 |
|
| 126 |
.. note:: |
| 127 |
|
| 128 |
If this actually reformats your code while committing, you’ll |
| 129 |
have to re-stage the new changes and ``git commit --amend``. |
| 130 |
Be careful if you had unstaged changes that got reformatted! |
| 131 |
|
| 132 |
- If you want to examine errors if rustfmt doesn’t like your |
| 133 |
indentation, but don’t want it to make changes on its own: |
| 134 |
``cargo fmt --all -- --check`` |
| 135 |
|
| 136 |
Test suite |
| 137 |
~~~~~~~~~~ |
| 138 |
|
| 139 |
All new features need to have corresponding tests. Please see the |
| 140 |
file ``rsvg/tests/README.md`` to see how to add new tests to the test suite. In short: |
| 141 |
|
| 142 |
- Add unit tests in the ``rsvg/src/*.rs`` files for internal things like |
| 143 |
parsers or algorithms. |
| 144 |
|
| 145 |
- Add rendering tests in ``rsvg/tests/src/*.rs`` for SVG or CSS features. |
| 146 |
See ``rsvg/tests/README.md`` for details on how to do this. |
| 147 |
|
| 148 |
- Tests for the C API go in ``librsvg-c/test-c/*.c``. Note that to |
| 149 |
run these tests you must run a full meson build, not just ``cargo |
| 150 |
test --workspace``. |
| 151 |
|
| 152 |
- Tests for ``rsvg-convert`` go in ``rsvg_convert/tests/*.rs``. |
| 153 |
|
| 154 |
In most cases, you can run ``cargo test --workspace`` if you set up your |
| 155 |
development environment as instructed in the :doc:`devel_environment` |
| 156 |
chapter. Alternatively, push your changes to a branch, and watch the |
| 157 |
results of its CI pipeline. |
| 158 |
|
| 159 |
Creating a merge request |
| 160 |
~~~~~~~~~~~~~~~~~~~~~~~~ |
| 161 |
|
| 162 |
You may create a forked version of librsvg in `GNOME’s Gitlab instance |
| 163 |
<https://gitlab.gnome.org/GNOME/librsvg>`__,. You can register an |
| 164 |
account there, or log in with your account from other OAuth services. |
| 165 |
|
| 166 |
For technical reasons, the maintainers of librsvg do not get |
| 167 |
automatically notified if you submit a pull request through the GNOME |
| 168 |
mirror in GitHub. In that case, please create a merge request at |
| 169 |
``gitlab.gnome.org`` instead; you can ask the maintainer for assistance. |
| 170 |
|
| 171 |
Formatting commit messages |
| 172 |
~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 173 |
|
| 174 |
If a commit fixes a bug, please format its commit message like this: |
| 175 |
|
| 176 |
:: |
| 177 |
|
| 178 |
(#123): Don't crash when foo is bar |
| 179 |
|
| 180 |
Explanation for why the crash happened, or anything that is not |
| 181 |
obvious from looking at the diff. |
| 182 |
|
| 183 |
Fixes https://gitlab.gnome.org/GNOME/librsvg/issues/123 |
| 184 |
|
| 185 |
Note the ``(#123)`` in the first line. This is the line that shows up in |
| 186 |
single-line git logs, and having the bug number there makes it easier to |
| 187 |
write the release notes later — one does not have to read all the commit |
| 188 |
messages to find the ids of fixed bugs. |
| 189 |
|
| 190 |
Also, please paste the complete URL to the bug report somewhere in the |
| 191 |
commit message, so that it’s easier to visit when reading the commit |
| 192 |
logs. |
| 193 |
|
| 194 |
Generally, commit messages should summarize *what* you did, and *why*. |
| 195 |
Think of someone doing ``git blame`` in the future when trying to figure |
| 196 |
out how some code works: they will want to see *why* a certain line of |
| 197 |
source code is there. The commit where that line was introduced should |
| 198 |
explain it. |
| 199 |
|
| 200 |
Testing performance-related changes |
| 201 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 202 |
|
| 203 |
The ``rsvg-bench`` directory in the source tree has a tool to |
| 204 |
benchmark librsvg. For example, you can ask rsvg-bench to render one |
| 205 |
or more SVGs hundreds of times in a row, so you can take accurate |
| 206 |
timings or run a sampling profiler and get enough samples. |
| 207 |
|
| 208 |
To fully read on and understand the usage of |
| 209 |
``rsvg-bench``, please refer to the :doc:`rsvg_bench` chapter. |
| 210 |
|
| 211 |
It has a comprehensive detail on how to use the tool, and how to |
| 212 |
interpret the results. |
| 213 |
|
| 214 |
Included benchmarks |
| 215 |
~~~~~~~~~~~~~~~~~~~ |
| 216 |
|
| 217 |
The ``rsvg/benches/`` directory has a couple of benchmarks for functions |
| 218 |
related to SVG filter effects. You can run them with ``cargo bench``. |
| 219 |
|
| 220 |
These benchmarks use the |
| 221 |
`Criterion <https://crates.io/crates/criterion>`__ crate, which supports |
| 222 |
some interesting options to generate plots and such. |