From 78bdc5fd0403c9b129d32946e6f087ac569977de Mon Sep 17 00:00:00 2001 From: Jeffry Molanus Date: Fri, 23 Aug 2019 21:27:55 +0200 Subject: [PATCH] Allow for installing the library to be optional. This change makes it such that during bindgen, we will look for the library in build/. If the user chooses the move (or copy) it to the system default search paths then we will pick it up during runtime. If the user does _not_ move the library, (who would?) we must specify the rpath during linking phase. There are various ways to do this, either by `RUSTFLAGS=.. cargo build` or by creating a `./cargo/config` and specify per target the desired flags. Within the `config` file however, we can not anticipate the absolute path see: https://github.com/rust-lang/cargo/issues/5077 Instead, Mayastor now has a Makefile that does this for people, so whoever wants to give it a swirl can do so without having to install "stuff" outside of the repo. Lastly, as people might want to use Ubuntu 18.04, the default in the Makefile is to not include ISA-L and crypto as those require a NASM version not available in 18.04 Signed-off-by: Jeffry Molanus --- build.rs | 12 ++++++++++++ build.sh | 58 ++++++++++++++++++++++++++++---------------------------- 2 files changed, 41 insertions(+), 29 deletions(-) diff --git a/build.rs b/build.rs index d0ada3d..0b2b375 100644 --- a/build.rs +++ b/build.rs @@ -48,6 +48,7 @@ fn find_spdk_lib(out_path: &PathBuf) -> Result<()> { .arg("-o") .arg(o_file) .arg(c_file) + .arg("-L ./build") .arg("-lspdk_fat") .output() .expect("Failed to execute cc"); @@ -121,6 +122,13 @@ fn main() { .clang_arg("-Ispdk/include") .clang_arg("-Ispdk/lib") .rustfmt_bindings(true) + .whitelist_function("^spdk.*") + .whitelist_function("*.aio.*") + .whitelist_function("*.iscsi.*") + .whitelist_function("*.lvs.*") + .whitelist_function("*.lvol.*") + .whitelist_var("^SPDK.*") + .whitelist_var("^spdk.*") .trust_clang_mangling(false) .layout_tests(false) .derive_default(true) @@ -139,6 +147,10 @@ fn main() { .expect("Couldn't write bindings!"); // spdk lib + println!( + "cargo:rustc-link-search={}", + format!("{}/build", std::env::current_dir().unwrap().display()) + ); println!("cargo:rustc-link-lib=spdk_fat"); // OS libs diff --git a/build.sh b/build.sh index 76155e9..96a57be 100755 --- a/build.sh +++ b/build.sh @@ -1,9 +1,9 @@ -#!/bin/sh -e +#!/bin/bash -e # This is a script which automates building of spdk fat library containing all -# spdk, dpdk and isa-l object files. It would have been nice if this was part -# of spdk makefiles so that anyone could run just configure && make to get the -# fat lib. But it's not a hot candidate for upstreaming since we do this only +# spdk, dpdk and optionally the isa-l object files. It would have been nice if +# this was part of spdk makefiles so that anyone could run just configure && make +# to get the fat lib. But it's not a hot candidate for upstreaming since we do this only # to work around limitations of rust build system, which is not a good reason # for changing spdk makefiles. # @@ -11,25 +11,16 @@ # (i.e. ./build.sh --enable-debug) BASEDIR=$(dirname "$0") -cd $BASEDIR +cd ${BASEDIR} # checkout spdk sources -[ -d spdk/.git ] || git submodule update --init --recursive +[[ -d spdk/.git ]] || git submodule update --init --recursive # We need to disable some CPU specific optimization flags because we cannot # know which flavour of x86-64 cpu the binary will run on. # corei7 with certain cpu flags disabled seems to be a reasonable compromise. cp defconfig_x86_64-nhm-linuxapp-gcc spdk/dpdk/config/defconfig_x86_64-nhm-linuxapp-gcc -# *should* not be needed to specify the -nmno-xxx however for certain -# it does. There are some existing bugs out there where either -# or gcc do not fully do the right thing, general consensus is that -# you are "tuning" CPU flags, you know what you are doing so these issues -# not treated with high priority. -# -# Ideally, we would use -march=x86-64, however DPDK *requires* at least -#.1 corei7 is the first CPU family that supports this. -# # The current supported CPU extensions we use are: # # MODE64 (call) @@ -56,44 +47,53 @@ cp defconfig_x86_64-nhm-linuxapp-gcc spdk/dpdk/config/defconfig_x86_64-nhm-linux DISABLED_FLAGS="-mno-movbe -mno-lzcnt -mno-bmi -mno-bmi2" cd spdk -CFLAGS=$DISABLED_FLAGS DPDK_EXTRA_FLAGS=$DISABLED_FLAGS ./configure \ - --with-dpdk-machine=nhm \ - --with-iscsi-initiator \ - --with-rdma \ - --with-internal-vhost-lib \ - --disable-tests \ - "$@" +CFLAGS=${DISABLED_FLAGS} DPDK_EXTRA_FLAGS=${DISABLED_FLAGS} ./configure \ + --with-dpdk-machine=nhm \ + --with-iscsi-initiator \ + --with-rdma \ + --with-internal-vhost-lib \ + --disable-tests \ + "$@" TARGET_ARCHITECTURE=corei7 make -j $(nproc) cd .. ARCHIVES= for f in spdk/build/lib/libspdk_*.a; do # avoid test mock lib with undefined symbols - if [ "$f" != spdk/build/lib/libspdk_ut_mock.a ]; then + if [[ "$f" != spdk/build/lib/libspdk_ut_mock.a ]]; then ARCHIVES="$ARCHIVES $f" fi done for f in spdk/dpdk/build/lib/librte_*.a; do # avoid name clashes - spdk has its own vhost implementation - if [ "$f" != spdk/dpdk/build/lib/librte_vhost.a ]; then + if [[ "$f" != spdk/dpdk/build/lib/librte_vhost.a ]]; then ARCHIVES="$ARCHIVES $f" fi done -ARCHIVES="$ARCHIVES spdk/isa-l/.libs/libisal.a" +# nasm is not recent enough on most main stream distro's so disable +# it by default + +for i in "$@" ; do + if [[ ${i} == "--with-isal" || ${i} == "--with-crypto" ]]; then + ARCHIVES="$ARCHIVES spdk/isa-l/.libs/libisal.a" + break + fi +done echo echo "Constructing libspdk_fat.so from following object archives:" -for a in $ARCHIVES; do +for a in ${ARCHIVES}; do echo " $a" done -[ -d build ] || mkdir build +[[ -d build ]] || mkdir build cc -shared -o build/libspdk_fat.so \ -lc -lrdmacm -laio -libverbs -liscsi -lnuma -ldl -lrt -luuid -lcrypto \ - -Wl,--whole-archive $ARCHIVES -Wl,--no-whole-archive + -Wl,--whole-archive ${ARCHIVES} -Wl,--no-whole-archive echo -echo "Don't forget to install build/libspdk_fat.so to dir where it can be found by linker" +echo "Feel free to move the library to one of your default library search paths." +echo "It is not needed as during runtime we will look for it within the repo." echo