13303
Comment: Add a note on removing toolchains/architectures
|
13589
|
Deletions are marked like this. | Additions are marked like this. |
Line 161: | Line 161: |
== Removing a crosstoolchain == If you want to remove a cross-toolchain and the corresponding foreign architecture entirely then you need to remove all the :arch packages before you run dpkg --remove-architecture arch. This one-liner should work: |
== Removal == This is currently the same on all suites. You can just use whatever package tools you like to remove crossbuild-essential-<arch> or gcc-<triplet> in the usual way. However if youhave installed cross-build-deps then there may well be a lot of foreign-architecture -dev packages installed. If you want to remove all foreign-arch packages and the corresponding foreign architecture entirely then you need to remove all the :arch packages before you run dpkg --remove-architecture arch. This one-liner should work: |
Line 168: | Line 172: |
CrossToolchains
This is in flux
This document describes cross-toolchains in Debian. Some of this is now in unstable, but only cross-binutils-* is in Jessie - other Jessie-compatible packages are available in the Debian Cross-toolchains repo. Some of this is still plans and packages in experimental, intended to be released in Stretch.
Contents
-
CrossToolchains
- Related pages
- Status of cross-toolchains in the Debian archive
- Status of cross-toolchains in Ubuntu
- Installation
- Removal
- Future cross-toolchain implementation (currently experimental)
- Installation concepts for experimental
- Which packages are what?
- Installing build-dependencies
- Information for package maintainers
- How does this _really_ work
Related pages
ToolChain/Cross : Overview of toolchain build methods
alioth cross-toolchain team where team is listed and code resides
MultiarchCrossToolchainBuild : Info on building toolchains using multiarch methods
CoinstallableToolchains : Scheme to allow co-installable compilers
toolchain/BootstrapIssues : Breakage found when building debian crosstoolchains (might save you some time!)
Sprints/2014/BootstrapSprint/Results : Crossbuild sprint report discussing various crossbuild/toolchain issues
Talks:
Pages of largely historical interest:
Status of cross-toolchains in the Debian archive
In jessie/testing
- cross-binutils (targetting arm64, armel, armhf, amd64,, i386, mips, mipsel, powerpc, ppc64el)
Other packages are available from the Debian Cross-toolchains repository. See 'Installation' below.
In unstable
- cross-binutils
- cross-gcc packages built from gcc-4.9 only for amd64, targeting the linux architectures supported in Debian: armel, armhf, arm64, mips, mipsel, powerpc, ppc64el gcc, g++ and gfortran cross-compilers are provided
- cross-gcc-defaults metapackages which provide symlinks to the current version of the compilers (so that 'arm-linux-gnueabi-gcc' works when the compiler binary is actually arm-linux-gnueabi-gcc-4.9
In experimental
- crossbuild-essential metapackage to pull in gcc, g++, libc-dev:arch and dpkg-cross (for autoconf and cmake cache/toolchain file support)
Status of cross-toolchains in Ubuntu
Current details are given on https://wiki.ubuntu.com/ToolChain#Cross_development_toolchain
If you have an Ubuntu system, cross-toolchains (i386 & amd64->armel) have been included since 10.10/Maverick. From 12.10/Quantal onwards there are crossbuild-essential-<arch> convenience packages to install cross toolchains, cross-pkgconfig and (multiarch) cross-libc. Armel then armhf were initially supported. Arm64, powerpc and ppc64el were added later.
All these toolchains search multiarch library and header paths by default so are suitable for multiarch crossbuilding.
Installation
For jessie/testing
Cross-toolchains for jessie are available, but only cross-binutils is in the main archive. Other packages come from an external repository.
The toolchains install on amd64 and i386 machines, targeting the jessie release architectures:
- arm64
- armel
- armhf
- mips
- mipsel
- powerpc
- ppc64el
Currently cpp, gcc, g++, and gfortran are built. It's easy to build more languages so ask if you have a need. gccgo and gobjc will be added soon.
These packages did not make it into Jessie so you need to install them from the Debian Cross-toolchains repository. Create /etc/apt/sources.list.d/crosstools.list containing:
deb http://emdebian.org/tools/debian/ jessie main
You will need the archive key installed.
curl http://emdebian.org/tools/debian/emdebian-toolchain-archive.key | sudo apt-key add -
The key fingerprint is: 084C 6C6F 3915 9EDB 6796 9AA8 7DE0 8967 1804 772E (you will need to install curl in a bare chroot)
crossbuild-essential-<arch> packages exist to aid in installing the correct cross-packages. For instance to install the armhf cross-toolchain, first enable the foreign architecture (and update), then install crossbuild-essential-armhf :
sudo dpkg --add-architecture armhf sudo apt-get update sudo apt-get install crossbuild-essential-armhf
This will pull in the required packages to cross-build for the target architecture, namely libc6-dev:<arch>, gcc-<triplet>, g++-<triplet> and dpkg-cross.
For unstable
You must enable the appropriate (HOST) foreign architecture before installing the cross-compiler.
dpkg --add-architecture armhf apt-get update
It is recommended to install the cross environment like this as that pulls in all the necessary components:
apt-get install crossbuild-essential-<arch>
i.e
apt-get install crossbuild-essential-armhf
But you can install just the compiler with
apt-get install gcc-arm-linux-gnueabihf
Note that gcc-arm-linux-gnueabihf is (like the native 'gcc') just a metapackage, which brings int he current version of the actual compiler gcc-4.9-arm-linux-gnueabihf (c.f. gcc-4.9)
g++-<triplet>, gfortran-<triplet>, gobjc-<triplet> and gccgo-<triplet> packages also exist.
Using a chroot of unstable
For any release older than Jessie, the simplest way is to create a chroot of unstable and install your toolchain & build the package there. This is particularly simple if you are simply building a kernel or a package with only libc build dependencies.
$ sudo debootstrap sid sid $ sudo chroot sid # dpkg --add-architecture armhf # apt-get update # apt install gcc-arm-linux-gnueabihf
For Wheezy
Without a chroot, you are blocked. Emdebian.org did have 'unstable' packages which would work on wheezy but these need to be restored after a server compromise.
For Squeeze
Packaged cross-toolchains are available from emdebian.org. These use classic cross-compiler paths and pre-date multiarch so expect to be used with xapt and/or dpkg-cross supplying build-dependencies.
Older
Emdebian.org keeps some 2.95 vintage packages in case that's useful (people do still ask occaisionally!). Currently awaiting re-uploading.
Removal
This is currently the same on all suites.
You can just use whatever package tools you like to remove crossbuild-essential-<arch> or gcc-<triplet> in the usual way. However if youhave installed cross-build-deps then there may well be a lot of foreign-architecture -dev packages installed.
If you want to remove all foreign-arch packages and the corresponding foreign architecture entirely then you need to remove all the :arch packages before you run dpkg --remove-architecture arch. This one-liner should work:
sudo apt-get remove `dpkg-query -f'${Package}:${Architecture}\n' -W '*:arch'`
where 'arch' is the foreign architecture you want to remove.
Future cross-toolchain implementation (currently experimental)
Debian provided basic cross-toolchain support in the archive from November 2014 onwards. Previously this had only been available from external repositories.
These are generally built to run on fast architectures (amd64, ppc64el, arm64), and target all reasonably popular architectures (arm64, armel, armhf, powerpc, ppc64, i386, amd64, mips, mipsel, mips64el).
They will be automatically installed (by the magic of multiarch) if you enable the architecture you are building for, and install build-essential for a target architecture, or a package which directly depends on gcc-for-host.
!Note the BUILD architecture is the machine you are building _on_. the HOST architecture is the one you are building _for_
Installation concepts for experimental
To cross-build (or install cross toolchains) you will need to enable multiarch for the architecture you are building for (the HOST arch) (unless targetting an architecture that is not in Debian, in which case the cross-toolchain will be installable without any foreign-arch packages).
dpkg --add-architecture armhf apt-get update
Use the debian architecture name to install toolchains (or cross-toolchains)
apt-get install -a<arch> build-essential
i.e
apt-get install -aarmhf build-essential
Note that the toolchains thus installed must be used as <triplet>-gcc, for both native _and_ cross usage. i.e. x86_64-linux-gnu-gcc for the native compiler on amd64, and arm-linux-gnueabihf-gcc for the cross-compiler targetting armhf.
Plain 'gcc' will (probably) not be installed.
Which packages are what?
- The actual versioned cross-compiler is in gcc-4.9-arm-linux-gnueabihf
- The package setting which version of the toolchain is currently the default is gcc-arm-linux-gnueabihf
- The package which pulls in a specific version of the target arch cross-compiler is gcc-4.9-for-host:armhf
- The package which pulls in the target arch cross-compiler is gcc-for-host:armhf
- The package which pulls in the build (native) arch compiler is gcc-for-build
Packages which need a particular version of gcc should build-depend on gcc-4.9-for-host Packages which also need the build-arch gcc when cross-building, should build-depend on gcc-for-build (for the default version) or gcc-4.9-for-build (to get 4.9 specifically).
Similar packages exist for g++, cpp, gfortran, binutils and pkg-config.
Installing build-dependencies
apt-get build-dep -a <arch> <package>
e.g.
apt-get build-dep -a armhf util-linux
If the build-deps are not installable in this way (usually due to un-multiarched packages in the dependency tree), then use dpkg-checkbuilddeps and apt-get install to manually insert the right packages.
Information for package maintainers
In the pre-multiarch-crosscompiler world (jessie and earlier) a package could run 'gcc' and expect to get the compiler targetting the native arch and running on the native arch (e.g amd64,amd64). And it could build-depend on 'gcc-4.7' to get an older compiler installed. However There was no way to depend on a particular compiler version and have that version of the cross-compiler installed, so this scheme made any package needing a particular gcc version uncrossbuildable (without a lot of faffing).
In stretch build-essential implicitly depends on the compiler for the HOST architecture (which is the architecture you are building _for_) via 'gcc-for-host'. This is the default compiler, which must be run specifying the TARGET architecture (the one you want to build code for), i.e. as x86_64-linux-gnu-eabi-gcc. Don't call 'gcc' as it may not do the right thing, or work at all.
Packages that need a specific version of the compiler can now depend on 'gcc-<version>-for-host' and will get the <triplet>-gcc for the (HOST) architecture that the build is targetting.
See the multilib section for info on why it is recommended to always call the compiler as <triplet>-gcc
How does this _really_ work
Details of the gcc interface and metapackage design are in https://wiki.debian.org/Sprints/2014/BootstrapSprint/Results
Appropriate info needs extracting to here
Sources
In the archive things are arranged like this:
src:cross-binutils provides the binutils-<triplet> packages
src:gcc-cross-support provides the gcc-4.9-for-host and gcc-4.9-for-build packages
src:cross-gcc-defaults provides the gcc-arm-linux-gnueabihf and gcc-for-host default-version packages.
- src:gcc-4.9 provides the native toolchain packages
- src:cross-4.9-gcc-armhf provides the (version 4.9) cross-gcc (and cpp, g++, gfortran) compilers targetting armhf (arm-linux-gnueabihf)
- src:cross-4.9-gcc-bootstrap-sparc provides (version 4.9) self-contained cross-gcc (and cpp, g++, gfortran) compilers targetting sparc (and other architectures which are not offical debian releases)
The various cross-gcc-<ver>-<arch> source packages are generated from a http://anonscm.debian.org/cgit/crosstoolchain/cross-gcc.git|git repo on alioth]]. This enables us to have one source per target arch so that arches can fail to build independently, but still meaning that there is only one core set of code to maintain.
The missing sources (cross-gcc-bootstrap, gcc-cross-support, cross-support) repos will be uploaded there shortly so that everything is in one place for maintenance.