Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 1 | PN = "rust-cross-canadian-${TRANSLATED_TARGET_ARCH}" |
| 2 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 3 | inherit rust-target-config |
| 4 | inherit rust-common |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 5 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 6 | LICENSE = "MIT" |
| 7 | |
| 8 | MODIFYTOS = "0" |
| 9 | |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 10 | DEPENDS += "virtual/${SDK_PREFIX}gcc-crosssdk virtual/nativesdk-libc virtual/nativesdk-${SDK_PREFIX}compilerlibs" |
| 11 | |
| 12 | SRC_URI += "file://target-rust-ccld.c" |
| 13 | LIC_FILES_CHKSUM = "file://target-rust-ccld.c;md5=af4e0e29f81a34cffe05aa07c89e93e9;endline=7" |
| 14 | S = "${WORKDIR}" |
| 15 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 16 | # Need to use our SDK's sh here, see #14878 |
| 17 | create_sdk_wrapper () { |
| 18 | file="$1" |
| 19 | shift |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 20 | cat <<- EOF > "${file}" |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 21 | #!/bin/sh |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 22 | \$$1 \$@ |
| 23 | EOF |
| 24 | |
| 25 | chmod +x "$file" |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | do_install () { |
| 29 | # Rust requires /usr/lib to contain the libs. |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 30 | # The required structure is retained for simplicity. |
| 31 | SYS_LIBDIR=$(dirname ${D}${libdir}) |
| 32 | SYS_BINDIR=$(dirname ${D}${bindir}) |
| 33 | RUSTLIB_DIR=${SYS_LIBDIR}/${TARGET_SYS}/rustlib |
| 34 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 35 | install -d ${RUSTLIB_DIR} |
| 36 | install -m 0644 "${RUST_TARGETS_DIR}/${RUST_HOST_SYS}.json" "${RUSTLIB_DIR}" |
| 37 | install -m 0644 "${RUST_TARGETS_DIR}/${RUST_TARGET_SYS}.json" "${RUSTLIB_DIR}" |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 38 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 39 | # 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] | 40 | # We have a problem as rust sets LD_LIBRARY_PATH and this will break running host |
| 41 | # binaries (even /bin/sh) in the SDK as they detect a newer glibc from the SDK |
| 42 | # in those paths and we hit symbol errors. We saw particular problems with symbol |
| 43 | # mismatch on ubuntu1804 during development. To avoid this we have an SDK built |
| 44 | # binary which unsets LD_LIBRARY_PATH, which can then call the wrapper script |
| 45 | # where the context is easier to do the env maniupations needed |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 46 | install -d ${SYS_BINDIR} |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 47 | outfile="${SYS_BINDIR}/target-rust-ccld" |
| 48 | ${CC} ${WORKDIR}/target-rust-ccld.c -o $outfile |
| 49 | chmod +x "$outfile" |
| 50 | create_sdk_wrapper "${SYS_BINDIR}/target-rust-ccld-wrapper" "CC" |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 51 | |
| 52 | ENV_SETUP_DIR=${D}${base_prefix}/environment-setup.d |
| 53 | mkdir "${ENV_SETUP_DIR}" |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 54 | RUST_ENV_SETUP_SH="${ENV_SETUP_DIR}/rust.sh" |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 55 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 56 | cat <<- EOF > "${RUST_ENV_SETUP_SH}" |
| 57 | 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] | 58 | export RUST_TARGET_PATH="\$OECORE_NATIVE_SYSROOT/usr/lib/${TARGET_SYS}/rustlib" |
| 59 | EOF |
| 60 | |
| 61 | chown -R root.root ${D} |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 62 | |
| 63 | CARGO_ENV_SETUP_SH="${ENV_SETUP_DIR}/cargo.sh" |
| 64 | cat <<- EOF > "${CARGO_ENV_SETUP_SH}" |
| 65 | export CARGO_HOME="\$OECORE_TARGET_SYSROOT/home/cargo" |
| 66 | mkdir -p "\$CARGO_HOME" |
| 67 | # Init the default target once, it might be otherwise user modified. |
| 68 | if [ ! -f "\$CARGO_HOME/config" ]; then |
| 69 | touch "\$CARGO_HOME/config" |
| 70 | echo "[build]" >> "\$CARGO_HOME/config" |
| 71 | echo 'target = "'${RUST_TARGET_SYS}'"' >> "\$CARGO_HOME/config" |
| 72 | echo '# TARGET_SYS' >> "\$CARGO_HOME/config" |
| 73 | echo '[target.'${RUST_TARGET_SYS}']' >> "\$CARGO_HOME/config" |
| 74 | echo 'linker = "target-rust-ccld"' >> "\$CARGO_HOME/config" |
| 75 | fi |
| 76 | |
| 77 | # Keep the below off as long as HTTP/2 is disabled. |
| 78 | export CARGO_HTTP_MULTIPLEXING=false |
| 79 | |
| 80 | export CARGO_HTTP_CAINFO="\$OECORE_NATIVE_SYSROOT/etc/ssl/certs/ca-certificates.crt" |
| 81 | EOF |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 82 | } |
| 83 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 84 | FILES:${PN} += "${base_prefix}/environment-setup.d" |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 85 | |