source: general/prog/rust.xml@ 9324b4e

bdubbs/svn
Last change on this file since 9324b4e was 9324b4e, checked in by Bruce Dubbs <bdubbs@…>, 5 years ago

Simplify custom rustc page

git-svn-id: svn://svn.linuxfromscratch.org/BLFS/branches/bdubbs@21040 af4574ff-66df-0310-9fd7-8a98e5e911e0

  • Property mode set to 100644
File size: 22.2 KB
Line 
1<?xml version="1.0" encoding="ISO-8859-1"?>
2<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
4 <!ENTITY % general-entities SYSTEM "../../general.ent">
5 %general-entities;
6
7 <!ENTITY rust-download-http "https://static.rust-lang.org/dist/rustc-&rust-version;-src.tar.gz">
8 <!ENTITY rust-download-ftp " ">
9 <!ENTITY rust-md5sum "366f049777e00d0d6f15d25895485efb">
10 <!ENTITY rust-size "152 MB">
11 <!-- Gentle Reminder: buildsize is how much the user requires for the real
12 install, i.e. the source with its DESTDIR *plus* the DESTDIR. You
13 can 'mkdir /tmp/RUST ; cp -a install/* /tmp/RUST' and then run 'du -sch'
14 to measure it. -->
15
16 <!ENTITY rust-buildsize "6.2 GB (475 MB installed) including 295MB of ~/.cargo files for the user building this. Add 1.5GB if installing the documentation (an extra 314MB is installed), and 2.0GB if running the tests">
17 <!ENTITY rust-time "34 SBU (add 3 SBU if installing the documentation and 15 SBU for tests, both with 4 processors)">
18]>
19
20<sect1 id="rust" xreflabel="rustc-&rust-version;">
21 <?dbhtml filename="rust.html"?>
22
23 <sect1info>
24 <othername>$LastChangedBy$</othername>
25 <date>$Date$</date>
26 </sect1info>
27
28 <title>Rustc-&rust-version;</title>
29
30 <indexterm zone="rust">
31 <primary sortas="a-rust">Rust</primary>
32 </indexterm>
33
34 <sect2 role="package">
35 <title>Introduction to Rust</title>
36
37 <para>
38 The <application>Rust</application> programming language is designed
39 to be a safe, concurrent, practical language.
40 </para>
41
42 <para>
43 This package is updated on a six-weekly release cycle. Because it is
44 such a large and slow package to build, and is at the moment only required
45 by five packages in this book, the BLFS editors take the view that it
46 should only be updated when that is necessary (either to fix problems,
47 or to allow a new version of <application>firefox</application> to build).
48 </para>
49
50 <para>
51 As with many other programming languages, rustc (the rust compiler)
52 needs a binary from which to bootstrap. It will download a stage0 binary
53 and many cargo crates (these are actually .tar.gz source archives) at
54 the start of the build, so you cannot compile it without an internet
55 connection.
56 </para>
57
58 <para>
59 These crates will then remain in various forms (cache, directories of
60 extracted source), in <filename class="directory">~/.cargo</filename> for
61 ever more. It is common for large <application>rust</application> packages
62 to use multiple versions of some crates. If you purge the files before
63 updating this package, very few crates will need to be updated by the
64 packages in this book which use it (and they will be downloaded as
65 required). But if you retain an older version as a fallback option and
66 then use it (that would require <emphasis>not</emphasis> building in
67 <filename class="directory">/usr</filename>), it is likely that it will
68 then have to re download some crates. For a full download (i.e. starting
69 with an empty or missing <filename class="directory">~/.cargo</filename>)
70 downloading the external cargo files for this version only takes a minute
71 or so on a fast network.
72 </para>
73
74 <note>
75 <para>
76 When you upgrade to a newer version, the new libraries will have various
77 hashes in their names and therefore there will be a mix of versions but
78 only one of each will be usable. A binary distribution would use its
79 package manager to delete all the old <application>rust</application>
80 installation before updating. You may wish to do the same to save space.
81 </para>
82
83 <para>
84 One alternative when working with multiple versions or just updating
85 to a new version is to place the files in the
86 <filename class="directory">/opt</filename> directory. The instructions
87 below provide optional commands to support better control of
88 new package versions or reinstallation of the current version.
89 </para>
90 </note>
91
92 <para>
93 The current <application>rustbuild</application> build-system will use
94 all available processors, although it does not scale well and often falls
95 back to just using one core while waiting for a library to compile.
96 </para>
97
98 <para>
99 At the moment <application>Rust</application> does not provide any
100 guarantees of a stable ABI.
101 </para>
102
103 <note>
104 <para>
105 Rustc defaults to building for ALL supported architectures, using a
106 shipped copy of LLVM. In BLFS the build is only for the X86 architecture.
107 If you intend to develop rust crates, this build may not be good
108 enough for your purposes.
109 </para>
110 <para>
111 Unlike with previous versions, the build times of this version when
112 repeated on the same machine seem reasonably consistent.
113 </para>
114 <para>
115 Unusually, a DESTDIR-style method is being used to install this package.
116 This is because running the install as root not only downloads all of the
117 cargo files again (to <filename>/root/.cargo</filename>), it then spends
118 a very long time recompiling. Using this method saves a lot of time, at
119 the cost of extra disk space.
120 </para>
121 </note>
122
123 &lfs83_checked;
124
125 <bridgehead renderas="sect3">Package Information</bridgehead>
126 <itemizedlist spacing="compact">
127 <listitem>
128 <para>
129 Download (HTTP): <ulink url="&rust-download-http;"/>
130 </para>
131 </listitem>
132 <listitem>
133 <para>
134 Download (FTP): <ulink url="&rust-download-ftp;"/>
135 </para>
136 </listitem>
137 <listitem>
138 <para>
139 Download MD5 sum: &rust-md5sum;
140 </para>
141 </listitem>
142 <listitem>
143 <para>
144 Download size: &rust-size;
145 </para>
146 </listitem>
147 <listitem>
148 <para>
149 Estimated disk space required: &rust-buildsize;
150 </para>
151 </listitem>
152 <listitem>
153 <para>
154 Estimated build time: &rust-time;
155 </para>
156 </listitem>
157 </itemizedlist>
158
159 <bridgehead renderas="sect3">Rust Dependencies</bridgehead>
160
161 <bridgehead renderas="sect4">Required</bridgehead>
162 <para role="required">
163 <xref linkend="curl"/>,
164 <xref linkend="cmake"/>,
165 <xref linkend="libssh2"/>, and
166 <xref linkend="python2"/>
167 </para>
168
169<!-- comment out while using shipped LLVM
170 <bridgehead renderas="sect4">Recommended</bridgehead>
171 <para role="recommended">
172 <package>clang</package> from <xref linkend="llvm"/>
173 (built with -DLLVM_LINK_LLVM_DYLIB=ON)
174 </para>-->
175
176 <bridgehead renderas="sect4">Optional</bridgehead>
177 <para role="optional">
178 <xref linkend="gdb"/> (used by the testsuite if it is present)
179 </para>
180
181 <para condition="html" role="usernotes">
182 User Notes: <ulink url="&blfs-wiki;/rust"/>
183 </para>
184 </sect2>
185
186 <sect2 role="installation">
187 <title>Installation of Rust</title>
188
189 <para>
190 If you are going to install into the
191 <filename class="directory">/opt</filename> directory, remove
192 conflicting entries and recreate the required entries.
193 As the <systemitem class="username">root</systemitem>
194 user:
195 </para>
196
197<screen role="root"><userinput>rm -rf /opt/rustc /opt/rustc-&rust-version; &amp;&amp;
198mkdir /opt/rustc-&rust-version; &amp;&amp;
199ln -sv rustc-&rust-version; /opt/rustc</userinput></screen>
200
201 <note>
202 <para>
203 If multiple versions of <application>Rust</application> are installed
204 in <filename class="directory">/opt</filename>, changing to another
205 version only requires changing the <filename> /opt/rustc</filename>
206 symbolic link.
207 </para>
208 </note>
209
210 <para>
211 Create a suitable <filename>config.toml</filename> file which will
212 configure the build. Unlike with previous releases, where even quite old
213 system versions of <application>LLVM</application>worked well, this
214 version ships with a development version and using the current <xref
215 linkend="llvm"/> release is known to result in breakage in some
216 circumstances.
217 </para>
218
219<screen><userinput>cat &lt;&lt; EOF &gt; config.toml
220# see config.toml.example for more possible options
221[llvm]
222
223# use ninja
224ninja = true
225
226targets = "X86"
227# When compiling LLVM, the experimental targets (WebAssembly
228# and RISCV) are built by default - omit them
229experimental-targets = ""
230
231[build]
232# omit HTML docs to save time and space (comment this to build them)
233docs = false
234
235# install cargo as well as rust
236extended = true
237
238[install]
239# Adjust the prefix for the desired destination
240#prefix = "/usr"
241prefix = "/opt/rustc-&rust-version;"
242
243# docdir is used even if the full awesome docs are not installed
244docdir = "share/doc/rustc-&rust-version;"
245
246[rust]
247channel = "stable"
248rpath = false
249
250# BLFS does not install the FileCheck executable from llvm,
251# so disable codegen tests
252codegen-tests = false
253
254# get a trace if there is an Internal Compiler Exception
255backtrace-on-ice = true
256
257EOF</userinput></screen>
258
259 <para>
260 Now install <application>Rust</application> by running the following
261 commands:
262 </para>
263
264<screen><userinput>export RUSTFLAGS="$RUSTFLAGS -C link-args=-lffi" &amp;&amp;
265./x.py build --exclude src/tools/miri</userinput></screen>
266
267 <note>
268 <para>
269 The testsuite will generate some messages in the
270 <phrase revision="sysv">system log</phrase>
271 <phrase revision="systemd">systemd journal</phrase>
272 for traps on invalid opcodes, and for segmentation faults.
273 In themselves these are nothing to worry about, just a way for the
274 test to be terminated. But if the output from the testsuite reports tests
275 which FAIL with segmentation faults (signal 11) then there may be a
276 problem.
277 </para>
278 </note>
279
280 <para>
281 To run the tests issue
282 <command>./x.py test --verbose --no-fail-fast | tee rustc-testlog</command>:
283 as with the build, that will use all available CPUs.
284 </para>
285
286 <para>
287 The instructions above do not build ARM compilers, so the testsuite
288 <emphasis>will</emphasis> fail and the tests will be reported to end in
289 error, with a backtrace of the last failing test. On a good run, 3 tests
290 which need Thumb (ARM) compilers will fail, all in <filename
291 class="directory">ui/issues</filename> for issues 37131, 49851 and 50993.
292 Occasionally a fourth test, in run-make, 'sysroot-crates-are-unstable',
293 has been known to fail. That is probably harmless. As with all large
294 testsuites, other tests might fail on some machines - if the number of
295 failures is in the single digits, check the log for 'FAILED' and review
296 lines above that. Any mention of SIGSEGV or signal 11 in a failing test
297 is a cause for concern.
298 </para>
299
300 <para>
301 Therefore, you should determine the number of tests, failures, etc. The
302 total number of tests which were considered is found by running:
303 </para>
304
305<screen><command>grep 'running .* tests' rustc-testlog | awk '{ sum += $2 } END { print sum }'</command></screen>
306
307 <para>
308 That should report 15795 tests. Similarly, the total tests which failed can
309 be found by running:
310 </para>
311
312<screen><command>grep '^test result:' rustc-testlog | awk '{ sum += $6 } END { print sum }'</command></screen>
313
314 <para>
315 And similarly for the tests which passed use $4, for those which were ignored
316 (i.e. skipped) use $8 (and $10 for 'measured', $12 for 'filtered out' but both
317 are probably zero). The breakdown does not quite match the overall total.
318 </para>
319
320 <para>
321 Still as your normal user, do a DESTDIR install:
322 </para>
323
324<screen><userinput>export LIBSSH2_SYS_USE_PKG_CONFIG=1 &amp;&amp;
325DESTDIR=${PWD}/install ./x.py install &amp;&amp;
326unset LIBSSH2_SYS_USE_PKG_CONFIG</userinput></screen>
327
328 <para>
329 Now, as the <systemitem class="username">root</systemitem> user
330 install the files from the DESTDIR:
331 </para>
332
333<screen role="root"><userinput>chown -R root:root install &amp;&amp;
334cp -a install/* /</userinput></screen>
335
336 </sect2>
337
338 <sect2 role="commands">
339 <title>Command Explanations</title>
340
341 <para>
342 <command>targets = "X86"</command>: this avoids building all the available
343 linux cross-compilers (Aarch64, MIPS, PowerPC, SystemZ, etc). Unfortunately,
344 rust insists on installing source files for these below
345 <filename class="directory">/usr/lib/rustlib/src</filename>.
346 </para>
347
348 <para>
349 <command>extended = true</command>: this installs Cargo alongside Rust.
350 </para>
351
352 <para>
353 <command>channel = "stable"</command>: this ensures only stable features
354 can be used, the default in <filename>config.toml</filename> is to use
355 development features, which is not appropriate for a released version.
356 </para>
357
358 <para>
359 <command>rpath = false</command>: by default, <command>rust</command> can
360 be run from where it was built, without being installed. That adds DT_RPATH
361 entries to all of the ELF files, which produces very messy output from
362 <command>ldd</command>, showing the libraries in the place they were built,
363 even if they have been deleted from there after the install.
364 </para>
365
366 <!-- comment while using shipped LLVM
367 <para>
368 <command>[target.x86_64-unknown-linux-gnu]</command>: the syntax of
369 <filename>config.toml</filename> requires an <literal>llvm-config</literal>
370 entry for each target for which system-llvm is to be used. Change the target
371 to <literal>[target.i686-unknown-linux-gnu]</literal> if you are building
372 on 32-bit x86. This whole section may be omitted if you wish to build
373 against the shipped llvm, or do not have clang, but the resulting build will
374 be larger and take longer.
375 </para>-->
376
377 <para>
378 <command>export RUSTFLAGS="$RUSTFLAGS -C link-args=-lffi"</command>:
379 This adds a link to libffi to any RUSTFLAGS you may already be passing
380 to the build. On some systems, linking fails to include libffi unless
381 this is used. The reason why this is needed is not clear.
382 </para>
383
384 <para>
385 <command>--exclude src/tools/miri</command>: For a long time, the miri
386 crate (an interpreter for the Midlevel Intermediate Representation)
387 has failed to build on releases. It is optional, but the failure
388 messages can persuade people that the whole build failed.
389 </para>
390
391 <para>
392 <command>--verbose</command>: this switch can sometimes provide more
393 information about a test which fails.
394 </para>
395
396 <para>
397 <command>--no-fail-fast</command>: this switch ensures that the testsuite
398 will not stop at the first error.
399 </para>
400
401 <para>
402 <command>export LIBSSH2_SYS_USE_PKG_CONFIG=1</command>: On some systems,
403 cairo fails to link during the install because it cannot find libssh2.
404 This seems to fix it, but again the reason why the problem occurs is not
405 understood.
406 </para>
407
408 <para>
409 <command>DESTDIR=${PWD}/install ./x.py install</command>: This effects a
410 DESTDIR-style install in the source tree,creating an <filename
411 class="directory">install</filename> directory. Note that DESTDIR installs
412 need an absolute path, passing 'install' will not work.
413 </para>
414
415 <para>
416 <command>chown -R root:root install</command>: the DESTDIR install
417 was run by a regular user, who owns the files. For security, change their
418 owner before doing a simple copy to install them.
419 </para>
420
421 </sect2>
422
423 <sect2 role="configuration">
424 <title>Configuring Rust</title>
425
426 <sect3 id="rustc-config">
427 <title>Configuration Information</title>
428
429 <para>
430 If you installed <application>rustc</application> in
431 <filename class="directory">/opt</filename>, you need to update the
432 following configuration files so that <application>rustc</application> is
433 correctly found by other packages and system processes.
434 </para>
435
436 <para>
437 As the <systemitem class="username">root</systemitem> user, update
438 the <filename>/etc/ld.so.conf</filename> file and the dynamic linker's
439 run-time cache file:
440 </para>
441
442<screen role="root"><userinput>cat &gt;&gt; /etc/ld.so.conf &lt;&lt; EOF
443<literal># Begin rustc addition
444
445/opt/rustc/lib
446
447# End rustc addition</literal>
448EOF
449
450ldconfig</userinput></screen>
451
452 <indexterm zone="rustc rustc-config">
453 <primary sortas="e-etc-ld.so.conf">/etc/ld.so.conf</primary>
454 </indexterm>
455
456 <para>
457 As the <systemitem class="username">root</systemitem> user, create
458 the <filename>/etc/profile.d/rustc.sh</filename> file:
459 </para>
460
461<screen role="root"><userinput>cat &gt; /etc/profile.d/rustc.sh &lt;&lt; "EOF"
462<literal># Begin /etc/profile.d/rustc.sh
463
464pathprepend /opt/rustc/bin PATH
465
466# End /etc/profile.d/rustc.sh</literal>
467EOF</userinput></screen>
468
469 <para>Immediately after installation, update the current PATH
470 for your current shell as a normal user:</para>
471
472<screen><userinput>source /etc/profile.d/rustc.sh</userinput></screen>
473
474 </sect3>
475 </sect2>
476
477
478 <sect2 role="content">
479 <title>Contents</title>
480
481 <segmentedlist>
482 <segtitle>Installed Programs</segtitle>
483 <segtitle>Installed Libraries</segtitle>
484 <segtitle>Installed Directories</segtitle>
485
486 <seglistitem>
487 <seg>
488 cargo-clippy, cargo-fmt, cargo, clippy-driver, rls, rust-gdb, rust-lldb, rustc, rustdoc, rustfmt.
489 </seg>
490 <seg>
491 Many lib*&lt;16-byte-hash&gt;.so libraries.
492 </seg>
493 <seg>
494 ~/.cargo,
495 /usr/lib/rustlib,
496 /usr/share/doc/rustc-&rust-version;, and
497 /usr/share/zsh/site-functions/
498 </seg>
499 </seglistitem>
500 </segmentedlist>
501
502 <variablelist>
503 <bridgehead renderas="sect3">Short Descriptions</bridgehead>
504 <?dbfo list-presentation="list"?>
505 <?dbhtml list-presentation="table"?>
506
507 <varlistentry id="cargo-clippy">
508 <term><command>cargo-clippy</command></term>
509 <listitem>
510 <para>
511 provides lint checks for a cargo package.
512 </para>
513 <indexterm zone="rust cargo-clippy">
514 <primary sortas="b-cargo-clippy">cargo-clippy</primary>
515 </indexterm>
516 </listitem>
517 </varlistentry>
518
519 <varlistentry id="cargo-fmt">
520 <term><command>cargo-fmt</command></term>
521 <listitem>
522 <para>
523 formats all bin and lib files of the current crate using
524 rustfmt.
525 </para>
526 <indexterm zone="rust cargo-fmt">
527 <primary sortas="b-cargo-fmt">cargo-fmt</primary>
528 </indexterm>
529 </listitem>
530 </varlistentry>
531
532 <varlistentry id="cargo">
533 <term><command>cargo</command></term>
534 <listitem>
535 <para>
536 is the Package Manager for Rust.
537 </para>
538 <indexterm zone="rust cargo">
539 <primary sortas="b-cargo">cargo</primary>
540 </indexterm>
541 </listitem>
542 </varlistentry>
543
544 <varlistentry id="clippy-driver">
545 <term><command>clippy-driver</command></term>
546 <listitem>
547 <para>
548 provides lint checks for Rust.
549 </para>
550 <indexterm zone="rust clippy-driver">
551 <primary sortas="b-clippy-driver">clippy-driver</primary>
552 </indexterm>
553 </listitem>
554 </varlistentry>
555
556 <varlistentry id="rls">
557 <term><command>rls</command></term>
558 <listitem>
559 <para>
560 is the Rust Language Server. This can run in the background to
561 provide IDEs, editors, and other tools with information about Rust
562 programs.
563 </para>
564 <indexterm zone="rust rls">
565 <primary sortas="b-rls">rls</primary>
566 </indexterm>
567 </listitem>
568 </varlistentry>
569
570 <varlistentry id="rust-gdb">
571 <term><command>rust-gdb</command></term>
572 <listitem>
573 <para>
574 is a wrapper script for gdb, pulling in Python
575 pretty-printing modules installed in <filename
576 class="directory">/usr/lib/rustlib/etc</filename>.
577 </para>
578 <indexterm zone="rust rust-gdb">
579 <primary sortas="b-rust-gdb">rust-gdb</primary>
580 </indexterm>
581 </listitem>
582 </varlistentry>
583
584 <varlistentry id="rust-lldb">
585 <term><command>rust-lldb</command></term>
586 <listitem>
587 <para>
588 is a wrapper script for LLDB (the LLVM debugger)
589 pulling in the Python pretty-printing modules.
590 </para>
591 <indexterm zone="rust rust-lldb">
592 <primary sortas="b-rust-lldb">rust=lldb</primary>
593 </indexterm>
594 </listitem>
595 </varlistentry>
596
597 <varlistentry id="rustc">
598 <term><command>rustc</command></term>
599 <listitem>
600 <para>
601 is the rust compiler.
602 </para>
603 <indexterm zone="rust rustc">
604 <primary sortas="b-rustc">rustc</primary>
605 </indexterm>
606 </listitem>
607 </varlistentry>
608
609 <varlistentry id="rustdoc">
610 <term><command>rustdoc</command></term>
611 <listitem>
612 <para>
613 generates documentation from rust source code.
614 </para>
615 <indexterm zone="rust rustdoc">
616 <primary sortas="b-rustdoc">rustdoc</primary>
617 </indexterm>
618 </listitem>
619 </varlistentry>
620
621 <varlistentry id="rustfmt">
622 <term><command>rustfmt</command></term>
623 <listitem>
624 <para>
625 formats rust code.
626 </para>
627 <indexterm zone="rust rustfmt">
628 <primary sortas="b-rustfmt">rustfmt</primary>
629 </indexterm>
630 </listitem>
631 </varlistentry>
632
633 <varlistentry id="libstd">
634 <term><filename class="libraryfile">libstd-&lt;16-byte-hash&gt;.so</filename></term>
635 <listitem>
636 <para>
637 is the Rust Standard Library, the foundation of portable Rust software.
638 </para>
639 <indexterm zone="rust libstd">
640 <primary sortas="c-libstd">libstd-&lt;16-byte-hash&gt;.so</primary>
641 </indexterm>
642 </listitem>
643 </varlistentry>
644 </variablelist>
645 </sect2>
646</sect1>
Note: See TracBrowser for help on using the repository browser.