summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/rust/rust.inc
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/rust/rust.inc')
-rw-r--r--meta/recipes-devtools/rust/rust.inc223
1 files changed, 0 insertions, 223 deletions
diff --git a/meta/recipes-devtools/rust/rust.inc b/meta/recipes-devtools/rust/rust.inc
deleted file mode 100644
index f58aa46444..0000000000
--- a/meta/recipes-devtools/rust/rust.inc
+++ /dev/null
@@ -1,223 +0,0 @@
1SUMMARY = "Rust compiler and runtime libaries"
2HOMEPAGE = "http://www.rust-lang.org"
3SECTION = "devel"
4LICENSE = "(MIT | Apache-2.0) & Unicode-TOU"
5LIC_FILES_CHKSUM = "file://COPYRIGHT;md5=92289ed52a60b63ab715612ad2915603"
6
7inherit rust
8inherit cargo_common
9
10DEPENDS += "file-native python3-native"
11DEPENDS:append:class-native = " rust-llvm-native"
12DEPENDS:append:class-nativesdk = " nativesdk-rust-llvm"
13
14S = "${RUSTSRC}"
15
16# Use at your own risk, accepted values are stable, beta and nightly
17RUST_CHANNEL ?= "stable"
18PV .= "${@bb.utils.contains('RUST_CHANNEL', 'stable', '', '-${RUST_CHANNEL}', d)}"
19
20export FORCE_CRATE_HASH="${BB_TASKHASH}"
21
22RUST_ALTERNATE_EXE_PATH ?= "${STAGING_LIBDIR}/llvm-rust/bin/llvm-config"
23RUST_ALTERNATE_EXE_PATH_NATIVE = "${STAGING_LIBDIR_NATIVE}/llvm-rust/bin/llvm-config"
24
25# We don't want to use bitbakes vendoring because the rust sources do their
26# own vendoring.
27CARGO_DISABLE_BITBAKE_VENDORING = "1"
28
29# We can't use RUST_BUILD_SYS here because that may be "musl" if
30# TCLIBC="musl". Snapshots are always -unknown-linux-gnu
31setup_cargo_environment () {
32 # The first step is to build bootstrap and some early stage tools,
33 # these are build for the same target as the snapshot, e.g.
34 # x86_64-unknown-linux-gnu.
35 # Later stages are build for the native target (i.e. target.x86_64-linux)
36 cargo_common_do_configure
37}
38
39inherit rust-target-config
40
41do_rust_setup_snapshot () {
42 for installer in "${WORKDIR}/rust-snapshot-components/"*"/install.sh"; do
43 "${installer}" --prefix="${WORKDIR}/rust-snapshot" --disable-ldconfig
44 done
45
46 # Some versions of rust (e.g. 1.18.0) tries to find cargo in stage0/bin/cargo
47 # and fail without it there.
48 mkdir -p ${RUSTSRC}/build/${BUILD_SYS}
49 ln -sf ${WORKDIR}/rust-snapshot/ ${RUSTSRC}/build/${BUILD_SYS}/stage0
50
51 # Need to use uninative's loader if enabled/present since the library paths
52 # are used internally by rust and result in symbol mismatches if we don't
53 if [ ! -z "${UNINATIVE_LOADER}" -a -e "${UNINATIVE_LOADER}" ]; then
54 for bin in cargo rustc rustdoc; do
55 patchelf-uninative ${WORKDIR}/rust-snapshot/bin/$bin --set-interpreter ${UNINATIVE_LOADER}
56 done
57 fi
58}
59addtask rust_setup_snapshot after do_unpack before do_configure
60do_rust_setup_snapshot[dirs] += "${WORKDIR}/rust-snapshot"
61do_rust_setup_snapshot[vardepsexclude] += "UNINATIVE_LOADER"
62
63python do_configure() {
64 import json
65 try:
66 import configparser
67 except ImportError:
68 import ConfigParser as configparser
69
70 # toml is rather similar to standard ini like format except it likes values
71 # that look more JSON like. So for our purposes simply escaping all values
72 # as JSON seem to work fine.
73
74 e = lambda s: json.dumps(s)
75
76 config = configparser.RawConfigParser()
77
78 # [target.ARCH-poky-linux]
79 host_section = "target.{}".format(d.getVar('RUST_HOST_SYS', True))
80 config.add_section(host_section)
81
82 llvm_config_target = d.expand("${RUST_ALTERNATE_EXE_PATH}")
83 llvm_config_build = d.expand("${RUST_ALTERNATE_EXE_PATH_NATIVE}")
84 config.set(host_section, "llvm-config", e(llvm_config_target))
85
86 config.set(host_section, "cxx", e(d.expand("${RUST_TARGET_CXX}")))
87 config.set(host_section, "cc", e(d.expand("${RUST_TARGET_CC}")))
88 config.set(host_section, "linker", e(d.expand("${RUST_TARGET_CCLD}")))
89 if "musl" in host_section:
90 config.set(host_section, "musl-root", e(d.expand("${STAGING_DIR_HOST}${exec_prefix}")))
91
92 # If we don't do this rust-native will compile it's own llvm for BUILD.
93 # [target.${BUILD_ARCH}-unknown-linux-gnu]
94 build_section = "target.{}".format(d.getVar('RUST_BUILD_SYS', True))
95 if build_section != host_section:
96 config.add_section(build_section)
97
98 config.set(build_section, "llvm-config", e(llvm_config_build))
99
100 config.set(build_section, "cxx", e(d.expand("${RUST_BUILD_CXX}")))
101 config.set(build_section, "cc", e(d.expand("${RUST_BUILD_CC}")))
102 config.set(build_section, "linker", e(d.expand("${RUST_BUILD_CCLD}")))
103
104 target_section = "target.{}".format(d.getVar('RUST_TARGET_SYS', True))
105 if target_section != host_section and target_section != build_section:
106 config.add_section(target_section)
107
108 config.set(target_section, "llvm-config", e(llvm_config_target))
109
110 config.set(target_section, "cxx", e(d.expand("${RUST_TARGET_CXX}")))
111 config.set(target_section, "cc", e(d.expand("${RUST_TARGET_CC}")))
112 config.set(target_section, "linker", e(d.expand("${RUST_TARGET_CCLD}")))
113
114 # [llvm]
115 config.add_section("llvm")
116 config.set("llvm", "static-libstdcpp", e(False))
117 if "llvm" in (d.getVar('TC_CXX_RUNTIME') or ""):
118 config.set("llvm", "use-libcxx", e(True))
119
120 # [rust]
121 config.add_section("rust")
122 config.set("rust", "rpath", e(True))
123 config.set("rust", "channel", e(d.expand("${RUST_CHANNEL}")))
124
125 # Whether or not to optimize the compiler and standard library
126 config.set("rust", "optimize", e(True))
127
128 # Emits extraneous output from tests to ensure that failures of the test
129 # harness are debuggable just from logfiles
130 config.set("rust", "verbose-tests", e(True))
131
132 # [build]
133 config.add_section("build")
134 config.set("build", "submodules", e(False))
135 config.set("build", "docs", e(False))
136
137 rustc = d.expand("${WORKDIR}/rust-snapshot/bin/rustc")
138 config.set("build", "rustc", e(rustc))
139
140 # Support for the profiler runtime to generate e.g. coverage report,
141 # PGO etc.
142 config.set("build", "profiler", e(True))
143
144 cargo = d.expand("${WORKDIR}/rust-snapshot/bin/cargo")
145 config.set("build", "cargo", e(cargo))
146
147 config.set("build", "vendor", e(True))
148
149 if not "targets" in locals():
150 targets = [d.getVar("RUST_TARGET_SYS", True)]
151 config.set("build", "target", e(targets))
152
153 if not "hosts" in locals():
154 hosts = [d.getVar("RUST_HOST_SYS", True)]
155 config.set("build", "host", e(hosts))
156
157 # We can't use BUILD_SYS since that is something the rust snapshot knows
158 # nothing about when trying to build some stage0 tools (like fabricate)
159 config.set("build", "build", e(d.getVar("RUST_BUILD_SYS", True)))
160
161 # [install]
162 config.add_section("install")
163 # ./x.py install doesn't have any notion of "destdir"
164 # but we can prepend ${D} to all the directories instead
165 config.set("install", "prefix", e(d.getVar("D", True) + d.getVar("prefix", True)))
166 config.set("install", "bindir", e(d.getVar("D", True) + d.getVar("bindir", True)))
167 config.set("install", "libdir", e(d.getVar("D", True) + d.getVar("libdir", True)))
168 config.set("install", "datadir", e(d.getVar("D", True) + d.getVar("datadir", True)))
169 config.set("install", "mandir", e(d.getVar("D", True) + d.getVar("mandir", True)))
170
171 with open("config.toml", "w") as f:
172 f.write('changelog-seen = 2\n\n')
173 config.write(f)
174
175 # set up ${WORKDIR}/cargo_home
176 bb.build.exec_func("setup_cargo_environment", d)
177}
178
179
180rust_runx () {
181 echo "COMPILE ${PN}" "$@"
182
183 # CFLAGS, LDFLAGS, CXXFLAGS, CPPFLAGS are used by rust's build for a
184 # wide range of targets (not just TARGET). Yocto's settings for them will
185 # be inappropriate, avoid using.
186 unset CFLAGS
187 unset LDFLAGS
188 unset CXXFLAGS
189 unset CPPFLAGS
190
191 export RUSTFLAGS="${RUST_DEBUG_REMAP}"
192
193 # Copy the natively built llvm-config into the target so we can run it. Horrible,
194 # but works!
195 if [ ${RUST_ALTERNATE_EXE_PATH_NATIVE} != ${RUST_ALTERNATE_EXE_PATH} ]; then
196 mkdir -p `dirname ${RUST_ALTERNATE_EXE_PATH}`
197 cp ${RUST_ALTERNATE_EXE_PATH_NATIVE} ${RUST_ALTERNATE_EXE_PATH}
198 chrpath -d ${RUST_ALTERNATE_EXE_PATH}
199 fi
200
201 oe_cargo_fix_env
202
203 python3 src/bootstrap/bootstrap.py ${@oe.utils.parallel_make_argument(d, '-j %d')} "$@" --verbose
204}
205rust_runx[vardepsexclude] += "PARALLEL_MAKE"
206
207do_compile () {
208 rust_runx build
209}
210
211rust_do_install () {
212 mkdir -p ${D}${bindir}
213 cp build/${RUST_HOST_SYS}/stage2/bin/* ${D}${bindir}
214
215 mkdir -p ${D}${libdir}/rustlib
216 cp -pRd build/${RUST_HOST_SYS}/stage2/lib/* ${D}${libdir}
217 # Remove absolute symlink so bitbake doesn't complain
218 rm -f ${D}${libdir}/rustlib/src/rust
219}
220
221do_install () {
222 rust_do_install
223}