diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..cffc922 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake . --impure diff --git a/.gitignore b/.gitignore index 56c0441..5f0d161 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ target examples/bind-shell/key-generator/pubkey examples/bind-shell/key-generator/privkey core -**/core \ No newline at end of file +**/core +.direnv diff --git a/Cargo.toml b/Cargo.toml index 58e4e92..5cf4480 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,8 @@ members = [ "tcp-test/client" ] resolver = "2" +package.name = "sparse" +package.version = "0.6.0" [profile.release] strip = true diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a8c5c72 --- /dev/null +++ b/flake.lock @@ -0,0 +1,171 @@ +{ + "nodes": { + "crane": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1705974079, + "narHash": "sha256-HyC3C2esW57j6bG0MKwX4kQi25ltslRnr6z2uvpadJo=", + "owner": "ipetkov", + "repo": "crane", + "rev": "0b4e511fe6e346381e31d355e03de52aa43e8cb2", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1681202837, + "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "cfacdce06f30d2b68473a46042957675eebb3401", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "libnl": { + "flake": false, + "locked": { + "lastModified": 1704704641, + "narHash": "sha256-5U9Pfd738Hyjtew9ZeDGKGbpRspym47T8egje1ZVUO4=", + "ref": "refs/heads/main", + "rev": "8693347fe9c47d08ce5899602ab4f208c1249619", + "revCount": 2024, + "type": "git", + "url": "https://github.com/thom311/libnl" + }, + "original": { + "type": "git", + "url": "https://github.com/thom311/libnl" + } + }, + "libpcap-src": { + "flake": false, + "locked": { + "lastModified": 1705891920, + "narHash": "sha256-4FehaAo6eWDqDVij/uY+BmVGhNMS7AfFZRyw2jk4inI=", + "ref": "refs/heads/master", + "rev": "fb92b4dd10ed1f73a536e512fd0b0e33b76329a6", + "revCount": 5944, + "type": "git", + "url": "https://github.com/the-tcpdump-group/libpcap" + }, + "original": { + "type": "git", + "url": "https://github.com/the-tcpdump-group/libpcap" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1705916986, + "narHash": "sha256-iBpfltu6QvN4xMpen6jGGEb6jOqmmVQKUrXdOJ32u8w=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "d7f206b723e42edb09d9d753020a84b3061a79d8", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "flake-utils": "flake-utils", + "libnl": "libnl", + "libpcap-src": "libpcap-src", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1705976279, + "narHash": "sha256-Zx97bJ3+O8IP70uJPD//rRsr8bcxICISMTZUT/L9eFk=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "f889dc31ef97835834bdc3662394ebdb3c96b974", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix index 271ffde..6efb704 100644 --- a/flake.nix +++ b/flake.nix @@ -3,8 +3,8 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11"; - fenix = { - url = "github:nix-community/fenix"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; inputs.nixpkgs.follows = "nixpkgs"; }; crane = { @@ -12,62 +12,106 @@ inputs.nixpkgs.follows = "nixpkgs"; }; flake-utils.url = "github:numtide/flake-utils"; + + libpcap-src = { + url = "git+https://github.com/the-tcpdump-group/libpcap"; + flake = false; + }; + libnl = { + url = "git+https://github.com/thom311/libnl"; + flake = false; + }; }; - outputs = { self, nixpkgs, flake-utils, crane, fenix }: + outputs = + { self, nixpkgs, flake-utils, crane, rust-overlay, libpcap-src, libnl }: flake-utils.lib.eachDefaultSystem (system: let - pkgs = nixpkgs.legacyPackages.${system}; + pkgs = import nixpkgs { + inherit system; + overlays = [ (import rust-overlay) ]; + }; - toolchain = with fenix.packages.${system}; - combine [ - stable.rustc - stable.cargo - targets.x86_64-pc-windows-gnu.stable.rust-std - targets.x86_64-unknown-linux-musl.stable.rust-std - stable.rust-analyzer - ]; + buildTools = with pkgs; [ + autoconf + automake + bison + cmake + flex + libtool + libpcap + musl + pkg-config + ]; + + toolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile + ./rust-toolchain.toml; craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; - src = craneLib.cleanCargoSource (craneLib.path ./.); + src = craneLib.path ./.; commonArgs = { inherit src; - strictDeps = true; + #strictDeps = true; + #CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static"; CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl"; + + SPARSE_BUILD_LIBPCAP = "${libpcap-src}"; + #SPARSE_BUILD_LIBNL = "${libnl}"; + }; + + commonWindowsArgs = commonArgs // { + CARGO_BUILD_TARGET = "x86_64-pc-windows-gnu"; }; artifacts = craneLib.buildDepsOnly commonArgs; + windowsArtifacts = craneLib.buildDepsOnly commonWindowsArgs; + + sparse-c2-linux-beacon = craneLib.buildPackage (commonArgs // { + inherit artifacts; + + pname = "sparse-c2-beacon"; + cargoExtraArgs = "-p sparse-c2-beacon --locked"; + doCheck = false; + + nativeBuildInputs = buildTools; + buildInputs = buildTools; + }); crate = craneLib.buildPackage (commonArgs // { inherit artifacts; - buildInputs = with pkgs; [ cmake make ]; + buildInputs = buildTools; }); in with pkgs; { devShells.default = craneLib.devShell rec { name = "sparse"; - buildInputs = [ cmake make ]; + buildInputs = buildTools; + + SPARSE_BUILD_LIBPCAP = "${libpcap-src}"; + #SPARSE_BUILD_LIBNL = "${libnl}"; }; - packages = { - default = crate; + packages = rec { + inherit sparse-c2-linux-beacon; + + default = sparse-c2-linux-beacon; windows = craneLib.buildPackage (commonArgs // { doCheck = false; CARGO_BUILD_TARGET = "x86_64-pc-windows-gnu"; - depsBuildBUild = [ + depsBuildBuild = [ pkgsCross.mingwW64.stdenv.cc pkgsCross.mingwW64.windows.pthreads ]; - }); - checks = { inherit crate; }; + artifacts = windowsArtifacts; + }); }; }); } diff --git a/pcap-sys/build.rs b/pcap-sys/build.rs index 727da70..649ed65 100644 --- a/pcap-sys/build.rs +++ b/pcap-sys/build.rs @@ -14,7 +14,7 @@ // along with this program. If not, see . fn main() { - let dst = cmake::Config::new("libpcap") + let dst = cmake::Config::new(std::env!("SPARSE_BUILD_LIBPCAP")) .define("BUILD_SHARED_LIBS", "OFF") .define("BUILD_WITH_LIBNL", "OFF") .define("DISABLE_BLUETOOTH", "ON") diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..f148683 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,5 @@ +[toolchain] +channel = "stable" +components = [ "rustfmt", "rust-std", "rustc-dev" ] +targets = [ "x86_64-pc-windows-gnu", "x86_64-unknown-linux-musl" ] +profile = "minimal"