1{
2 lib,
3 rustPlatform,
4 llvmPackages,
5 pkg-config,
6 elfutils,
7 zlib,
8 zstd,
9 scx-common,
10 scx,
11 protobuf,
12 libseccomp,
13}:
14rustPlatform.buildRustPackage {
15 pname = "scx_rustscheds";
16 inherit (scx-common) version src;
17
18 inherit (scx-common.versionInfo.scx) cargoHash;
19
20 # Copy compiled headers and libs from scx.cscheds
21 postPatch = ''
22 mkdir libbpf
23 cp -r ${scx.cscheds.dev}/libbpf/* libbpf/
24 '';
25
26 nativeBuildInputs = [
27 pkg-config
28 rustPlatform.bindgenHook
29 protobuf
30 ];
31 buildInputs = [
32 elfutils
33 zlib
34 zstd
35 libseccomp
36 ];
37
38 env = {
39 BPF_CLANG = lib.getExe llvmPackages.clang;
40 BPF_EXTRA_CFLAGS_PRE_INCL = lib.concatStringsSep " " [
41 "-I${scx.cscheds.dev}/libbpf/src/usr/include"
42 "-I${scx.cscheds.dev}/libbpf/include/uapi"
43 "-I${scx.cscheds.dev}/libbpf/include/linux"
44 ];
45 RUSTFLAGS = lib.concatStringsSep " " [
46 "-C relocation-model=pic"
47 "-C link-args=-lelf"
48 "-C link-args=-lz"
49 "-C link-args=-lzstd"
50 "-L ${scx.cscheds.dev}/libbpf/src"
51 ];
52 };
53
54 hardeningDisable = [
55 "stackprotector"
56 "zerocallusedregs"
57 ];
58
59 doCheck = true;
60 checkFlags = [
61 "--skip=compat::tests::test_ksym_exists"
62 "--skip=compat::tests::test_read_enum"
63 "--skip=compat::tests::test_struct_has_field"
64 "--skip=cpumask"
65 "--skip=topology"
66 ];
67
68 meta = scx-common.meta // {
69 description = "Sched-ext Rust userspace schedulers";
70 longDescription = ''
71 This includes Rust based schedulers such as
72 scx_rustland, scx_bpfland, scx_lavd, scx_layered, scx_rlfifo.
73
74 ::: {.note}
75 Sched-ext schedulers are only available on kernels version 6.12 or later.
76 It is recommended to use the latest kernel for the best compatibility.
77 :::
78 '';
79 };
80}