Skip to content

Commit

Permalink
feat(ci): refactoring nix scripts
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Savitskiy <[email protected]>
  • Loading branch information
dsavitskiy committed Jul 5, 2024
1 parent b62829d commit 6336ae3
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 752 deletions.
176 changes: 59 additions & 117 deletions ci.nix
Original file line number Diff line number Diff line change
@@ -1,130 +1,72 @@
{ nospdk ? false, norust ? false, spdk_rel ? false, asan ? false }:
{ rust ? "stable"
, spdk ? "develop"
, spdk-path ? null
} @ args:
let
sources = import ./nix/sources.nix;

pkgs = import sources.nixpkgs {
overlays =
[ (_: _: { inherit sources; }) (import ./nix/overlay.nix { }) ];
overlays = [
(_: _: { inherit sources; })
(import ./nix/overlay.nix { })
];
};
in
with pkgs;
let
nospdk_moth =
"You have requested environment without SPDK, you should provide it!";
norust_moth =
"You have requested environment without RUST, you should provide it!";
norustc_msg = "no rustc, use rustup tool to install it";
channel = import ./nix/lib/rust.nix { inherit sources; };

# python environment for test/python
pytest_inputs = python3.withPackages
pytest_inputs = with pkgs; python3.withPackages
(ps: with ps; [ virtualenv grpcio grpcio-tools asyncssh black ]);
spdk = if (!spdk_rel) then libspdk-dev else libspdk;
in
mkShell {
name = "io-engine-dev-shell";
# fortify does not work with -O0 which is used by spdk when --enable-debug
hardeningDisable = [ "fortify" ];
buildInputs = [
autoconf
automake
clang
cowsay
docker
docker-compose
e2fsprogs
etcd
fio
gdb
git
gnuplot
kubernetes-helm
libaio
libbsd
libexecinfo
libnvme
libpcap
libunwind
liburing
llvmPackages.bintools
llvmPackages.libclang
meson
ninja
nodejs-16_x
numactl
nvme-cli
openssl
pkg-config
pre-commit
procps
pytest_inputs
python3
udev
utillinux
xfsprogs
yasm
] ++ (if (nospdk) then [ spdk.buildInputs ] else [ spdk ])
++ pkgs.lib.optional (!norust && asan) channel.asan
++ pkgs.lib.optional (!norust && !asan) channel.stable
++ pkgs.lib.optional (!norust) channel.nightly;

RUST_NIGHTLY_PATH = channel.nightly;
LIBCLANG_PATH = io-engine.LIBCLANG_PATH;
PROTOC = io-engine.PROTOC;
PROTOC_INCLUDE = io-engine.PROTOC_INCLUDE;
SPDK_PATH = if nospdk then null else "${spdk}";
FIO_SPDK = if nospdk then null else "${spdk}/fio/spdk_nvme";
ETCD_BIN = "${etcd}/bin/etcd";
LVM_BINS = "${lvm2.bin}/bin";
shellAttrs = import ./spdk-rs/nix/shell {
inherit rust;
inherit spdk;
inherit spdk-path;
inherit sources;
inherit pkgs;

IO_ENGINE_DIR = if asan then "target/x86_64-unknown-linux-gnu/debug" else "target/debug";
cfg = {
buildInputs = with pkgs; [
docker
docker-compose
e2fsprogs
etcd
gdb
git
gnuplot
kubernetes-helm
nodejs-16_x
numactl
pytest_inputs
udev
xfsprogs
];

# ASAN-related Cargo settings.
ASAN_ENABLE = if asan then "1" else null;
ASAN_OPTIONS = if asan then "detect_leaks=0" else null;
ASAN_BUILD_ENV = if asan then "shell" else null;
RUSTFLAGS = if asan then "-Zsanitizer=address" else null;
CARGO_BUILD_RUSTFLAGS = if asan then "-Zbuild-std" else null;
CARGO_BUILD_TARGET = if asan then "x86_64-unknown-linux-gnu" else null;
CARGO_PROFILE_DEV_PANIC = if asan then "unwind" else null;
RUST_BACKTRACE = if asan then "full" else null;
shellEnv = with pkgs; {
PROTOC = io-engine.PROTOC;
PROTOC_INCLUDE = io-engine.PROTOC_INCLUDE;
ETCD_BIN = "${etcd}/bin/etcd";
LVM_BINS = "${lvm2.bin}/bin";
};

shellHook = ''
export FIO="$(which fio 2> /dev/null)"
${pkgs.lib.optionalString (asan) "export LLVM_SYMBOLIZER_DIR=$(dirname $(realpath $(which llvm-symbolizer)))"}
shellHook = ''
# SRCDIR is needed by docker-compose files as it requires absolute paths
export SRCDIR=`pwd`
${pkgs.lib.optionalString (asan) "echo 'AddressSanitizer is enabled, forcing nightly rustc.'"}
${pkgs.lib.optionalString (asan) "echo ' ASAN_ENABLE :' $\{ASAN_ENABLE\}"}
${pkgs.lib.optionalString (asan) "echo ' ASAN_OPTIONS :' $\{ASAN_OPTIONS\}"}
${pkgs.lib.optionalString (asan) "echo ' RUSTFLAGS :' $\{RUSTFLAGS\}"}
${pkgs.lib.optionalString (asan) "echo ' CARGO_BUILD_RUSTFLAGS :' $\{CARGO_BUILD_RUSTFLAGS\}"}
${pkgs.lib.optionalString (asan) "echo ' CARGO_BUILD_TARGET :' $\{CARGO_BUILD_TARGET\}"}
${pkgs.lib.optionalString (asan) "echo ' CARGO_PROFILE_DEV_PANIC :' $\{CARGO_PROFILE_DEV_PANIC\}"}
${pkgs.lib.optionalString (asan) "echo ' RUST_BACKTRACE :' $\{RUST_BACKTRACE\}"}
${pkgs.lib.optionalString (asan) "echo ' LLVM_SYMBOLIZER_DIR :' $\{LLVM_SYMBOLIZER_DIR\}"}
${pkgs.lib.optionalString (asan) "echo"}
export PATH="$PATH:$(pwd)/scripts/nix-sudo"
echo 'FIO version :' $(fio --version 2> /dev/null)
echo 'FIO path :' $FIO
${pkgs.lib.optionalString (!nospdk) "echo 'SPDK version :' $(echo $SPDK_PATH | sed 's/.*libspdk-//g')"}
${pkgs.lib.optionalString (!nospdk) "echo 'SPDK path :' $SPDK_PATH"}
${pkgs.lib.optionalString (!nospdk) "echo 'SPDK FIO plugin :' $FIO_SPDK"}
echo 'LVM path :' $LVM_BINS
${pkgs.lib.optionalString (!norust) "echo 'Rust version :' $(rustc --version 2> /dev/null || echo '${norustc_msg}')"}
${pkgs.lib.optionalString (!norust) "echo 'Rust path :' $(which rustc 2> /dev/null || echo '${norustc_msg}')"}
echo 'I/O engine dir :' $IO_ENGINE_DIR
${pkgs.lib.optionalString (nospdk) "cowsay ${nospdk_moth}"}
${pkgs.lib.optionalString (nospdk) "export CFLAGS=-msse4"}
${pkgs.lib.optionalString (nospdk) "echo"}
${pkgs.lib.optionalString (norust) "cowsay ${norust_moth}"}
${pkgs.lib.optionalString (norust) "echo 'Hint: use rustup tool.'"}
${pkgs.lib.optionalString (norust) "echo"}
export IO_ENGINE_DIR="$RUST_TARGET_DEBUG"
'';

# SRCDIR is needed by docker-compose files as it requires absolute paths
export SRCDIR=`pwd`
if [ -z "$CI" ]; then
echo
pre-commit install
pre-commit install --hook commit-msg
fi
export PATH=$PATH:$(pwd)/scripts/nix-sudo
'';
}
shellInfoHook = ''
echo
echo "PROTOC : $PROTOC"
echo "PROTOC_INCLUDE : $PROTOC_INCLUDE"
echo "ETCD_BIN : $ETCD_BIN"
echo "LVM path : $LVM_BINS"
echo "I/O engine dir : $IO_ENGINE_DIR"
'';
};
};
in
pkgs.mkShell shellAttrs // {
name = "io-engine-dev-shell";
}
9 changes: 9 additions & 0 deletions ide.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{ rust ? "none"
, spdk ? "develop"
, spdk-path ? null
} @ args:
import ./ci.nix {
inherit rust;
inherit spdk;
inherit spdk-path;
}
12 changes: 0 additions & 12 deletions nix/lib/rust.nix

