aboutsummaryrefslogtreecommitdiffstats
path: root/chapter06/rustc.xml
blob: d1094e2571f1e6af9ddd815badaf74f53cb6a25d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
  <!ENTITY % general-entities SYSTEM "../general.ent">
  %general-entities;
]>

<sect1 id="ch-tools-rustc" role="wrap">
  <?dbhtml filename="rustc.html"?>

  <sect1info condition="script">
    <productname>Rustc</productname>
    <productnumber>&rustc-version;</productnumber>
    <address>&rustc-url;</address>
  </sect1info>

  <title>Rustc-&rustc-version;</title>

  <indexterm zone="ch-tools-rustc">
    <primary sortas="a-Rustc">Rustc</primary>
    <secondary>tools</secondary>
  </indexterm>

  <sect2 role="package">
    <title/>

    <para>The Rust programming language is designed to be a safe,
    concurrent, practical language.</para>

    <segmentedlist>
      <segtitle>&buildtime;</segtitle>
      <segtitle>&diskspace;</segtitle>

      <seglistitem>
        <seg>&rustc-tmp-sbu;</seg>
        <seg>&rustc-tmp-du;</seg>
      </seglistitem>
    </segmentedlist>

  </sect2>

  <sect2 role="installation">
    <title>Installation of Rustc</title>

    <para>Tell Rustc how to support <envar>$LFS_TGT</envar> triplet:</para>

<screen><userinput remap="pre">cp -v compiler/rustc_target/src/spec/x86_64_{unknown,lfs}_linux_gnu.rs
cp -v compiler/rustc_target/src/spec/i686_{unknown,lfs}_linux_gnu.rs
cp -v compiler/rustc_target/src/spec/i586_{unknown,lfs}_linux_gnu.rs
sed -i.orig compiler/rustc_target/src/spec/mod.rs                        \
    -e '/targets!/a\    ("x86_64-lfs-linux-gnu", x86_64_lfs_linux_gnu),' \
    -e '/targets!/a\    ("i686-lfs-linux-gnu", i686_lfs_linux_gnu),'     \
    -e '/targets!/a\    ("i586-lfs-linux-gnu", i586_lfs_linux_gnu),'</userinput></screen>

    <para>In the first pass, build Rustc as a cross compiler for
    <envar>$LFS_TGT</envar>.  The cross compiler will link to LLVM Pass 1,
    so we need to tell the dynamic linker of the host distro where to find
    the LLVM Pass 1 dynamic library:</para>

<screen><userinput remap="pre">export LD_LIBRARY_PATH=$LFS/tools/lib</userinput></screen>

    <para>Create a suitable configuration:</para>

<screen><userinput remap="pre">install -vm755 src/llvm-project/llvm/cmake/config.guess config.guess
cat &gt; pass1.toml &lt;&lt; EOF<literal>
[llvm]
link-shared = true

[build]
# omit docs to save time and space (default is to build them)
docs = false

# install cargo as well as rustc, but skip other tools as they are
# not necessary for temporary installation
extended = true
tools = ["cargo"]

# don't download crates during build
locked-deps = true
vendor = true

# build both the native compiler and the cross compiler
# native compiler is necessary because Rust heavily uses meta-programming
target = [ "</literal>$(./config.guess)<literal>", "</literal>$LFS_TGT<literal>" ]

[rust]
channel = "stable"

# LFS does not install the FileCheck executable from llvm,
# so disable codegen tests
codegen-tests = false

[target.</literal>$(./config.guess)<literal>]
# link Rustc to LLVM pass 1
llvm-config = "</literal>$LFS<literal>/tools/bin/llvm-config"

[target.</literal>$LFS_TGT<literal>]
cc     = "</literal>$LFS<literal>/tools/bin/</literal>$LFS_TGT<literal>-gcc"
cxx    = "</literal>$LFS<literal>/tools/bin/</literal>$LFS_TGT<literal>-g++"
ar     = "</literal>$LFS<literal>/tools/bin/</literal>$LFS_TGT<literal>-ar"
ranlib = "</literal>$LFS<literal>/tools/bin/</literal>$LFS_TGT<literal>-ranlib"

# not ld: on Linux platforms Rustc uses GCC driver for linking
linker = "</literal>$LFS<literal>/tools/bin/</literal>$LFS_TGT<literal>-gcc"
</literal>EOF</userinput></screen>

    <para>Build the cross compiler and target libraries:</para>

<screen><userinput remap="make">python3 x.py build --stage 1 library --config pass1.toml</userinput></screen>

    <para>In the second pass, build Rustc as a native compiler on
    <envar>$LFS_TGT</envar>:</para>

<screen><userinput remap="pre">cat &gt; pass2.toml &lt;&lt; EOF<literal>
[llvm]
link-shared = true

[build]
docs = false
extended = true
tools = ["cargo"]
locked-deps = true
vendor = true

# build the native compiler for this triplet
host = [ "</literal>$LFS_TGT<literal>" ]

[install]
prefix = "/opt/rustc-&rustc-version;"
docdir = "share/doc/rustc-&rustc-version;"

[rust]
channel = "stable"
rpath = false

# BLFS does not install the FileCheck executable from llvm,
# so disable codegen tests
codegen-tests = false

[target.</literal>$(./config.guess)<literal>]
llvm-config = "</literal>$LFS<literal>/tools/bin/llvm-config"

[target.</literal>$LFS_TGT<literal>]
cc     = "</literal>$LFS<literal>/tools/bin/</literal>$LFS_TGT<literal>-gcc"
cxx    = "</literal>$LFS<literal>/tools/bin/</literal>$LFS_TGT<literal>-g++"
ar     = "</literal>$LFS<literal>/tools/bin/</literal>$LFS_TGT<literal>-ar"
ranlib = "</literal>$LFS<literal>/tools/bin/</literal>$LFS_TGT<literal>-ranlib"
linker = "</literal>$LFS<literal>/tools/bin/</literal>$LFS_TGT<literal>-gcc"

# link Rustc to LLVM pass 2
llvm-config = "</literal>$LFS<literal>/tools/</literal>$LFS_TGT<literal>/bin/llvm-config"
</literal>EOF</userinput></screen>

    <para>Build the native compiler:</para>

<screen><userinput remap="make">env {X86_64,I{5,6}86}_LFS_LINUX_GNU_OPENSSL_DIR=$LFS/usr \
python3 x.py build --keep-stage 0     \
                   --keep-stage-std 1 \
                   --stage 2          \
                   --config pass2.toml</userinput></screen>

    <para>Install the package:</para>

<screen><userinput remap="make">env {X86_64,I{5,6}86}_LFS_LINUX_GNU_OPENSSL_DIR=$LFS/usr \
    DESTDIR=$LFS                                         \
python3 x.py install --keep-stage 0     \
                     --keep-stage-std 1 \
                     --stage 2          \
                     --config pass2.toml
ln -sv rustc-&rustc-version; $LFS/opt/rustc</userinput></screen>

    <!-- Maybe we should just set LD_LIBRARY_PATH=$LFS/tools
         during the entire chapter 5 and 6.  But doing so will need to
         modify .bashrc of lfs user.  For now just unset it, so the manual
         build is consistent with jhalfs.  -->
    <para>Clean up the environment:</para>

<screen><userinput remap="make">unset LD_LIBRARY_PATH</userinput></screen>

  </sect2>

  <sect2 role="content">
    <title/>

    <para>Details on this package are located in
    <xref linkend="contents-rustc" role="."/></para>
  </sect2>

</sect1>