Unverified Commit 68f2d23b authored by John Titor's avatar John Titor
Browse files

scx.cscheds: switch to make packaging

Upstream deprecated meson builds.

This also switches libbpf and bpftool dependencies to nixpkgs provided ones.
Please report if this causes any issues.
parent 7a29ec41
Loading
Loading
Loading
Loading
+8 −74
Original line number Diff line number Diff line
{
  lib,
  llvmPackages,
  fetchFromGitHub,
  writeShellScript,
  bash,
  meson,
  ninja,
  jq,
  libbpf,
  pkg-config,
  bpftools,
  elfutils,
  zlib,
  zstd,
  scx-common,
  protobuf,
  libseccomp,
}:

@@ -21,56 +14,17 @@ llvmPackages.stdenv.mkDerivation (finalAttrs: {
  pname = "scx_cscheds";
  inherit (scx-common) version src;

  # scx needs specific commits of bpftool and libbpf
  # can be found in meson.build of scx src
  # grep 'bpftool_commit =' ./meson.build
  bpftools_src = fetchFromGitHub {
    owner = "libbpf";
    repo = "bpftool";
    inherit (scx-common.versionInfo.bpftool) rev hash;
    fetchSubmodules = true;
  };
  # grep 'libbpf_commit = ' ./meson.build
  libbpf_src = fetchFromGitHub {
    owner = "libbpf";
    repo = "libbpf";
    inherit (scx-common.versionInfo.libbpf) rev hash;
    fetchSubmodules = true;
  };

  # this imitates the fetch_bpftool and fetch_libbpf script in src/meson-scripts
  fetchBpftool = writeShellScript "fetch_bpftool" ''
    [ "$2" == '${finalAttrs.bpftools_src.rev}' ] || exit 1
    cd "$1"
    cp --no-preserve=mode,owner -r "${finalAttrs.bpftools_src}/" ./bpftool
  '';
  fetchLibbpf = writeShellScript "fetch_libbpf" ''
    [ "$2" == '${finalAttrs.libbpf_src.rev}' ] || exit 1
    cd "$1"
    cp --no-preserve=mode,owner -r "${finalAttrs.libbpf_src}/" ./libbpf
    mkdir -p ./libbpf/src/usr/include
  '';

  postPatch = ''
    rm meson-scripts/fetch_bpftool meson-scripts/fetch_libbpf
    patchShebangs ./meson-scripts
    cp ${finalAttrs.fetchBpftool} meson-scripts/fetch_bpftool
    cp ${finalAttrs.fetchLibbpf} meson-scripts/fetch_libbpf
    substituteInPlace ./meson-scripts/build_bpftool \
      --replace-fail '/bin/bash' '${lib.getExe bash}'
    substituteInPlace ./scheds/c/Makefile \
      --replace-fail '/usr/local' '${placeholder "out"}'
  '';

  nativeBuildInputs = [
    meson
    ninja
    jq
    pkg-config
    zstd
    protobuf
    llvmPackages.libllvm
  ]
  ++ bpftools.buildInputs
  ++ bpftools.nativeBuildInputs;
    bpftools
    libbpf
  ];

  buildInputs = [
    elfutils
@@ -78,34 +32,14 @@ llvmPackages.stdenv.mkDerivation (finalAttrs: {
    libseccomp
  ];

  mesonFlags = [
    (lib.mapAttrsToList lib.mesonEnable {
      # systemd unit is implemented in the nixos module
      # upstream systemd files are a hassle to patch
      "systemd" = false;
      # not for nix
      "openrc" = false;
    })
    (lib.mapAttrsToList lib.mesonBool {
      # needed libs are already fetched as FOD
      "offline" = true;
      # rust based schedulers are built separately
      "enable_rust" = false;
    })
    # Clang to use when compiling .bpf.c
    (lib.mesonOption "bpf_clang" (lib.getExe llvmPackages.clang))
  makeFlags = [
    "PREFIX=${placeholder "out"}"
  ];

  hardeningDisable = [
    "stackprotector"
    "zerocallusedregs"
  ];

  outputs = [
    "bin"
    "out"
  ];

  doCheck = true;

  meta = scx-common.meta // {
+1 −1
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@
scx.cscheds.overrideAttrs (oldAttrs: {
  pname = "scx_full";
  postInstall = (oldAttrs.postInstall or "") + ''
    cp ${scx.rustscheds}/bin/* ${placeholder "bin"}/bin/
    cp ${lib.getBin scx.rustscheds}/bin/* ${placeholder "out"}/bin/
  '';

  passthru.tests.basic = nixosTests.scx;
+0 −1
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ rustPlatform.buildRustPackage {
  };

  hardeningDisable = [
    "stackprotector"
    "zerocallusedregs"
  ];

+1 −19
Original line number Diff line number Diff line
@@ -18,32 +18,14 @@ fi

latestHash=$(nix-prefetch-git https://github.com/sched-ext/scx.git --rev refs/tags/v$latestVer --quiet | jq -r .hash)

tmp=$(mktemp -d)
trap 'rm -rf -- "${tmp}"' EXIT

git clone --depth 1 --branch "v$latestVer" https://github.com/sched-ext/scx.git "$tmp/scx"

pushd "$tmp/scx"

bpftoolRev=$(grep 'bpftool_commit =' ./meson.build | awk -F"'" '{print $2}')
bpftoolHash=$(nix-prefetch-git https://github.com/libbpf/bpftool.git --rev $bpftoolRev --fetch-submodules --quiet | jq -r .hash)

libbpfRev=$(grep 'libbpf_commit =' ./meson.build | awk -F"'" '{print $2}')
libbpfHash=$(nix-prefetch-git https://github.com/libbpf/libbpf.git --rev $libbpfRev --fetch-submodules --quiet | jq -r .hash)

jq \
  --arg latestVer "$latestVer" --arg latestHash "$latestHash" \
  --arg bpftoolRev "$bpftoolRev" --arg bpftoolHash "$bpftoolHash" \
  --arg libbpfRev "$libbpfRev" --arg libbpfHash "$libbpfHash" \
  ".scx.version = \$latestVer | .scx.hash = \$latestHash |\
  .bpftool.rev = \$bpftoolRev | .bpftool.hash = \$bpftoolHash |\
  .libbpf.rev = \$libbpfRev | .libbpf.hash = \$libbpfHash" \
  ".scx.version = \$latestVer | .scx.hash = \$latestHash" \
  "$versionJson" | sponge $versionJson

echo "scx: $localVer -> $latestVer"

echo "Updating cargoHash. This may take a while..."
popd
cargoHash=$((nix-build --attr scx.rustscheds 2>&1 || true) | awk '/got/{print $2}')

if [ -z "$cargoHash" ]; then
+0 −8
Original line number Diff line number Diff line
@@ -3,13 +3,5 @@
    "version": "1.0.17",
    "hash": "sha256-UhFHT8cSrdjhSqjj4qFzn5UvfPOLPwrBh1ytL2gFhzU=",
    "cargoHash": "sha256-yQM2zx1IzGjegwLK4epsluWl8m5RSP3jB00Lpd8+TLE="
  },
  "bpftool": {
    "rev": "183e7010387d1fc9f08051426e9a9fbd5f8d409e",
    "hash": "sha256-ZZly6csVWOmtLmld1fhSDUqyRgZx2gSMGXTaSASGv7c="
  },
  "libbpf": {
    "rev": "b4fa3e39a77fd65574fb5f899486795fc3d89bd9",
    "hash": "sha256-wlymVgcLlGCUOC92CkYU6QZZnqx8nidSfhr1pTiS8aM="
  }
}