Skip to content
This repository has been archived by the owner on Sep 30, 2021. It is now read-only.

Commit

Permalink
Allow for installing the library to be optional.
Browse files Browse the repository at this point in the history
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:

rust-lang/cargo#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 <jeffry.molanus@gmail.com>
  • Loading branch information
gila committed Aug 24, 2019
1 parent 29b02b0 commit 2c7e24f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 33 deletions.
12 changes: 12 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
73 changes: 40 additions & 33 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
#!/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.
#
# Usage: ./build.sh [extra-spdk-configure-args...]
# (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

# nasm is not recent enough on most main stream distro's so disable
# it by default, in SPDK however its enabled by default.

WANT_ISAL=0

for i in "$@" ; do
if [[ ${i} == "--with-isal" || ${i} == "--with-crypto" ]]; then
WANT_ISAL=1
break
fi
done

# 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)
Expand All @@ -55,45 +58,49 @@ cp defconfig_x86_64-nhm-linuxapp-gcc spdk/dpdk/config/defconfig_x86_64-nhm-linux
# to a CPU instruction, for this one really needs to read the manual
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 \
"$@"
TARGET_ARCHITECTURE=corei7 make -j $(nproc)
cd ..
# we invert the defaults here to reduce upstream divergence
CONFIGURE_OPTS="--with-dpdk-machine=nhm --with-iscsi-initiator --with-rdma"
CONFIGURE_OPTS+=" --with-internal-vhost-lib --disable-tests "

if [[ ${WANT_ISAL} == 0 ]]; then
echo "disabeling ISAL"
CONFIGURE_OPTS+=" --without-isal --without-crypto"
else
ARCHIVES="$ARCHIVES spdk/isa-l/.libs/libisal.a"
fi

(cd spdk; CFLAGS=${DISABLED_FLAGS} DPDK_EXTRA_FLAGS=${DISABLED_FLAGS} ./configure \
${CONFIGURE_OPTS} "$@"
TARGET_ARCHITECTURE=corei7 make -j "$(nproc)"
)

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"

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

0 comments on commit 2c7e24f

Please sign in to comment.