blob: 17f933959f5fe8c0afaeda46714eaf45bbc4f4d7 [file] [log] [blame]
Andrew Geisslerd159c7f2021-09-02 21:05:58 -05001PN = "rust-cross-canadian-${TRANSLATED_TARGET_ARCH}"
2
Patrick Williams92b42cb2022-09-03 06:53:57 -05003inherit rust-target-config
4inherit rust-common
Andrew Geisslerd159c7f2021-09-02 21:05:58 -05005
Patrick Williams92b42cb2022-09-03 06:53:57 -05006LICENSE = "MIT"
7
8MODIFYTOS = "0"
9
Andrew Geissler87f5cff2022-09-30 13:13:31 -050010DEPENDS += "virtual/${SDK_PREFIX}gcc-crosssdk virtual/nativesdk-libc virtual/nativesdk-${SDK_PREFIX}compilerlibs"
11
12SRC_URI += "file://target-rust-ccld.c"
13LIC_FILES_CHKSUM = "file://target-rust-ccld.c;md5=af4e0e29f81a34cffe05aa07c89e93e9;endline=7"
14S = "${WORKDIR}"
15
Patrick Williams92b42cb2022-09-03 06:53:57 -050016# Need to use our SDK's sh here, see #14878
17create_sdk_wrapper () {
18 file="$1"
19 shift
Patrick Williams92b42cb2022-09-03 06:53:57 -050020 cat <<- EOF > "${file}"
Andrew Geissler87f5cff2022-09-30 13:13:31 -050021 #!/bin/sh
Patrick Williams92b42cb2022-09-03 06:53:57 -050022 \$$1 \$@
23 EOF
24
25 chmod +x "$file"
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050026}
27
28do_install () {
29 # Rust requires /usr/lib to contain the libs.
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050030 # 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 Williams92b42cb2022-09-03 06:53:57 -050035 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 Geisslerd159c7f2021-09-02 21:05:58 -050038
Patrick Williams92b42cb2022-09-03 06:53:57 -050039 # Uses SDK's CC as linker so linked binaries works out of box.
Andrew Geissler87f5cff2022-09-30 13:13:31 -050040 # 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 Williams92b42cb2022-09-03 06:53:57 -050046 install -d ${SYS_BINDIR}
Andrew Geissler87f5cff2022-09-30 13:13:31 -050047 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 Geisslerd159c7f2021-09-02 21:05:58 -050051
52 ENV_SETUP_DIR=${D}${base_prefix}/environment-setup.d
53 mkdir "${ENV_SETUP_DIR}"
Patrick Williams92b42cb2022-09-03 06:53:57 -050054 RUST_ENV_SETUP_SH="${ENV_SETUP_DIR}/rust.sh"
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050055
Patrick Williams92b42cb2022-09-03 06:53:57 -050056 cat <<- EOF > "${RUST_ENV_SETUP_SH}"
57 export RUSTFLAGS="--sysroot=\$OECORE_TARGET_SYSROOT/usr -C link-arg=--sysroot=\$OECORE_TARGET_SYSROOT"
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050058 export RUST_TARGET_PATH="\$OECORE_NATIVE_SYSROOT/usr/lib/${TARGET_SYS}/rustlib"
59 EOF
60
61 chown -R root.root ${D}
Patrick Williams92b42cb2022-09-03 06:53:57 -050062
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 Geisslerd159c7f2021-09-02 21:05:58 -050082}
83
Patrick Williams92b42cb2022-09-03 06:53:57 -050084FILES:${PN} += "${base_prefix}/environment-setup.d"
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050085