summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/rust/rust.inc
diff options
context:
space:
mode:
authorRandy MacLeod <Randy.MacLeod@windriver.com>2021-08-10 13:52:19 -0400
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-08-26 22:09:43 +0100
commit61e1570c6a09c1984e919e8c0a82a74c1a08d821 (patch)
treeaccab4b08aa3c62f098c9bb19399efb46906256a /meta/recipes-devtools/rust/rust.inc
parent705b1d757fa221614f4f72cabf0fac5884cb6bfd (diff)
downloadpoky-61e1570c6a09c1984e919e8c0a82a74c1a08d821.tar.gz
rust: initial merge of most of meta-rust
In the meta-rust repo at commit: 448047c Upgrade to 1.54.0 (#359) Make the required directories: mkdir ../oe-core/meta/recipes-devtools/rust mkdir ../oe-core/meta/recipes-devtools/cargo mkdir ../oe-core/meta/recipes-example and then: cp recipes-devtools/rust/* ../oe-core/meta/recipes-devtools/rust cp recipes-devtools/cargo/* ../oe-core/meta/recipes-devtools/cargo cp lib/crate.py ../oe-core/meta/lib cp recipes-example/* ../oe-core/meta/recipes-example cp conf/distro/include/rust_* ../oe-core/meta/conf/distro/include/ cp classes/* ../oe-core/meta/classes/ cp recipes-core/packagegroups/packagegroup-rust-cross-canadian.bb ../oe-core/meta/recipes-core/packagegroups (From OE-Core rev: 3ed57578cca93ff1ba4e0bf3f25566e10659a2f9) Signed-off-by: Randy MacLeod <Randy.MacLeod@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-devtools/rust/rust.inc')
-rw-r--r--meta/recipes-devtools/rust/rust.inc193
1 files changed, 193 insertions, 0 deletions
diff --git a/meta/recipes-devtools/rust/rust.inc b/meta/recipes-devtools/rust/rust.inc
new file mode 100644
index 0000000000..6045ab4d42
--- /dev/null
+++ b/meta/recipes-devtools/rust/rust.inc
@@ -0,0 +1,193 @@
1SUMMARY = "Rust compiler and runtime libaries"
2HOMEPAGE = "http://www.rust-lang.org"
3SECTION = "devel"
4LICENSE = "MIT | Apache-2.0"
5LIC_FILES_CHKSUM = "file://COPYRIGHT;md5=93a95682d51b4cb0a633a97046940ef0"
6
7inherit rust
8inherit cargo_common
9
10DEPENDS += "file-native python3-native"
11DEPENDS:append:class-native = " rust-llvm-native"
12
13S = "${RUSTSRC}"
14
15# We generate local targets, and need to be able to locate them
16export RUST_TARGET_PATH="${WORKDIR}/targets/"
17
18export FORCE_CRATE_HASH="${BB_TASKHASH}"
19
20RUST_ALTERNATE_EXE_PATH ?= "${STAGING_LIBDIR}/llvm-rust/bin/llvm-config"
21export YOCTO_ALTERNATE_EXE_PATH = "${RUST_ALTERNATE_EXE_PATH}"
22export YOCTO_ALTERNATE_MULTILIB_NAME = "/${BASELIB}"
23
24# We don't want to use bitbakes vendoring because the rust sources do their
25# own vendoring.
26CARGO_DISABLE_BITBAKE_VENDORING = "1"
27
28# We can't use RUST_BUILD_SYS here because that may be "musl" if
29# TCLIBC="musl". Snapshots are always -unknown-linux-gnu
30SNAPSHOT_BUILD_SYS = "${BUILD_ARCH}-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 printf '[target.%s]\n' "${SNAPSHOT_BUILD_SYS}" >> ${CARGO_HOME}/config
39 printf "linker = '%s'\n" "${RUST_BUILD_CCLD}" >> ${CARGO_HOME}/config
40}
41
42include rust-common.inc
43
44do_rust_setup_snapshot () {
45 for installer in "${WORKDIR}/rust-snapshot-components/"*"/install.sh"; do
46 "${installer}" --prefix="${WORKDIR}/rust-snapshot" --disable-ldconfig
47 done
48
49 # Some versions of rust (e.g. 1.18.0) tries to find cargo in stage0/bin/cargo
50 # and fail without it there.
51 mkdir -p ${RUSTSRC}/build/${BUILD_SYS}
52 ln -sf ${WORKDIR}/rust-snapshot/ ${RUSTSRC}/build/${BUILD_SYS}/stage0
53}
54addtask rust_setup_snapshot after do_unpack before do_configure
55do_rust_setup_snapshot[dirs] += "${WORKDIR}/rust-snapshot"
56
57python do_configure() {
58 import json
59 try:
60 import configparser
61 except ImportError:
62 import ConfigParser as configparser
63
64 # toml is rather similar to standard ini like format except it likes values
65 # that look more JSON like. So for our purposes simply escaping all values
66 # as JSON seem to work fine.
67
68 e = lambda s: json.dumps(s)
69
70 config = configparser.RawConfigParser()
71
72 # [target.ARCH-poky-linux]
73 target_section = "target.{}".format(d.getVar('TARGET_SYS', True))
74 config.add_section(target_section)
75
76 llvm_config = d.expand("${YOCTO_ALTERNATE_EXE_PATH}")
77 config.set(target_section, "llvm-config", e(llvm_config))
78
79 config.set(target_section, "cxx", e(d.expand("${RUST_TARGET_CXX}")))
80 config.set(target_section, "cc", e(d.expand("${RUST_TARGET_CC}")))
81
82 # If we don't do this rust-native will compile it's own llvm for BUILD.
83 # [target.${BUILD_ARCH}-unknown-linux-gnu]
84 target_section = "target.{}".format(d.getVar('SNAPSHOT_BUILD_SYS', True))
85 config.add_section(target_section)
86
87 config.set(target_section, "llvm-config", e(llvm_config))
88
89 config.set(target_section, "cxx", e(d.expand("${RUST_BUILD_CXX}")))
90 config.set(target_section, "cc", e(d.expand("${RUST_BUILD_CC}")))
91
92 # [rust]
93 config.add_section("rust")
94 config.set("rust", "rpath", e(True))
95 config.set("rust", "channel", e("stable"))
96
97 # Whether or not to optimize the compiler and standard library
98 config.set("rust", "optimize", e(True))
99
100 # [build]
101 config.add_section("build")
102 config.set("build", "submodules", e(False))
103 config.set("build", "docs", e(False))
104
105 rustc = d.expand("${WORKDIR}/rust-snapshot/bin/rustc")
106 config.set("build", "rustc", e(rustc))
107
108 # Support for the profiler runtime to generate e.g. coverage report,
109 # PGO etc.
110 config.set("build", "profiler", e(True))
111
112 cargo = d.expand("${WORKDIR}/rust-snapshot/bin/cargo")
113 config.set("build", "cargo", e(cargo))
114
115 config.set("build", "vendor", e(True))
116
117 if not "targets" in locals():
118 targets = [d.getVar("TARGET_SYS", True)]
119 config.set("build", "target", e(targets))
120
121 if not "hosts" in locals():
122 hosts = [d.getVar("HOST_SYS", True)]
123 config.set("build", "host", e(hosts))
124
125 # We can't use BUILD_SYS since that is something the rust snapshot knows
126 # nothing about when trying to build some stage0 tools (like fabricate)
127 config.set("build", "build", e(d.getVar("SNAPSHOT_BUILD_SYS", True)))
128
129 # [install]
130 config.add_section("install")
131 # ./x.py install doesn't have any notion of "destdir"
132 # but we can prepend ${D} to all the directories instead
133 config.set("install", "prefix", e(d.getVar("D", True) + d.getVar("prefix", True)))
134 config.set("install", "bindir", e(d.getVar("D", True) + d.getVar("bindir", True)))
135 config.set("install", "libdir", e(d.getVar("D", True) + d.getVar("libdir", True)))
136 config.set("install", "datadir", e(d.getVar("D", True) + d.getVar("datadir", True)))
137 config.set("install", "mandir", e(d.getVar("D", True) + d.getVar("mandir", True)))
138
139 with open("config.toml", "w") as f:
140 f.write('changelog-seen = 2\n\n')
141 config.write(f)
142
143 # set up ${WORKDIR}/cargo_home
144 bb.build.exec_func("setup_cargo_environment", d)
145}
146
147
148rust_runx () {
149 echo "COMPILE ${PN}" "$@"
150
151 # CFLAGS, LDFLAGS, CXXFLAGS, CPPFLAGS are used by rust's build for a
152 # wide range of targets (not just TARGET). Yocto's settings for them will
153 # be inappropriate, avoid using.
154 unset CFLAGS
155 unset LDFLAGS
156 unset CXXFLAGS
157 unset CPPFLAGS
158
159 oe_cargo_fix_env
160
161 python3 src/bootstrap/bootstrap.py ${@oe.utils.parallel_make_argument(d, '-j %d')} "$@" --verbose
162}
163rust_runx[vardepsexclude] += "PARALLEL_MAKE"
164
165do_compile () {
166 rust_runx build
167}
168
169rust_do_install () {
170 mkdir -p ${D}${bindir}
171 cp build/${HOST_SYS}/stage2/bin/* ${D}${bindir}
172
173 mkdir -p ${D}${libdir}/rustlib
174 cp -pRd build/${HOST_SYS}/stage2/lib/* ${D}${libdir}
175 # Remove absolute symlink so bitbake doesn't complain
176 rm -f ${D}${libdir}/rustlib/src/rust
177}
178
179rust_install_targets() {
180 # Install our custom target.json files
181 local td="${D}${libdir}/rustlib/"
182 install -d "$td"
183 for tgt in "${WORKDIR}/targets/"* ; do
184 install -m 0644 "$tgt" "$td"
185 done
186}
187
188
189do_install () {
190 rust_do_install
191 rust_install_targets
192}
193# ex: sts=4 et sw=4 ts=8