rustc/debian
2017-07-17 21:04:42 +02:00
..
bin Enable optional tests, and add verbosity/backtraces to tests 2016-02-09 21:24:26 +01:00
icons Replace 32x32 logo with local file 2015-07-20 10:26:40 +10:00
patches Add a strong check that rustc_llvm is actually dynamically-linked 2017-07-17 19:17:32 +02:00
source Fix bootstrapping and rename the tarball to orig-stage0 2017-05-31 15:57:51 +02:00
upstream Update debian/watch file 2015-02-24 10:52:29 +01:00
.gitignore Try to support cross-compiling 2017-05-31 01:00:14 +02:00
architecture-test.mk Fix bootstrapping and rename the tarball to orig-stage0 2017-05-31 15:57:51 +02:00
architecture.mk Compatibility fixes and improvements to help work better on Ubuntu 2017-02-27 13:34:51 +01:00
build-preview-dsc.sh Add disclaimer about build-preview-dsc.sh, remove done TODO item 2017-05-31 16:03:09 +02:00
changelog Update patches, update d/changelog 2017-07-17 16:52:18 +02:00
compat Back to dh 9, use binutils instead of binutils-multiarch 2017-02-27 14:12:37 +01:00
config.toml.in Update config.toml, lintian-overrides 2017-07-17 21:04:42 +02:00
control Work around #839145 2017-07-17 20:01:19 +02:00
copyright Update d/copyright 2017-07-17 16:58:49 +02:00
crate-copyright.py Update d/copyright, d/control 2017-05-16 18:00:31 +02:00
docs Numerous minor rust-doc fixups 2015-02-27 09:50:00 +00:00
ensure-patch Don't allow fuzz when applying patches 2017-06-16 13:25:22 +02:00
gbp.conf Avoid having to do --git-ignore-branch every time 2017-06-14 00:47:56 +02:00
get-stage0.py Fix bootstrapping and rename the tarball to orig-stage0 2017-05-31 15:57:51 +02:00
libstd-rust-1.18.lintian-overrides Update config.toml, lintian-overrides 2017-07-17 21:04:42 +02:00
libstd-rust-dev.install Split out library packages for multiarch 2015-05-27 18:02:10 +10:00
libstd-rust-dev.lintian-overrides Split out library packages for multiarch 2015-05-27 18:02:10 +10:00
make_orig-stage0_tarball.sh Fix bootstrapping and rename the tarball to orig-stage0 2017-05-31 15:57:51 +02:00
README.Debian Use Multi-Arch: allowed, it's more correct than : foreign 2017-06-27 13:55:37 +02:00
README.source Doc fixes and tweaks 2017-05-31 16:38:29 +02:00
rules Update config.toml, lintian-overrides 2017-07-17 21:04:42 +02:00
rust-doc.doc-base.book Numerous minor rust-doc fixups 2015-02-27 09:50:00 +00:00
rust-doc.doc-base.intro Remove EPUB from doc-base files 2015-07-19 22:50:26 +10:00
rust-doc.doc-base.reference Upstream don't seem to be building reference.pdf any more 2016-11-07 14:14:53 +01:00
rust-doc.docs Split out library packages for multiarch 2015-05-27 18:02:10 +10:00
rust-doc.install Replace 32x32 logo with local file 2015-07-20 10:26:40 +10:00
rust-doc.links Use system highlight.js 2017-05-16 13:11:10 +02:00
rust-gdb.install Install debugger_pretty_printers_common to rust-gdb and rust-lldb 2016-11-07 12:36:22 +01:00
rust-gdb.links Link rust-{gdb,lldb}.1 to {gdb,lldb}.1 manpages 2015-07-20 11:16:25 +10:00
rust-lldb.install Install debugger_pretty_printers_common to rust-gdb and rust-lldb 2016-11-07 12:36:22 +01:00
rust-lldb.links Fix rust-lldb symlink 2017-03-02 23:00:39 +01:00
rust-src.install Clean out lintian-warning stuff from rust-src 2017-05-16 13:03:29 +02:00
rust-src.links Simpler way of doing the rust-src package 2017-05-16 01:23:25 +02:00
rustc.install Fix architecture.mk install path 2015-05-27 18:02:10 +10:00
rustc.manpages Rename rust binary package to rustc 2015-02-27 09:50:00 +00:00
TODO.Debian Bump the LLVM requirement to fix FTBFS on armhf 2017-06-14 09:26:28 +02:00
update-version.sh Use Multi-Arch: allowed, it's more correct than : foreign 2017-06-27 13:55:37 +02:00
watch Update debian/watch 2016-12-23 16:20:15 +01:00

Document by Luca Bruno & Sylvestre Ledru

This source package is unfortunately quite tricky and with
several cutting edges, due to the complexity of rust-lang
bootstrapping system and the high rate of language changes
still ongoing.

We try to describe here inner packaging details and the
reasons behind them.


Import of a new upstream version
================================

$ uscan
$ gbp import-orig --upstream-branch=upstream/experimental --debian-branch=debian/experimental ../rustc_X.YY.0+dfsg1.orig.tar.xz
$ dch -v X.YY.0+dfsg1-1
$ debian/rules update-version
# might also need to bump the version of the cargo Build-Depends