This file was deleted.

7 changes: 1 addition & 6 deletions nix/overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,14 @@ let
img_prefix = if product_prefix == "" then config.product_prefix else product_prefix;
in
self: super: rec {
fio = super.callPackage ./pkgs/fio { };
sourcer = super.callPackage ./lib/sourcer.nix { };
images = super.callPackage ./pkgs/images { inherit img_tag img_org img_prefix; };
libnvme = super.callPackage ./pkgs/libnvme { };
libspdk = (super.callPackage ./pkgs/libspdk { with-fio = false; }).release;
libspdk-fio = (super.callPackage ./pkgs/libspdk { with-fio = true; multi-outputs = true; }).release;
libspdk-dev = (super.callPackage ./pkgs/libspdk { with-fio = true; }).debug;
io-engine = (super.callPackage ./pkgs/io-engine { inherit tag sourcer; }).release;
io-engine-adhoc = (super.callPackage ./pkgs/io-engine { inherit tag; }).adhoc;
io-engine-dev = (super.callPackage ./pkgs/io-engine { inherit tag; }).debug;
mkContainerEnv = super.callPackage ./lib/mkContainerEnv.nix { };
ms-buildenv = super.callPackage ./pkgs/ms-buildenv { };
nvme-cli = super.callPackage ./pkgs/nvme-cli { };
nvmet-cli = super.callPackage ./pkgs/nvmet-cli { };
units = (super.callPackage ./pkgs/io-engine/units.nix { inherit tag sourcer; });
}
// (import ../spdk-rs/nix/overlay.nix { } self super)
58 changes: 0 additions & 58 deletions nix/pkgs/fio/default.nix

