123 lines
3.8 KiB
Nix
123 lines
3.8 KiB
Nix
{ pkgs, buildTools, buildEnvironment, craneLib, advisory-db, winpcap-libs
|
|
, winpcap-drivers, freebsd-libs, libnl, libpcap-linux-musl, libpcap-linux-gnu
|
|
, libpcap-freebsd }:
|
|
let
|
|
patch-elf = header: drv: path:
|
|
let hdr = toString header;
|
|
in pkgs.stdenv.mkDerivation {
|
|
name = "elf-patch-${hdr}";
|
|
|
|
buildInputs = with pkgs; [ vim ];
|
|
|
|
src = drv;
|
|
|
|
buildPhase = ''
|
|
mkdir -p $out/$(dirname ${path})
|
|
cp ${drv}/${path} $out/${path}
|
|
echo '000007: ${hdr}' xxd -r - $out/${path}
|
|
'';
|
|
};
|
|
patch-freebsd-elf = patch-elf 9;
|
|
|
|
src = craneLib.cleanCargoSource ./.;
|
|
|
|
commonArgs = buildEnvironment // {
|
|
inherit src;
|
|
strictDeps = true;
|
|
|
|
nativeBuildInputs = buildTools;
|
|
buildInputs = buildTools;
|
|
};
|
|
|
|
freebsdArgs = commonArgs // {
|
|
CARGO_BUILD_RUSTFLAGS =
|
|
"-Ctarget-feature=+crt-static -Clink-args=--target=x86_64-unknown-freebsd -Clink-args=--sysroot=${freebsd-libs} -Clink-args=-L${freebsd-libs}/lib -Clink-args=-L${freebsd-libs}/usr/lib -Clink-args=-L${libpcap-freebsd}/lib";
|
|
|
|
doCheck = false;
|
|
};
|
|
|
|
windowsArgs = commonArgs // { doCheck = false; };
|
|
|
|
linuxCargoArtifacts = craneLib.buildDepsOnly (commonArgs // {
|
|
name = "sparse-deps-linux";
|
|
cargoExtraArgs = "--target=x86_64-unknown-linux-musl --locked";
|
|
});
|
|
freebsdCargoArtifacts = craneLib.buildDepsOnly (freebsdArgs // {
|
|
name = "sparse-deps-freebsd";
|
|
cargoExtraArgs = "--target=x86_64-unknown-freebsd --locked";
|
|
});
|
|
windowsCargoArtifacts = craneLib.buildDepsOnly (windowsArgs // {
|
|
name = "sparse-deps-windows";
|
|
cargoExtraArgs = "--target=x86_64-pc-windows-gnu --locked";
|
|
});
|
|
|
|
fileSetForCrate = crate:
|
|
pkgs.lib.fileset.toSource {
|
|
root = ./.;
|
|
fileset = pkgs.lib.fileset.unions [
|
|
./.cargo/config.toml
|
|
./Cargo.toml
|
|
./Cargo.lock
|
|
./build_common.rs
|
|
(craneLib.fileset.commonCargoSources ./pcap-sys)
|
|
(craneLib.fileset.commonCargoSources ./nl-sys)
|
|
(craneLib.fileset.commonCargoSources ./packets)
|
|
(craneLib.fileset.commonCargoSources crate)
|
|
];
|
|
};
|
|
|
|
sparse-beacon-linux = craneLib.buildPackage (commonArgs // {
|
|
cargoArtifacts = linuxCargoArtifacts;
|
|
name = "sparse-beacon-linux";
|
|
cargoExtraArgs = "-p sparse-beacon";
|
|
src = fileSetForCrate ./sparse-beacon;
|
|
|
|
CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl";
|
|
CARGO_BUILD_RUSTFLAGS = "-Ctarget-feature=+crt-static";
|
|
});
|
|
|
|
sparse-beacon-freebsd-sysv = craneLib.buildPackage (freebsdArgs // {
|
|
inherit src;
|
|
cargoArtifacts = freebsdCargoArtifacts;
|
|
name = "sparse-beacon-freebsd";
|
|
cargoExtraArgs = "-p sparse-beacon";
|
|
|
|
nativeBuildInputs = buildTools;
|
|
|
|
CARGO_BUILD_TARGET = "x86_64-unknown-freebsd";
|
|
CARGO_BUILD_RUSTFLAGS = "-Ctarget-feature=+crt-static";
|
|
});
|
|
|
|
sparse-beacon-freebsd =
|
|
patch-freebsd-elf sparse-beacon-freebsd-sysv "bin/sparse-beacon";
|
|
|
|
sparse-beacon-windows = craneLib.buildPackage (windowsArgs // {
|
|
cargoArtifacts = windowsCargoArtifacts;
|
|
name = "sparse-beacon-windows";
|
|
cargoExtraArgs = "-p sparse-beacon";
|
|
src = fileSetForCrate ./sparse-beacon;
|
|
|
|
CARGO_BUILD_TARGET = "x86_64-pc-windows-gnu";
|
|
CARGO_BUILD_RUSTFLAGS = "-Ctarget-feature=+crt-static";
|
|
});
|
|
|
|
outputs = rec {
|
|
packages = {
|
|
inherit sparse-beacon-linux sparse-beacon-windows
|
|
sparse-beacon-freebsd-sysv sparse-beacon-freebsd;
|
|
};
|
|
checks = outputs.packages // {
|
|
rs-fmt = craneLib.cargoFmt { inherit src; };
|
|
rs-audit = craneLib.cargoAudit { inherit src advisory-db; };
|
|
rs-toml-fmt = craneLib.taploFmt {
|
|
src = pkgs.lib.sourceFilesBySuffices src [ ".toml" ];
|
|
};
|
|
rs-deny = craneLib.cargoDeny { inherit src; };
|
|
rs-clippy = craneLib.cargoClippy (commonArgs // {
|
|
cargoArtifacts = linuxCargoArtifacts;
|
|
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
|
|
});
|
|
};
|
|
};
|
|
in outputs
|