blob: 7bfef6d175970c181846821a5b1d494ccd789c11 [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 Williamsac13d5f2023-11-24 18:59:46 -060057 RUST_TARGET_TRIPLE=`echo ${RUST_TARGET_SYS} | tr '[:lower:]' '[:upper:]' | sed 's/-/_/g'`
58 RUST_HOST_TRIPLE=`echo ${RUST_HOST_SYS} | tr '[:lower:]' '[:upper:]' | sed 's/-/_/g'`
59 SDKLOADER=${@bb.utils.contains('SDK_ARCH', 'x86_64', 'ld-linux-x86-64.so.2', '', d)}${@bb.utils.contains('SDK_ARCH', 'i686', 'ld-linux.so.2', '', d)}${@bb.utils.contains('SDK_ARCH', 'aarch64', 'ld-linux-aarch64.so.1', '', d)}${@bb.utils.contains('SDK_ARCH', 'ppc64le', 'ld64.so.2', '', d)}${@bb.utils.contains('SDK_ARCH', 'riscv64', 'ld-linux-riscv64-lp64d.so.1', '', d)}
60
Patrick Williams92b42cb2022-09-03 06:53:57 -050061 cat <<- EOF > "${RUST_ENV_SETUP_SH}"
Patrick Williamsac13d5f2023-11-24 18:59:46 -060062 export CARGO_TARGET_${RUST_TARGET_TRIPLE}_RUSTFLAGS="--sysroot=\$OECORE_TARGET_SYSROOT/usr -C link-arg=--sysroot=\$OECORE_TARGET_SYSROOT"
63 export CARGO_TARGET_${RUST_HOST_TRIPLE}_RUNNER="\$OECORE_NATIVE_SYSROOT/lib/${SDKLOADER}"
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050064 export RUST_TARGET_PATH="\$OECORE_NATIVE_SYSROOT/usr/lib/${TARGET_SYS}/rustlib"
65 EOF
66
67 chown -R root.root ${D}
Patrick Williams92b42cb2022-09-03 06:53:57 -050068
69 CARGO_ENV_SETUP_SH="${ENV_SETUP_DIR}/cargo.sh"
70 cat <<- EOF > "${CARGO_ENV_SETUP_SH}"
71 export CARGO_HOME="\$OECORE_TARGET_SYSROOT/home/cargo"
72 mkdir -p "\$CARGO_HOME"
73 # Init the default target once, it might be otherwise user modified.
74 if [ ! -f "\$CARGO_HOME/config" ]; then
75 touch "\$CARGO_HOME/config"
76 echo "[build]" >> "\$CARGO_HOME/config"
77 echo 'target = "'${RUST_TARGET_SYS}'"' >> "\$CARGO_HOME/config"
78 echo '# TARGET_SYS' >> "\$CARGO_HOME/config"
79 echo '[target.'${RUST_TARGET_SYS}']' >> "\$CARGO_HOME/config"
80 echo 'linker = "target-rust-ccld"' >> "\$CARGO_HOME/config"
81 fi
82
83 # Keep the below off as long as HTTP/2 is disabled.
84 export CARGO_HTTP_MULTIPLEXING=false
85
86 export CARGO_HTTP_CAINFO="\$OECORE_NATIVE_SYSROOT/etc/ssl/certs/ca-certificates.crt"
87 EOF
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050088}
89
Patrick Williams92b42cb2022-09-03 06:53:57 -050090FILES:${PN} += "${base_prefix}/environment-setup.d"
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050091