rust-bin: common code for building libs
Libraries that overlap with the standard library must have explicit extern declarations. Without something like pkg-config where the libraries can publish this info, it's easiest to just hard-code the list of troublesome libraries.
This commit is contained in:
committed by
Steven Walter
parent
8a6f084c66
commit
837000f68a
@@ -9,14 +9,77 @@ FILES_${PN} += "${rustlibdir}/*.so"
|
||||
FILES_${PN}-dev += "${rustlibdir}/*.rlib"
|
||||
FILES_${PN}-dbg += "${rustlibdir}/.debug"
|
||||
|
||||
RUSTC_ARCHFLAGS += "-C opt-level=3 -L ${STAGING_DIR_HOST}/${rustlibdir}"
|
||||
RUSTC_ARCHFLAGS += "-C opt-level=3 -g -L ${STAGING_DIR_HOST}/${rustlibdir}"
|
||||
EXTRA_OEMAKE += 'RUSTC_ARCHFLAGS="${RUSTC_ARCHFLAGS}"'
|
||||
|
||||
# Some libraries alias with the standard library but libstd is configured to
|
||||
# make it difficult or imposisble to use its version. Unfortunately libstd
|
||||
# must be explicitly overridden using extern.
|
||||
OVERLAP_LIBS = "\
|
||||
libc \
|
||||
log \
|
||||
getopts \
|
||||
"
|
||||
def get_overlap_deps(d):
|
||||
deps = d.getVar("DEPENDS").split()
|
||||
overlap_deps = []
|
||||
for o in d.getVar("OVERLAP_LIBS", True).split():
|
||||
l = len([o for dep in deps if (o + '-rs' in dep)])
|
||||
if l > 0:
|
||||
overlap_deps.append(o)
|
||||
return " ".join(overlap_deps)
|
||||
OVERLAP_DEPS = "${@get_overlap_deps(d)}"
|
||||
|
||||
# Prevents multiple static copies of standard library modules
|
||||
# See https://github.com/rust-lang/rust/issues/19680
|
||||
RUSTC_FLAGS += "-C prefer-dynamic"
|
||||
|
||||
rustlib="${libdir}/${TUNE_PKGARCH}${TARGET_VENDOR}-${TARGET_OS}/rustlib/${HOST_SYS}/lib"
|
||||
CRATE_NAME ?= "${@d.getVar('BPN', True).replace('-rs', '').replace('-', '_')}"
|
||||
BINNAME ?= "${BPN}"
|
||||
LIBNAME ?= "lib${CRATE_NAME}"
|
||||
CRATE_TYPE ?= "dylib"
|
||||
BIN_SRC ?= "${S}/src/main.rs"
|
||||
LIB_SRC ?= "${S}/src/lib.rs"
|
||||
|
||||
get_overlap_externs () {
|
||||
externs=
|
||||
for dep in ${OVERLAP_DEPS}; do
|
||||
extern=$(ls ${STAGING_DIR_HOST}/${rustlibdir}/lib$dep.{so,rlib} 2>/dev/null \
|
||||
| awk '{print $1}');
|
||||
if [ -n "$extern" ]; then
|
||||
externs="$externs --extern $dep=$extern"
|
||||
else
|
||||
echo "$dep in depends but no such library found in ${rustlibdir}!" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
echo "$externs"
|
||||
}
|
||||
|
||||
oe_compile_rust_lib () {
|
||||
rm -rf ${LIBNAME}.{rlib,so}
|
||||
oe_runrustc $(get_overlap_externs) ${LIB_SRC} --crate-name=${CRATE_NAME} --crate-type=${CRATE_TYPE} "$@"
|
||||
}
|
||||
oe_compile_rust_lib[vardeps] += "get_overlap_externs"
|
||||
|
||||
oe_compile_rust_bin () {
|
||||
rm -rf ${BINNAME}
|
||||
oe_runrustc $(get_overlap_externs) ${BIN_SRC} -o ${BINNAME} "$@"
|
||||
}
|
||||
oe_compile_rust_bin[vardeps] += "get_overlap_externs"
|
||||
|
||||
oe_install_rust_lib () {
|
||||
for lib in $(ls ${LIBNAME}.{so,rlib} 2>/dev/null); do
|
||||
echo Installing $lib
|
||||
install -D -m 644 $lib ${D}/${rustlibdir}/$lib
|
||||
done
|
||||
}
|
||||
|
||||
oe_install_rust_bin () {
|
||||
echo Installing ${BINNAME}
|
||||
install -D -m 644 ${BINNAME} ${D}/${bindir}/${BINNAME}
|
||||
}
|
||||
|
||||
do_rust_bin_fixups() {
|
||||
for f in `find ${PKGD} -name '*.so*'`; do
|
||||
|
||||
Reference in New Issue
Block a user