Skip to content

Commit

Permalink
fix(arm): improve ARM build process and compatibility
Browse files Browse the repository at this point in the history
spdk-rs used to not build on arm solely due to the
nix environment setup. There were issues with compiler
flags (-msse4 is x86 only) and some base environment
configuration. By fixing the environment we were able
to get a successful build of spdk-rs.

On top of these fixes we are able to test them in the
github action runner which runs nix-shell. This in turn
compiles spdk from source (openebs/spdk).

Signed-off-by: Max Newcomer <[email protected]>
  • Loading branch information
maxwnewcomer committed Dec 31, 2024
1 parent 93d0d20 commit 57c4a43
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/pr-code-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ on:
types: ['opened', 'edited', 'reopened', 'synchronize']
jobs:
rust-lint:
runs-on: ubuntu-latest
strategy:
matrix:
os: [github-arm64-2c-8gb, ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
Expand Down
16 changes: 6 additions & 10 deletions nix/pkgs/libspdk/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
, libtool
, liburing
, libuuid
, llvmPackages
, meson
, nasm
, ncurses
Expand Down Expand Up @@ -69,6 +68,8 @@ let
else
"--without-fio";

# Only set crossPrefix if we're actually cross-compiling
# (which we aren't, but let's keep the logic).
crossPrefix =
if targetPlatform.config != buildPlatform.config then
"--crossPrefix=${targetPlatform.config}"
Expand All @@ -90,13 +91,13 @@ let
version = "24.05-${lib.substring 0 7 rev}";
name = "${pname}-${version}";
};

drvAttrs = rec {
pname = spdk.pname;
version = spdk.version;

src = [
(fetchFromGitHub {
# Note that this would only rebuild if the first 7 chars differ, but in practice should be fine
name = spdk.name;
owner = "openebs";
repo = "spdk";
Expand All @@ -113,16 +114,13 @@ let
cmake
gcc
help2man
llvmPackages.bintools
llvmPackages.clang
llvmPackages.libclang
meson
ninja
pkg-config
procps
udev
utillinux
(python3.withPackages (ps: with ps; [ pyelftools ]))
pkgs.python3Packages.pyelftools
] ++ extraBuildInputs;

buildInputs = [
Expand Down Expand Up @@ -158,9 +156,7 @@ let
enableParallelBuilding = true;
hardeningDisable = [ "all" ];

#
# Phases.
#
# Our phases
prePatch = ''
pushd ..
chmod -R u+w build_scripts
Expand All @@ -181,4 +177,4 @@ let
'';
};
in
llvmPackages.stdenv.mkDerivation drvAttrs
pkgs.stdenv.mkDerivation drvAttrs
13 changes: 11 additions & 2 deletions nix/shell/spdk.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ let
echo "FIO path : $FIO"
'';

# Determine the system architecture
system = builtins.currentSystem;

# Define CFLAGS based on the architecture
cflagsValue =
if system == "aarch64-linux"
then "-march=armv8-a+crypto"
else "-msse4";

# spdk-path argument overrides spdk argument.
spdkCfg = if spdk-path != null then "none" else spdk;

Expand Down Expand Up @@ -63,14 +72,14 @@ let
};

# Do not use Nix libspdk. User must provide SPDK.
# Build environment for development libspdk packahe is provided.
# Build environment for development libspdk package is provided.
none = {
drv = null;

buildInputs = with pkgs; libspdk-dev.nativeBuildInputs ++ libspdk-dev.buildInputs;

shellEnv = {
CFLAGS = "-msse4";
CFLAGS = cflagsValue;
SPDK_RS_BUILD_USE_LOGS = "yes"; # Tells spdk-rs build.rs script to rerun when build_logs dir is updated.
};

Expand Down

0 comments on commit 57c4a43

Please sign in to comment.