Patrick Williams | 8e7b46e | 2023-05-01 14:19:06 -0500 | [diff] [blame] | 1 | SUMMARY = "Rust compiler and runtime libaries (cross-canadian for ${TARGET_ARCH} target)" |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 2 | PN = "rust-cross-canadian-${TRANSLATED_TARGET_ARCH}" |
| 3 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 4 | inherit rust-target-config |
| 5 | inherit rust-common |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 6 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 7 | LICENSE = "MIT" |
| 8 | |
| 9 | MODIFYTOS = "0" |
| 10 | |
Andrew Geissler | 028142b | 2023-05-05 11:29:21 -0500 | [diff] [blame] | 11 | DEPENDS += "virtual/${SDK_PREFIX}gcc virtual/nativesdk-libc virtual/nativesdk-${SDK_PREFIX}compilerlibs" |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 12 | |
| 13 | SRC_URI += "file://target-rust-ccld.c" |
| 14 | LIC_FILES_CHKSUM = "file://target-rust-ccld.c;md5=af4e0e29f81a34cffe05aa07c89e93e9;endline=7" |
| 15 | S = "${WORKDIR}" |
| 16 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 17 | # Need to use our SDK's sh here, see #14878 |
| 18 | create_sdk_wrapper () { |
| 19 | file="$1" |
| 20 | shift |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 21 | cat <<- EOF > "${file}" |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 22 | #!/bin/sh |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 23 | \$$1 \$@ |
| 24 | EOF |
| 25 | |
| 26 | chmod +x "$file" |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | do_install () { |
| 30 | # Rust requires /usr/lib to contain the libs. |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 31 | # 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 Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 36 | 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 Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 39 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 40 | # Uses SDK's CC as linker so linked binaries works out of box. |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 41 | # 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 Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 47 | install -d ${SYS_BINDIR} |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 48 | 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 Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 52 | |
| 53 | ENV_SETUP_DIR=${D}${base_prefix}/environment-setup.d |
| 54 | mkdir "${ENV_SETUP_DIR}" |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 55 | RUST_ENV_SETUP_SH="${ENV_SETUP_DIR}/rust.sh" |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 56 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 57 | cat <<- EOF > "${RUST_ENV_SETUP_SH}" |
| 58 | export RUSTFLAGS="--sysroot=\$OECORE_TARGET_SYSROOT/usr -C link-arg=--sysroot=\$OECORE_TARGET_SYSROOT" |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 59 | export RUST_TARGET_PATH="\$OECORE_NATIVE_SYSROOT/usr/lib/${TARGET_SYS}/rustlib" |
| 60 | EOF |
| 61 | |
| 62 | chown -R root.root ${D} |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 63 | |
| 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 Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 83 | } |
| 84 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 85 | FILES:${PN} += "${base_prefix}/environment-setup.d" |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 86 | |