Gentoo Archives: gentoo-alt

From: Greg Turner <gmt@×××××.us>
To: gentoo-alt@l.g.o
Subject: Re: [gentoo-alt] Crossdev in a prefix / bug 384167
Date: Thu, 13 Jun 2013 16:27:55
Message-Id: CA+VB3NTszjLqfn_wNVTbqogjyzL7m2XYZZvxgcSZCHqCrj6Z2A@mail.gmail.com
In Reply to: Re: [gentoo-alt] Crossdev in a prefix / bug 384167 by Ruud Koolen
1 On Wed, Jun 12, 2013 at 8:40 PM, Ruud Koolen <redlizard@×××××××××.nl> wrote:
2 > On Monday 10 June 2013 12:17:44 gmt@×××××.us wrote:
3 >> I have crossdev starting to work in a prefix, via an overlay. So far, I
4 >> have x86_64-pc-linux-gnu->i686-pc-linux-gnu[-multilib] working, and I seem
5 >> to be making good progress towards my intermediate objective,
6 >> x86_64-pc-linux-gnu->x86-64-w64-mingw64[multilib].
7 >
8 > heroxbd and me are working on that too, as part of
9 > http://wiki.gentoo.org/wiki/Google_Summer_of_Code/2013/Ideas/Gentoo_on_Android .
10 > The idea so far is that crossdev should work more or less automatically once
11 > we manage to implement some toolchain fixes; basically, the toolchain
12 > packages (binutils, gcc, libc) and portage should support cross-compiling
13 > across different prefixes as well as across different architectures, after
14 > which the crossdev script should just work.
15
16 A number of places in the existing e{builds,classes} assume,
17 approximately (and in pseudo-pseudocode :P) that:
18
19 ( ${CHOST} != ${C{BUILD,TARGET}} )
20 ===> ( EPREFIX == "" )
21
22
23 In English, I mean, that at any given moment, one is permitted by the
24 code to be either cross-compiling or to be using prefixed-portage, but
25 not both.
26
27 The changes I've made so far are lowest-hanging-fruit -- they don't
28 really change this assumption. Instead what they do is extend
29 prefix-compatibility to the crossdev script and a few key toolchain
30 ebuilds. The existing logic, translates, roughly, to this:
31
32 When I am built according to 'the "X" convention'
33 (see below for a partial definition) I assume and/or
34 require that EPREFIX is "", and I go through the
35 configure and compile phases "pretending" that ROOT
36 is "/". Then, I ask the toolchain build scripts to make a
37 cross-compiling environment which, in turn, creates its
38 own sub-ROOT at /usr/${CTARGET}. During the install
39 phase, I then specify (effectively, if not literally)
40 DESTDIR=${D}${ROOT}, so that the cross-sub-root ends up
41 installed to as ${ROOT}usr/${CTARGET}.
42
43 As you can see this is all pretty standard. The only "trick" is that
44 under no circumstances may knowledge of ROOT leak into these toolchain
45 e-builds during any build phases, and get mixed-up with the sub-ROOT.
46 IIUC we want to be able to "chroot $(portageq envvar ROOT)" and have
47 the right thing happen, which in this case means that within that
48 chroot, with CHOST unchanged, we are able to build stuff for our
49 cross-platform sub-ROOT by cross-emerging, which would itself be
50 chroot-able -- at least, I think that's right.
51
52 One thing I still haven't entirely figured out is what, exactly,
53 constitutes the fully correct specification of 'the "X" convention'.
54 The simplest and most intuitive version of this is "${CHOST} !=
55 ${CTARGET}" but once we permit "cross-multilib-ness" to occur as well,
56 those tests potentially break down. I see some deficiencies in the
57 current non-ROOT, non-EPREFIX case pertaining to this in gx86.
58
59 I think the changes required are actually quite easy and don't really
60 add much complexity; in fact they sometimes make it slightly simpler,
61 if you can believe it. Here's how I'm trying to change the above to
62 be EPREFIX-compatible.
63
64 When I am built according to 'the "X" convention'
65 I go through the configure and compile phases
66 "pretending" that ROOT is "/" and EPREFIX is
67 unchanged. Then, I ask the toolchain build scripts
68 to make a cross-compiling environment which, in turn,
69 creates its own sub-root at
70 ${EPREFIX}/usr/${CTARGET}. During the install
71 phase, I then specify (effectively, if not literally)
72 DESTDIR=${ED}${ROOT}, so the cross-sub-root ends up
73 installed as ${EROOT}usr/${CTARGET}.
74
75 Bascially, there's nothing novel about the above, it just applies the
76 "ebuild modifications" outlined at
77 http://www.gentoo.org/proj/en/gentoo-alt/prefix/techdocs.xml to the
78 previous version. Just as we could chroot ${ROOT} and cross-build in
79 the previous framework, we could now in theory chroot ${ROOT}, set
80 PATH="${EPREFIX}/bin:(insert standard stuff here):${PATH}", and do
81 whatever else constitutes activating the prefix portage, and then use
82 the prefixed, chrooted cross-emerge.
83
84 So returning to my initial point, this is the easy version. The
85 /hard/ version pertains to the case that within the cross-emerge black
86 box, we want a second, possibly different EPREFIX -- we might call
87 this the CROSS_${CTARGET}_EPREFIX. Put another way, I'm extending
88 crossdev to support a prefix on the host, but it still won't support a
89 prefix on the /target/.
90
91 I'm pretty sure it wouldn't be /that/ hard to actually go all the way
92 and support both. I'm quite sure there are real-world applications
93 that actually call for that. It's harder, though, because everywhere
94 -- not just in the toolchain ebuilds -- that currently assumes or
95 asserts that ( ${CHOST} != ${CTARGET} ) ===> ( ${EPREFIX} == "" )
96 would need to be fixed. In my easy solution, we don't care about
97 this, since it's always true in regular non-cross portage, and it's
98 still always true in the cross-emerge black-box (note -- so far my
99 patches don't touch the cross-emerge wrapper scripts and I haven't
100 tested them. I'm hoping, if they don't work right OOTB, they'll be
101 relatively easy to fix. I haven't even tested with ROOT != "/",
102 either, and wouldn't be surprised if I still had ROOT+EPREFIX bugs as
103 well).
104
105 Unfortunately, also, at some point, this whole mess is going to start
106 bumping up against the limitations of prefix portage; namely, that it
107 has not yet been ported beyond the deprecated no-multilib profile. I
108 am expecting this to break PREFIX -> multilib cross emerges, at least
109 until the prefix and non-prefix versions of gcc-config are unified.
110 To fix that, we could either fix prefix portage to support multilib
111 (better for gentoo) or give the "ESUBROOT"s (made-up fake variable for
112 ${EROOT}/usr/${CTARGET}/) their own external ${PORTDIR}, containing
113 the non-prefix portage tree (easier to implement), so that
114 cross-emerge built against gx86 even on prefix-portage hosts.
115
116 One final thing I think we should really be looking at. Recent gcc
117 toolchains have increasingly robust support for a "sysroot" concept
118 that achieves many of the same benefits we currently derive using
119 smoke-and-mirrors with ${ROOT} in cross-emerge. Determining in which
120 versions various toolchain components start supporting sysroot
121 correctly, and using the feature (perhaps optionally) in those cases
122 (in lieu of the smoke-and-mirrors approach) would have the added
123 benefit of creating "relocatable" toolchains, which is to say,
124 rpath-free -- you can just stick 'em in a tarball and plop them down
125 wherever you like, and by-and-large, the right thing will actually
126 happen. There is even early support for the same concept in recent
127 libtools, so that, hypothetically, you can build stuff within or
128 without your "SUBROOT" and everything will "just work" (although
129 package-level compatibility with the libtool feature is quite spotty,
130 I suspect).
131
132 I'd be curious to hear more about what your GSOC objectives are,
133 especially whether it's the "easy" or the "hard" fix, above, you are
134 shooting for.
135
136 -gmt

Replies

Subject Author
Re: [gentoo-alt] Crossdev in a prefix / bug 384167 heroxbd <heroxbd@×××××.com>