source: chapter06/rustc.xml@ d7c5e6c

xry111/rust-wip-20221008
Last change on this file since d7c5e6c was 4621dcb, checked in by Xi Ruoyao <xry111@…>, 19 months ago

rust: temporary rustc: export LD_LIBRARY_PATH for LLVM Pass 1

Rustc Pass 1 links to LLVM Pass 1, but the building system does not set
rpath for LLVM shared library (even if rpath = true is used). Explicitly
tell the host dynamic linker to search $LFS/tools/lib so LLVM Pass 1 can
be found.

Thanks Moody for report.

  • Property mode set to 100644
File size: 6.3 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
8<sect1 id="ch-tools-rustc" role="wrap">
9 <?dbhtml filename="rustc.html"?>
10
11 <sect1info condition="script">
12 <productname>Rustc</productname>
13 <productnumber>&rustc-version;</productnumber>
14 <address>&rustc-url;</address>
15 </sect1info>
16
17 <title>Rustc-&rustc-version;</title>
18
19 <indexterm zone="ch-tools-rustc">
20 <primary sortas="a-Rustc">Rustc</primary>
21 <secondary>tools</secondary>
22 </indexterm>
23
24 <sect2 role="package">
25 <title/>
26
27 <para>The Rust programming language is designed to be a safe,
28 concurrent, practical language.</para>
29
30 <segmentedlist>
31 <segtitle>&buildtime;</segtitle>
32 <segtitle>&diskspace;</segtitle>
33
34 <seglistitem>
35 <seg>&rustc-tmp-sbu;</seg>
36 <seg>&rustc-tmp-du;</seg>
37 </seglistitem>
38 </segmentedlist>
39
40 </sect2>
41
42 <sect2 role="installation">
43 <title>Installation of Rustc</title>
44
45 <para>Tell Rustc how to support <envar>$LFS_TGT</envar> triplet:</para>
46
47<screen><userinput remap="pre">cp -v compiler/rustc_target/src/spec/x86_64_{unknown,lfs}_linux_gnu.rs
48cp -v compiler/rustc_target/src/spec/i686_{unknown,lfs}_linux_gnu.rs
49cp -v compiler/rustc_target/src/spec/i586_{unknown,lfs}_linux_gnu.rs
50sed -i.orig compiler/rustc_target/src/spec/mod.rs \
51 -e '/targets!/a\ ("x86_64-lfs-linux-gnu", x86_64_lfs_linux_gnu),' \
52 -e '/targets!/a\ ("i686-lfs-linux-gnu", i686_lfs_linux_gnu),' \
53 -e '/targets!/a\ ("i586-lfs-linux-gnu", i586_lfs_linux_gnu),'</userinput></screen>
54
55 <para>In the first pass, build Rustc as a cross compiler for
56 <envar>$LFS_TGT</envar>. The cross compiler will link to LLVM Pass 1,
57 so we need to tell the dynamic linker of the host distro where to find
58 the LLVM Pass 1 dynamic library:</para>
59
60<screen><userinput remap="pre">export LD_LIBRARY_PATH=$LFS/tools/lib</userinput></screen>
61
62 <para>Create a suitable configuration:</para>
63
64<screen><userinput remap="pre">install -vm755 src/llvm-project/llvm/cmake/config.guess config.guess
65cat &gt; pass1.toml &lt;&lt; EOF<literal>
66[llvm]
67link-shared = true
68
69[build]
70# omit docs to save time and space (default is to build them)
71docs = false
72
73# install cargo as well as rustc, but skip other tools as they are
74# not necessary for temporary installation
75extended = true
76tools = ["cargo"]
77
78# don't download crates during build
79locked-deps = true
80vendor = true
81
82# build both the native compiler and the cross compiler
83# native compiler is necessary because Rust heavily uses meta-programming
84target = [ "</literal>$(./config.guess)<literal>", "</literal>$LFS_TGT<literal>" ]
85
86[rust]
87channel = "stable"
88
89# LFS does not install the FileCheck executable from llvm,
90# so disable codegen tests
91codegen-tests = false
92
93[target.</literal>$(./config.guess)<literal>]
94# link Rustc to LLVM pass 1
95llvm-config = "</literal>$LFS<literal>/tools/bin/llvm-config"
96
97[target.</literal>$LFS_TGT<literal>]
98cc = "</literal>$LFS<literal>/tools/bin/</literal>$LFS_TGT<literal>-gcc"
99cxx = "</literal>$LFS<literal>/tools/bin/</literal>$LFS_TGT<literal>-g++"
100ar = "</literal>$LFS<literal>/tools/bin/</literal>$LFS_TGT<literal>-ar"
101ranlib = "</literal>$LFS<literal>/tools/bin/</literal>$LFS_TGT<literal>-ranlib"
102
103# not ld: on Linux platforms Rustc uses GCC driver for linking
104linker = "</literal>$LFS<literal>/tools/bin/</literal>$LFS_TGT<literal>-gcc"
105</literal>EOF</userinput></screen>
106
107 <para>Build the cross compiler and target libraries:</para>
108
109<screen><userinput remap="make">python3 x.py build --stage 1 library --config pass1.toml</userinput></screen>
110
111 <para>In the second pass, build Rustc as a native compiler on
112 <envar>$LFS_TGT</envar>:</para>
113
114<screen><userinput remap="pre">cat &gt; pass2.toml &lt;&lt; EOF<literal>
115[llvm]
116link-shared = true
117
118[build]
119docs = false
120extended = true
121tools = ["cargo"]
122locked-deps = true
123vendor = true
124
125# build the native compiler for this triplet
126host = [ "</literal>$LFS_TGT<literal>" ]
127
128[install]
129prefix = "/opt/rustc-&rustc-version;"
130docdir = "share/doc/rustc-&rustc-version;"
131
132[rust]
133channel = "stable"
134rpath = false
135
136# BLFS does not install the FileCheck executable from llvm,
137# so disable codegen tests
138codegen-tests = false
139
140[target.</literal>$(./config.guess)<literal>]
141llvm-config = "</literal>$LFS<literal>/tools/bin/llvm-config"
142
143[target.</literal>$LFS_TGT<literal>]
144cc = "</literal>$LFS<literal>/tools/bin/</literal>$LFS_TGT<literal>-gcc"
145cxx = "</literal>$LFS<literal>/tools/bin/</literal>$LFS_TGT<literal>-g++"
146ar = "</literal>$LFS<literal>/tools/bin/</literal>$LFS_TGT<literal>-ar"
147ranlib = "</literal>$LFS<literal>/tools/bin/</literal>$LFS_TGT<literal>-ranlib"
148linker = "</literal>$LFS<literal>/tools/bin/</literal>$LFS_TGT<literal>-gcc"
149
150# link Rustc to LLVM pass 2
151llvm-config = "</literal>$LFS<literal>/tools/</literal>$LFS_TGT<literal>/bin/llvm-config"
152</literal>EOF</userinput></screen>
153
154 <para>Build the native compiler:</para>
155
156<screen><userinput remap="make">env {X86_64,I{5,6}86}_LFS_LINUX_GNU_OPENSSL_DIR=$LFS/usr \
157python3 x.py build --keep-stage 0 \
158 --keep-stage-std 1 \
159 --stage 2 \
160 --config pass2.toml</userinput></screen>
161
162 <para>Install the package:</para>
163
164<screen><userinput remap="make">env {X86_64,I{5,6}86}_LFS_LINUX_GNU_OPENSSL_DIR=$LFS/usr \
165 DESTDIR=$LFS \
166python3 x.py install --keep-stage 0 \
167 --keep-stage-std 1 \
168 --stage 2 \
169 --config pass2.toml
170ln -sv rustc-&rustc-version; $LFS/opt/rustc</userinput></screen>
171
172 <!-- Maybe we should just set LD_LIBRARY_PATH=$LFS/tools
173 during the entire chapter 5 and 6. But doing so will need to
174 modify .bashrc of lfs user. For now just unset it, so the manual
175 build is consistent with jhalfs. -->
176 <para>Clean up the environment:</para>
177
178<screen><userinput remap="make">unset LD_LIBRARY_PATH</userinput></screen>
179
180 </sect2>
181
182 <sect2 role="content">
183 <title/>
184
185 <para>Details on this package are located in
186 <xref linkend="contents-rustc" role="."/></para>
187 </sect2>
188
189</sect1>
Note: See TracBrowser for help on using the repository browser.