Embedded libraries
==================

This source package embeds several external libraries (foeked and managed
by rust upstream as git submodules).
In early stages, many more libraries were forked/emebedded but we are steadily
progressing in splitting them out.

Here below the remaining ones, with the technical reasons.

 * jemalloc from https://github.com/rust-lang/jemalloc
   -> system-wide one can't be used due to rust using a "je_" prefix.

   This is intentional upstream design and won't change soon, see:
    - https://github.com/rust-lang/rust/pull/18678
    - http://smallcultfollowing.com/babysteps/blog/2014/11/14/allocators-in-rust/

 * compiler-rt from https://github.com/rust-lang/compiler-rt
   -> system-wide compiler-rt fails during linkage

   Bug reported upstream, still to be fixed, see:
    - https://github.com/rust-lang/rust/issues/15054
    - https://github.com/rust-lang/rust/issues/15708

As a summary, we plan to:
 * keep embedding jemalloc (probably forever)
 * work with upstream to fix compiler-rt linkage soon.

 -- Sylvestre Ledru <sylvestre@debian.org>  Sat, 06 May 2017 13:26:08 +0200


Building from source
====================

The Debian rustc package will use the system rustc to bootstrap itself from.
The system rustc has to be either the previous or the same version as the rustc
being built; the build will fail if this is not the case.

    sudo apt-get build-dep ./
    dpkg-buildpackage
    # Or, to directly use what's in the Debian FTP archive
    sudo apt-get build-dep rustc
    apt-get source --compile rustc

Alternatively, you may give the "pkg.rustc.dlstage0" DEB_BUILD_PROFILE to
instead use the process defined by Rust upstream. This downloads the "official"
stage0 compiler for the version being built from rust-lang.org. At the time of
writing "official" means "the previous stable version".

    sudo apt-get build-dep -P pkg.rustc.dlstage0 ./
    dpkg-buildpackage
    # Or, to directly use what's in the Debian FTP archive
    sudo apt-get build-dep -P pkg.rustc.dlstage0 rustc
    apt-get source --compile -P pkg.rustc.dlstage0 rustc

After [1] is fixed, both of these should in theory give identical results.

If neither of these options are acceptable to you, e.g. because your distro
does not have rustc already and your build process cannot access the network,
see "Bootstrapping" below.

[1] https://github.com/rust-lang/rust/issues/34902


Bootstrapping
=============

To bootstrap rustc on a distro that does not have it or cargo available on any
architecture (so cross-compiling is not an option) you can run `debian/rules
source_orig-stage0`. This creates a .dsc that does not Build-Depend on rustc or
cargo. Instead, it includes an extra orig-stage0 source tarball that contains
the official stage0 compiler, pre-downloaded from rust-lang.org so that your
build daemons don't need to access the network during the build.

    debian/rules source_orig-stage0
    # Follow the final manual instructions that it outputs. Then:
    sbuild ../rustc_*.dsc && dput ../rustc_*.dsc

To only bootstrap specific architectures, run this instead:

    upstream_bootstrap_arch="arm64 armhf" debian/rules source_orig-stage0

This way, other architectures will be omitted from the orig-stage0 tarball. You
might want to do this e.g. if these other architectures are already present in
your distro, but the $upstream_bootstrap_arch ones are not yet present.

Notes
-----

The approach bundles the upstream bootstrapping binaries inside the Debian
source package. This is a nasty hack that stretches the definition of "source
package", but has a few advantages explained below.

The traditional Debian way of bootstrapping compilers - and other distros have
similar approaches - is some variant of the following:

1. A developer locally installs some upstream bootstrapping binaries.
2. They locally build a Debian package, using these binaries as undeclared
   build dependencies.
3. They upload these binary packages to Debian, which can be used as declared
   Build-Depends in the future, including by the same package.

The problem with this is, Debian does not have any policy nor infrastructure
that can try to reproduce what this developer supposedly did.

Using bootstrapping binary blobs *at some point of the process* is unavoidable.
Rather than pretending we didn't do this, it is better to record *which blobs*
we used, so it can be audited later. If we bundle non-Debian build-dependencies
inside the source package, then we can do a *source-only upload*, and the
building of the binary packages can be done by the normal build infrastructure.

If the build process is reproducible [1] then we can be sure that *you* (as the
developer that prepared the source-only upload) didn't backdoor the binaries,
nor did the build daemons even if they were compromised during the build.

The bootstrapping binaries may still have been backdoored, but this is true in
both scenarios. So our arrangement is still a strict improvement in security,
because it reduces the set of "things that may have been backdoored". Also,
more people use the upstream binaries than the "magical original Debian
package", so backdoors have a greater chance of being detected in the former.

In the long run, this process is laying the foundations for doing Diverse
Double-Compilation [2], where we use *many independent* bootstrapping binaries
to reproduce bit-for-bit identical output compilers, giving confidence that
nothing was backdoored along the way.

[1] The build process for rustc is currently *not* reproducible but we're
    working towards it. https://github.com/rust-lang/rust/issues/34902
[2] http://www.dwheeler.com/trusting-trust/