]> git.proxmox.com Git - debcargo-conf.git/blame - README.rst
Revert last revert
[debcargo-conf.git] / README.rst
CommitLineData
89606032
XL
1.. contents::
2
3Packaging a crate for Debian
4============================
d580884e 5
c9806f32 6To get set up, run at Debian unstable (recommended)::
1057693c 7
4333698e 8 apt update && apt install debcargo
1057693c
XL
9
10Then for each new package:
23db3623 11
8960a81d
XL
12To package a new crate, or to update an existing crate
13------------------------------------------------------
931eabc0 14
8960a81d
XL
15::
16
17 ./new-package.sh <rust-crate-name> # or
18 ./update.sh <rust-crate-name>
86e10bdd 19
6c1b3182
XL
20and follow its instructions.
21
8960a81d 22Note that ``new-package.sh`` is just a symlink to ``update.sh``, to help newcomers.
7b976234 23
1ff2ded3
XL
24To package a co-installable older version of a crate
25----------------------------------------------------
7b976234 26
6c1b3182 27To maintain an old version of a crate alongside the latest one, first make sure
8960a81d 28the latest version is packaged by doing all of the above, then run::
6c1b3182 29
8960a81d
XL
30 ./new-package.sh <rust-crate-name> <old-version> # or
31 ./update.sh <rust-crate-name> <old-version>
86e10bdd 32
fed17d69
XL
33and follow its instructions. To save time, you can first copy anything relevant
34from ``src/<rust-crate-name>`` to ``src/<rust-crate-name>-<old-version>``, then
35adapt it as needed.
999f9269 36
8960a81d
XL
37To prepare a release
38--------------------
39
40::
5cbe2f60 41
699de4ac
SL
42 ./release.sh <rust-crate-name> # or
43 ./release.sh <rust-crate-name> <old-version> # as appropriate
44 DISTRO=experimental ./release.sh <rust-crate-name> # to target another distro
86e10bdd 45
fed17d69
XL
46This prepares the necessary Debian files in ``build/``, and creates a git
47branch to manage the packaging until it is accepted in Debian itself. You need
48to run additional commands after this - more specific instructions are given to
49you about this, by the script after you run it.
6c1b3182 50
8960a81d
XL
51Holding packages at old versions
52--------------------------------
53
54If you need to keep the latest version in Debian at an older version than is
55released on crates.io, e.g. to upload an important bugfix without being blocked
56on having to package all the dependencies of the newest version, you can::
57
58 REALVER=<old-version> ./update.sh <rust-crate-name> # then
59 REALVER=<old-version> ./release.sh <rust-crate-name>
60
c6709bfe
XL
61Repackaging the existing revision
62---------------------------------
63
64In order to build a package A already in ``debcargo-conf/src``
65in the exact version which is present here, do the following::
66
67 $ ./repackage.sh A
68 $ cd build
69 $ ./build.sh A
70
71If this package is already in the archive and you want to recreate that
72exactly, you will need to use the exact same version of debcargo that was
73used previously. This version is mentioned in ``debian/changelog``.
74
d580884e 75
c6709bfe
XL
76Build environment
77=================
78
79To set up a suitable build environment for ``./build.sh``::
80
745a5a63 81 $ sudo apt-get install devscripts reprepro debootstrap sbuild dh-cargo schroot autopkgtest
c6709bfe
XL
82 $ sudo sbuild-createchroot --include=eatmydata,ccache,gnupg,dh-cargo,cargo,lintian,perl-openssl-defaults \
83 --chroot-prefix debcargo-unstable unstable \
84 /srv/chroot/debcargo-unstable-amd64-sbuild http://deb.debian.org/debian
85
1ff2ded3
XL
86An explanation of this, plus more recipes, can be found on the `sbuild wiki
87page <https://wiki.debian.org/sbuild>`_.
88
1e197466
MC
89If you need to pass additional options to sbuild, like "--arch=i386", then set
90the SBUILD_OPTS environment variable.
91
c6709bfe
XL
92Normally, ``./build.sh`` will fail early if not all the build dependencies are
93available in your local apt cache. If you are packaging a large dependency tree
94however, to avoid many round-trips through NEW it is possible to bypass this
95check and build all the packages together. Suppose package B depends on package
96A, then you can run something like::
97
98 $ export IGNORE_MISSING_BUILD_DEPS=1
99 $ ./release.sh A
100 $ ( cd build && ./build.sh A )
101 # push pending and checkout master
102 $ ./release.sh B
103 $ ( cd build && ./build.sh B librust-A*.deb )
104
105The extra arguments after ``./build.sh B <args>`` is extra deb files to pass to
106sbuild to use as dependencies. In this case, ``librust-A*.deb`` should have
e313fb0f
BN
107been built by the previous step. Alternatively, use the environment variable
108``EXTRA_DEBS``, like so: ::
109
110 $ EXTRA_DEBS=librust-A*.deb ./build.sh B
111 $ EXTRA_DEBS=librust-A.deb,librust-B.deb ./build.sh C
c6709bfe
XL
112
113After everything is built successfully, you can ``dput`` all of them and then
114push all the ``pending-*`` branches as normal.
115
116
89606032
XL
117Repository structure
118====================
119
120``pending-*`` branches are managed by ``./release.sh``, so please don't manage
121them yourself as you will interfere with the working of that script. The
122intention is that they should only differ from the master branch by 1 commit,
123i.e. the ``dch -r`` commit created by ``./release.sh``.
124
125If you want to create separate non-master branches, that is fine - just don't
126call them ``pending-*`` and don't run ``./release.sh`` on those branches. If you
127want to test your crate, instead run::
128
129 cd build && [SOURCEONLY=1] ./build.sh <rust-crate-name> [<old-version>]
130
131omitting or not omitting the stuff in [] as needed.
132
133Like many other Debian git repositories, we don't follow "feature branch"
134practises here. We generally don't package just 1 or 2 rust crates at a time,
135but all of its dependencies and sometimes some reverse-dependencies too. So
136normally we'll be touching a few dozen packages at once. In this context, it's
137good to merge often, to avoid conflicts with someone else that might also need
138to touch those too in the next few days.
139
140To match a release (i.e. a ``.deb`` or a ``.dsc`` file) to a commit, find the
141commit message that actually says "Release package X". This will usually be a
142merge commit.
143
144
145Expert mode & packaging multiple packages
146=========================================
147
148You should get used to the single-packaging workflow a bit first, including
149doing a few `test builds <#build-environment>`_ of your package. Otherwise the
150instructions below may seem a bit opaque.
151
1521. ``rm -rf build/* && sbuild-update -udr debcargo-unstable-amd64-sbuild`` -
153 clears out your build directory, making the subsequent steps a bit faster.
1542. ``./update.sh <CRATE>`` for all your relevant packages
1553. Do any manual updates.
94d1ee96 1564. ``cd build`` then ``IGNORE_MISSING_BUILD_DEPS=1 ./build.sh <CRATE> *.deb``
89606032
XL
157 for all your relevant packages, in dependency order.
1585. Deal with any issues that come up.
1596. Push your updates to our git.
1607. Run ``dev/list-rdeps <CRATE> [<CRATE> ...]`` on all the crates you updated.
161 Any reverse-dependencies that are affected, also need to be updated and you
162 should repeat steps 1-7 (including this step) for them as well, until this
163 step lists no new packages that are affected.
1648. ``./release.sh <CRATE>`` for all the packages you updated, running the build
165 again if necessary. It may be possible to do this out of dependency order,
166 assuming you didn't have to make significant changes in step (5). If you
167 did, then this step also has to be done in dependency order.
1689. Push your ``pending-*`` branches to our git.
169
170I like to have 4 shell windows open for this:
171
1721. To do the manual updates.
1732. To explore git, to remember what step you're on and to lookup previous
174 reference material.
1753. To explore the build directory, e.g. logs and crate source code.
94d1ee96
XL
1764. To run a build. Try to have one running here at all times, for the next
177 package you didn't look at yet, to save time waiting.
89606032
XL
178
179There are also various scripts in ``dev/*`` that might help you. They should
180have a couple lines at the top of the source code describing their
181functionality and some brief usage instructions.
182
183Whew, thanks for all your work!
184
185
7f68b728
XL
186General packaging tips
187======================
188
189Dependencies on clippy
190----------------------
191
192Patch away dependencies on "clippy" unless it is a "real" dependency. Usually
193crates only use clippy to lint themselves and it is not a "real" dependency
194in the sense that they actually import clippy's code for what they do.
195
89606032
XL
196If you want to be sure, ``rg clippy`` and check that all the usages of it are
197inside ``cfg_attr`` declarations. If so, then just get rid of it.
7f68b728 198
738135f9
XL
199OS-specific crates
200------------------
201
202See redox-syscall for examples on how to deal with these.
203
204If this is unclear, ask on IRC.
205
7f68b728
XL
206Architecture-specific crates
207----------------------------
01f68998 208
738135f9 209This is a bit harder. Usually there are two options:
95399141 210
738135f9
XL
2111. The crate should build a dummy/no-op version of itself "out-of-the-box"
212 on the architectures it doesn't work on.
2132. Dependent crates should depend on it with a platform-specific dependency,
214 see https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#platform-specific-dependencies
215
216(1) involves less burden for others, both for dependent crates and for us
217packagers, since we don't have to override d/rules to ignore test failures on
218non-working architectures. You should communicate to upstream that this is
219the preferred approach.
220
221In the case of (2), the crate should document exactly what conditional should
222be used, and keep this documentation up-to-date. This allows us to easily
223determine if dependent crates are using the correct conditional. You will then
224have to override d/rules for this crate, see src/simd for an example.
225
226You should file a bug upstream if the crate does neither (1) nor document the
227conditions for (2), e.g. https://github.com/hsivonen/simd/issues/25
228
229(Actually the above applies even for "OS-specific crates" but then (2) is
230obvious so documentation is less necessary, and dependent crates all do it
231correctly already.)
95399141 232
c9063851
AK
233Setting collapse_features in debcargo.conf
234------------------------------------------
235
236Rust and Debian have a two different levels of abstraction when handling dependencies and the
237relationship between them. In rust the lowest level is a feature, and in Debian it's the binary
238package.
239
240This means that the following dependency chain is not a problem in rust:
241
242- crate A with feature AX depends on crate B with feature BY
243- crate B with feature BX depends on crate A with feature AY
244
245This is a perfectly valid situation in the rust+cargo ecosystem. Notice that
246there is no dependency cycle on the per-feature level, and this is enforced by
247cargo; but if collapse_features is used then package A+AX+AY would cyclicly
248depend on package B+BX+BY.
249
250This is reflected in the Debian packages by producing `Provides` lines for all combinations
251of features, and this can become a quite large section.
252
253Setting `collapse_features = true` in debcargo.toml removes this behaviour and is recommended,
254but it can lead to dependency cycles of debian packages, if that happens those must be
255broken up by having some or all of the packages set this feature to false.
256
a0c73b1a
XL
257Changed orig tarballs
258---------------------
259
260Sometimes the orig.tar generated by debcargo might change e.g. if you are using
261a newer version of debcargo and one of the dependencies relating to generating
262the tarball was updated and its behaviour changed - compression settings,
263tarball archive ordering, etc. This will cause your upload to get REJECTED by
264the Debian FTP archive for having a different orig.tar. In this case, set
1ff2ded3 265``REUSE_EXISTING_ORIG_TARBALL=1`` when running ``./release.sh``.
a0c73b1a 266
7f68b728
XL
267ITPs
268----
95399141 269
7f68b728 270Don't file ITPs for library crates, but do file them for binary crates.
01f68998 271
1ff2ded3
XL
272Generally we'll be uploading a dozen crates or so at once. Submitting ITPs for
273these is unnecessary since we're the only ones uploading and there is no chance
274of conflict. It would only be spam for the bug tracker. Please instead
275co-ordinate uploads on the ``#debian-rust`` IRC channel.
01f68998 276
0d1e2247
SL
277Testing
278-------
279
dc94b1d5
XL
280Debian has two types of tests:
281
1ff2ded3
XL
2821. pre-install tests run in ``debian/rules``
2832. post-install tests defined in ``debian/tests/control``
dc94b1d5
XL
284
285For Debian rust packages, in (1) we run the crate's test suite with default
286features but only if there are no dev-dependencies, and in (2) we run the whole
1ff2ded3
XL
287test suite with each feature enabled separately plus ``--no-default-features``
288and ``--all-features``.
dc94b1d5
XL
289
290Sometimes, tests require extra tweaks and settings to work. In this case, you
291can tweak ``debian/rules`` for (1), and for (2) you will simply have to mark
292the relevant tests as broken using ``test_is_broken = true``. See the existing
293crate configs for examples.
294
295Other times, the tests are simply broken or can't be run in Debian. In this
296case you should disable the test in (1) by running ``dh_auto_test -- build``
297instead of the default ``dh_auto_test -- test --all``, and for (2) again you
298should mark the relevant tests as broken.
b8798cdc
SL
299These tests are going to be marked as flaky in autopkgtest, still executed but
300won't fail the autopkgtest run.
dc94b1d5 301
ef62445b
SL
302Currently, using debcargo, it is not possible to add new dependencies as part
303of an autopkgtest run. See https://salsa.debian.org/rust-team/debcargo/-/merge_requests/24
304Instead, just override ``debian/tests/control``. See ``src/cbindgen/`` as
305example.
306
dc94b1d5
XL
307Please note that ``[packages.lib]\ntest_is_broken = true`` will transitively
308disable tests for all combinations of features. Sometimes this is correct e.g.
309if the test actually breaks for all features. Sometimes this is *not* correct,
310e.g. if the test only breaks for ``--no-default-features``. In the latter case
311you should instead patch the crate to ignore those tests when the relevant
1ff2ded3 312features are absent - e.g. ``src/regex-automata/debian/patches/ignore-std-tests.patch``.
01f68998 313
a1872536
XL
314Binary-crate has "required-features"
315------------------------------------
316
317See ``src/dotenv`` for an example on dealing with this.
318
319Binary-crate has conflicting name
320---------------------------------
321
322See ``src/fd-find`` for an example on dealing with this.
323
053e604c
SL
324Updating the dependencies
325-------------------------
326
ed1eaac5
XL
327In some cases, libraries/programs are forcing an old version of a library as
328dependencies. In order to limit the number of duplicated libraries in the
329archive, please try to evaluate if a newer version of the dependencies could be
330used.
331
1ff2ded3 332To achieve that, after ``./update.sh``, try::
ed1eaac5
XL
333
334 $ cd build/<package>/
335 $ rm -rf .pc # sometimes this is necessary due to minor debcargo bug
336 $ quilt push -a
337 $ quilt new relax-dep.diff
338 $ quilt edit Cargo.toml
16650581 339 $ quilt header -e --dep3
ed1eaac5
XL
340 $ quilt refresh
341 $ cargo build # check that it works. if it does, then
342 $ cp -R patches ../../src/<package>/debian
343
344Suppose you want to change the dependency from 0.3 to 0.5. If the crate builds
345with no further source changes, then we would change the required version in
346``Cargo.toml`` from ``0.3`` to ``>= 0.3, < 0.6`` or something like that. Then
347the convention is to put all these changes into a single patch called
348``relax-dep-versions.patch``.
349
350OTOH, if the cargo build fails, and you can fix it up by editing the source
351code in a minor way to use the new crate API, then: for each crate that needs
352to be updated, you should instead name the patch ``update-dep-<crate>.patch``
1ff2ded3
XL
353and add both the ``Cargo.toml`` and the source code changes to it. The change
354to ``Cargo.toml`` would then simply say (e.g.) ``0.5`` since the older versions
355actually don't work, and not the version range from the previous paragraph.
e4d0e3d6 356
870cacd0
RK
357If you want to make a crate work with an older dependency version than listed
358in ``Cargo.toml`` (for example 0.3 instead of 0.5), you cannot use a flexible
359version requirement like ``>= 0.3, < 0.6``. Instead you have to specify only
360the older version, in this example ``0.3`` (`explanation`_).
361
362.. _explanation: https://salsa.debian.org/rust-team/debcargo-conf/merge_requests/86#note_135456
363
16650581 364Information on patch headers is available in `dep3`_.
932e534e 365Use (some of) the headers to explain **why** the patch exists.
16650581 366
367.. _dep3: https://dep-team.pages.debian.net/deps/dep3/
368
e4d0e3d6
XL
369Help, something went wrong!
370---------------------------
371
372Sometimes, the error messages are not the most informative. In this case you
373can try re-running the command with ``RUST_BACKTRACE=1``. If you are using the
374``debcargo`` from Debian's own repositories, you should also install the
375``debcargo-dbgsym`` package, otherwise the stack trace will be next to useless.
376Make sure you have the `debug repository <https://wiki.debian.org/HowToGetABacktrace#Installing_the_debugging_symbols>`_
377enabled in your APT sources.
65c5dc9d
GS
378
379
380Some ramblings
381--------------
382
383In ``#debian-rust`` came these two blog posts along with the remark of _good read_
8c68fe9c
GS
384 * https://blog.hackeriet.no/packaging-a-rust-project-for-debian/
385 * https://blog.hackeriet.no/packaging-rust-part-II/
65c5dc9d 386
16650581 387Now are they, those two blog posts, parked here. Waiting for better integration.
901609d8
GS
388
389
390Developing Rust code using Debian-packaged crates
391=================================================
392
393While perhaps not the stated intention, the Rust ecosystem in Debian
394is actually quite usable for developing Rust code in general. Thanks
395to `source replacement
396<https://doc.rust-lang.org/cargo/reference/source-replacement.html>`_,
397Cargo can be configured to use only local, Debian-provided packages by
844ab706
GS
398placing something like the following in ``~/.cargo/config.toml`` (for
399user-wide effect) or in a given project's ``.cargo/config.toml``::
901609d8
GS
400
401 [net]
402 offline = true
403
404 [source]
405
406 [source.crates-io]
407 replace-with = "debian"
408
409 [source.debian]
1e1d8645 410 directory = "/usr/share/cargo/registry"
901609d8
GS
411
412In this state, Cargo will only look for crates installed as Debian
413packages on the local system.