(def hpkgs
  "https://raw.githubusercontent.com/andrewchambers/hpkgs/93a809b9a17c2275a25c9bc085dc7eb14de9cf7e/")

(defn hpkg-use*
  [p]
  (import* (string hpkgs p) :prefix ""))

(defn hpkg-import*
  [p]
  (import* (string hpkgs p)))

(hpkg-use* "prelude")
(hpkg-use* "community/libsodium")
(hpkg-use* "community/rust")
(hpkg-import* "core")

(defsrc bupstash-src
  :url
  "https://github.com/andrewchambers/bupstash/releases/download/v0.2.0/bupstash-v0.2.0-src+deps.tar.gz"
  :hash
  "sha256:927c667db941af8a5ae9d9961c60f30a57e7e6600cce426a07f23531aa7676f8")

(defpkg bupstash
  :builder
  (fn []
    (os/setenv "PATH" (join-pkg-paths ":" "/bin" [core/build-env rust]))
    (os/setenv "PKG_CONFIG_PATH" (join-pkg-paths ":" "/lib/pkgconfig" [libsodium]))
    (unpack-src bupstash-src)
    (sh/$ cargo build --offline --release)
    (sh/$ strip target/release/bupstash)
    (sh/$ mkdir (dyn :pkg-out) ^ /bin)
    (sh/$ cp target/release/bupstash (dyn :pkg-out) ^ /bin)))
