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 | |
| 10 | # Need to use our SDK's sh here, see #14878 |
| 11 | create_sdk_wrapper () { |
| 12 | file="$1" |
| 13 | shift |
| 14 | |
| 15 | cat <<- EOF > "${file}" |
| 16 | #!${base_prefix}/bin/sh |
| 17 | \$$1 \$@ |
| 18 | EOF |
| 19 | |
| 20 | chmod +x "$file" |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | do_install () { |
| 24 | # Rust requires /usr/lib to contain the libs. |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 25 | # The required structure is retained for simplicity. |
| 26 | SYS_LIBDIR=$(dirname ${D}${libdir}) |
| 27 | SYS_BINDIR=$(dirname ${D}${bindir}) |
| 28 | RUSTLIB_DIR=${SYS_LIBDIR}/${TARGET_SYS}/rustlib |
| 29 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 30 | install -d ${RUSTLIB_DIR} |
| 31 | install -m 0644 "${RUST_TARGETS_DIR}/${RUST_HOST_SYS}.json" "${RUSTLIB_DIR}" |
| 32 | install -m 0644 "${RUST_TARGETS_DIR}/${RUST_TARGET_SYS}.json" "${RUSTLIB_DIR}" |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 33 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 34 | # Uses SDK's CC as linker so linked binaries works out of box. |
| 35 | install -d ${SYS_BINDIR} |
| 36 | create_sdk_wrapper "${SYS_BINDIR}/target-rust-ccld" "CC" |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 37 | |
| 38 | ENV_SETUP_DIR=${D}${base_prefix}/environment-setup.d |
| 39 | mkdir "${ENV_SETUP_DIR}" |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 40 | RUST_ENV_SETUP_SH="${ENV_SETUP_DIR}/rust.sh" |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 41 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 42 | cat <<- EOF > "${RUST_ENV_SETUP_SH}" |
| 43 | 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] | 44 | export RUST_TARGET_PATH="\$OECORE_NATIVE_SYSROOT/usr/lib/${TARGET_SYS}/rustlib" |
| 45 | EOF |
| 46 | |
| 47 | chown -R root.root ${D} |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 48 | |
| 49 | CARGO_ENV_SETUP_SH="${ENV_SETUP_DIR}/cargo.sh" |
| 50 | cat <<- EOF > "${CARGO_ENV_SETUP_SH}" |
| 51 | export CARGO_HOME="\$OECORE_TARGET_SYSROOT/home/cargo" |
| 52 | mkdir -p "\$CARGO_HOME" |
| 53 | # Init the default target once, it might be otherwise user modified. |
| 54 | if [ ! -f "\$CARGO_HOME/config" ]; then |
| 55 | touch "\$CARGO_HOME/config" |
| 56 | echo "[build]" >> "\$CARGO_HOME/config" |
| 57 | echo 'target = "'${RUST_TARGET_SYS}'"' >> "\$CARGO_HOME/config" |
| 58 | echo '# TARGET_SYS' >> "\$CARGO_HOME/config" |
| 59 | echo '[target.'${RUST_TARGET_SYS}']' >> "\$CARGO_HOME/config" |
| 60 | echo 'linker = "target-rust-ccld"' >> "\$CARGO_HOME/config" |
| 61 | fi |
| 62 | |
| 63 | # Keep the below off as long as HTTP/2 is disabled. |
| 64 | export CARGO_HTTP_MULTIPLEXING=false |
| 65 | |
| 66 | export CARGO_HTTP_CAINFO="\$OECORE_NATIVE_SYSROOT/etc/ssl/certs/ca-certificates.crt" |
| 67 | EOF |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 68 | } |
| 69 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 70 | FILES:${PN} += "${base_prefix}/environment-setup.d" |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 71 | |