blob: d569ac59f5256ba435f811d5b70e94884bc7d14b [file] [log] [blame]
Patrick Williams8e7b46e2023-05-01 14:19:06 -05001SUMMARY = "Rust compiler and runtime libaries (cross-canadian for ${TARGET_ARCH} target)"
Andrew Geisslerd159c7f2021-09-02 21:05:58 -05002PN = "rust-cross-canadian-${TRANSLATED_TARGET_ARCH}"
3
Patrick Williams92b42cb2022-09-03 06:53:57 -05004inherit rust-target-config
5inherit rust-common
Andrew Geisslerd159c7f2021-09-02 21:05:58 -05006
Patrick Williams92b42cb2022-09-03 06:53:57 -05007LICENSE = "MIT"
8
9MODIFYTOS = "0"
10
Andrew Geissler028142b2023-05-05 11:29:21 -050011DEPENDS += "virtual/${SDK_PREFIX}gcc virtual/nativesdk-libc virtual/nativesdk-${SDK_PREFIX}compilerlibs"
Andrew Geissler87f5cff2022-09-30 13:13:31 -050012
13SRC_URI += "file://target-rust-ccld.c"
14LIC_FILES_CHKSUM = "file://target-rust-ccld.c;md5=af4e0e29f81a34cffe05aa07c89e93e9;endline=7"
15S = "${WORKDIR}"
16
Patrick Williams92b42cb2022-09-03 06:53:57 -050017# Need to use our SDK's sh here, see #14878
18create_sdk_wrapper () {
19 file="$1"
20 shift
Patrick Williams92b42cb2022-09-03 06:53:57 -050021 cat <<- EOF > "${file}"
Andrew Geissler87f5cff2022-09-30 13:13:31 -050022 #!/bin/sh
Patrick Williams92b42cb2022-09-03 06:53:57 -050023 \$$1 \$@
24 EOF
25
26 chmod +x "$file"
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050027}
28
29do_install () {
30 # Rust requires /usr/lib to contain the libs.
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050031 # The required structure is retained for simplicity.
32 SYS_LIBDIR=$(dirname ${D}${libdir})
33 SYS_BINDIR=$(dirname ${D}${bindir})
34 RUSTLIB_DIR=${SYS_LIBDIR}/${TARGET_SYS}/rustlib
35
Patrick Williams92b42cb2022-09-03 06:53:57 -050036 install -d ${RUSTLIB_DIR}
37 install -m 0644 "${RUST_TARGETS_DIR}/${RUST_HOST_SYS}.json" "${RUSTLIB_DIR}"
38 install -m 0644 "${RUST_TARGETS_DIR}/${RUST_TARGET_SYS}.json" "${RUSTLIB_DIR}"
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050039
Patrick Williams92b42cb2022-09-03 06:53:57 -050040 # Uses SDK's CC as linker so linked binaries works out of box.
Andrew Geissler87f5cff2022-09-30 13:13:31 -050041 # We have a problem as rust sets LD_LIBRARY_PATH and this will break running host
42 # binaries (even /bin/sh) in the SDK as they detect a newer glibc from the SDK
43 # in those paths and we hit symbol errors. We saw particular problems with symbol
44 # mismatch on ubuntu1804 during development. To avoid this we have an SDK built
45 # binary which unsets LD_LIBRARY_PATH, which can then call the wrapper script
46 # where the context is easier to do the env maniupations needed
Patrick Williams92b42cb2022-09-03 06:53:57 -050047 install -d ${SYS_BINDIR}
Andrew Geissler87f5cff2022-09-30 13:13:31 -050048 outfile="${SYS_BINDIR}/target-rust-ccld"
49 ${CC} ${WORKDIR}/target-rust-ccld.c -o $outfile
50 chmod +x "$outfile"
51 create_sdk_wrapper "${SYS_BINDIR}/target-rust-ccld-wrapper" "CC"
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050052
53 ENV_SETUP_DIR=${D}${base_prefix}/environment-setup.d
54 mkdir "${ENV_SETUP_DIR}"
Patrick Williams92b42cb2022-09-03 06:53:57 -050055 RUST_ENV_SETUP_SH="${ENV_SETUP_DIR}/rust.sh"
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050056
Patrick Williams92b42cb2022-09-03 06:53:57 -050057 cat <<- EOF > "${RUST_ENV_SETUP_SH}"
58 export RUSTFLAGS="--sysroot=\$OECORE_TARGET_SYSROOT/usr -C link-arg=--sysroot=\$OECORE_TARGET_SYSROOT"
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050059 export RUST_TARGET_PATH="\$OECORE_NATIVE_SYSROOT/usr/lib/${TARGET_SYS}/rustlib"
60 EOF
61
62 chown -R root.root ${D}
Patrick Williams92b42cb2022-09-03 06:53:57 -050063
64 CARGO_ENV_SETUP_SH="${ENV_SETUP_DIR}/cargo.sh"
65 cat <<- EOF > "${CARGO_ENV_SETUP_SH}"
66 export CARGO_HOME="\$OECORE_TARGET_SYSROOT/home/cargo"
67 mkdir -p "\$CARGO_HOME"
68 # Init the default target once, it might be otherwise user modified.
69 if [ ! -f "\$CARGO_HOME/config" ]; then
70 touch "\$CARGO_HOME/config"
71 echo "[build]" >> "\$CARGO_HOME/config"
72 echo 'target = "'${RUST_TARGET_SYS}'"' >> "\$CARGO_HOME/config"
73 echo '# TARGET_SYS' >> "\$CARGO_HOME/config"
74 echo '[target.'${RUST_TARGET_SYS}']' >> "\$CARGO_HOME/config"
75 echo 'linker = "target-rust-ccld"' >> "\$CARGO_HOME/config"
76 fi
77
78 # Keep the below off as long as HTTP/2 is disabled.
79 export CARGO_HTTP_MULTIPLEXING=false
80
81 export CARGO_HTTP_CAINFO="\$OECORE_NATIVE_SYSROOT/etc/ssl/certs/ca-certificates.crt"
82 EOF
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050083}
84
Patrick Williams92b42cb2022-09-03 06:53:57 -050085FILES:${PN} += "${base_prefix}/environment-setup.d"
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050086