diff --git a/CMakeLists.txt b/CMakeLists.txt index 7fde4de..af3db3e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,7 @@ project(pinedio-usb C) set(CMAKE_C_STANDARD 11) add_library(pinedio-usb STATIC libpinedio-usb.c) +set_target_properties(pinedio-usb PROPERTIES PUBLIC_HEADER libpinedio-usb.h) find_package(PkgConfig REQUIRED) pkg_check_modules(LIBUSB REQUIRED libusb-1.0) target_link_libraries(pinedio-usb ${LIBUSB_LIBRARIES}) @@ -12,3 +13,5 @@ target_include_directories(pinedio-usb PRIVATE ${LIBUSB_INCLUDE_DIRS}) add_executable(pinedio-test test.c) target_link_libraries(pinedio-test PRIVATE pinedio-usb) + +install(TARGETS pinedio-usb) diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..3fe9ba1 --- /dev/null +++ b/flake.lock @@ -0,0 +1,60 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1736200483, + "narHash": "sha256-JO+lFN2HsCwSLMUWXHeOad6QUxOuwe9UOAF/iSl1J4I=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "3f0a8ac25fb674611b98089ca3a5dd6480175751", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-24.11", + "type": "indirect" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "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 new file mode 100644 index 0000000..f69c808 --- /dev/null +++ b/flake.nix @@ -0,0 +1,64 @@ +{ + description = "A userspace driver for the Pinedio usb LoRa radio."; + + inputs.nixpkgs.url = "nixpkgs/nixos-24.11"; + + inputs.flake-utils.url = "github:numtide/flake-utils"; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101"; + version = builtins.substring 0 8 lastModifiedDate; + pkgs = import nixpkgs {inherit system;}; + mkBuild = attrs: pkgs.stdenv.mkDerivation (attrs // { + inherit version; + src = ./.; + nativeBuildInputs = [ pkgs.cmake pkgs.ninja pkgs.pkg-config ]; + buildInputs = [ pkgs.libusb1 ]; + }); + in + { + + packages = rec { + libpinedio-usb = mkBuild { + pname = "libpinedio-usb"; + }; + pinedio-test = mkBuild { + pname = "pinedio-test"; + installPhase = '' + mkdir -p $out/bin + cp pinedio-test $out/bin + ''; + }; + default = libpinedio-usb; + }; + + devShells.default = pkgs.mkShell { + inputsFrom = [ + self.packages.${system}.pinedio-test + ]; + packages = [ pkgs.git pkgs.nixd pkgs.valgrind ]; + }; + + # Run test suite when checking the flake + checks = + rec { + inherit (self.packages.${system}) pinedio-test; + + test = pkgs.stdenv.mkDerivation + { + pname = "pinedio-test"; + inherit version; + + buildInputs = [ pinedio-test ]; + dontUnpack = true; + + buildPhase = '' + echo Running pinedio-test + echo TODO: pinedio-test currently segfaults so skip this for now''; + installPhase = ''mkdir -p $out''; + }; + }; + }); +}