This file was deleted.

8 changes: 5 additions & 3 deletions nix/pkgs/io-engine/cargo-package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
, lib
, libaio
, libbsd
, libexecinfo
, libnvme
, libspdk
, libspdk-dev
Expand All @@ -30,7 +31,7 @@
}:
let
version = versions.version;
channel = import ../../lib/rust.nix { inherit sources; };
channel = import ../../../spdk-rs/nix/lib/rust.nix { inherit sources; };
rustPlatform = makeRustPlatform {
rustc = channel.stable;
cargo = channel.stable;
Expand Down Expand Up @@ -75,6 +76,7 @@ let
buildInputs = [
libaio
libbsd
libexecinfo
libnvme
libpcap
libunwind
Expand Down Expand Up @@ -102,12 +104,12 @@ in
cargoBuildFlags = "--bin io-engine --bin io-engine-client --bin casperf";
buildType = "release";
buildInputs = buildProps.buildInputs ++ [ libspdk ];
SPDK_PATH = "${libspdk}";
SPDK_ROOT_DIR = "${libspdk}";
});
debug = rustPlatform.buildRustPackage (buildProps // {
cargoBuildFlags = "--workspace --bins --exclude io-engine-bench";
buildType = "debug";
buildInputs = buildProps.buildInputs ++ [ libspdk-dev ];
SPDK_PATH = "${libspdk-dev}";
SPDK_ROOT_DIR = "${libspdk-dev}";
});
}
19 changes: 0 additions & 19 deletions nix/pkgs/libnvme/default.nix

This file was deleted.

Loading

0 comments on commit 6336ae3

Please sign in to comment.