From 57c4a4350a02bbc99a8ed6474e47c403c41131b2 Mon Sep 17 00:00:00 2001 From: Max Newcomer Date: Wed, 18 Dec 2024 11:33:06 -0600 Subject: [PATCH] fix(arm): improve ARM build process and compatibility 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 --- .github/workflows/pr-code-lint.yaml | 5 ++++- nix/pkgs/libspdk/default.nix | 16 ++++++---------- nix/shell/spdk.nix | 13 +++++++++++-- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/.github/workflows/pr-code-lint.yaml b/.github/workflows/pr-code-lint.yaml index 3993fea..86ee94c 100644 --- a/.github/workflows/pr-code-lint.yaml +++ b/.github/workflows/pr-code-lint.yaml @@ -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: diff --git a/nix/pkgs/libspdk/default.nix b/nix/pkgs/libspdk/default.nix index 2206fa8..9ec2324 100644 --- a/nix/pkgs/libspdk/default.nix +++ b/nix/pkgs/libspdk/default.nix @@ -31,7 +31,6 @@ , libtool , liburing , libuuid -, llvmPackages , meson , nasm , ncurses @@ -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}" @@ -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"; @@ -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 = [ @@ -158,9 +156,7 @@ let enableParallelBuilding = true; hardeningDisable = [ "all" ]; - # - # Phases. - # + # Our phases prePatch = '' pushd .. chmod -R u+w build_scripts @@ -181,4 +177,4 @@ let ''; }; in -llvmPackages.stdenv.mkDerivation drvAttrs +pkgs.stdenv.mkDerivation drvAttrs diff --git a/nix/shell/spdk.nix b/nix/shell/spdk.nix index 089de22..daa4ac4 100644 --- a/nix/shell/spdk.nix +++ b/nix/shell/spdk.nix @@ -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; @@ -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. };