-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.clj
More file actions
99 lines (89 loc) · 4.3 KB
/
Copy pathbuild.clj
File metadata and controls
99 lines (89 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
(ns build
"Build/deploy for clj-fff. The main `com.blockether/fff` jar is small; native
libraries are published as per-platform artifacts such as
`com.blockether/fff-native-linux-x64`."
(:require [clojure.java.io :as io]
[clojure.string :as str]
[clojure.tools.build.api :as b]
[deps-deploy.deps-deploy :as dd]))
(def lib 'com.blockether/fff)
(def native-platforms #{"linux-x64" "linux-arm64" "darwin-arm64" "darwin-x64" "windows-x64"})
(def native-libs {"linux-x64" "libfff_c.so"
"linux-arm64" "libfff_c.so"
"darwin-arm64" "libfff_c.dylib"
"darwin-x64" "libfff_c.dylib"
"windows-x64" "fff_c.dll"})
(def version
(let [v (System/getenv "VERSION")]
(cond
(and v (str/starts-with? v "v")) (subs v 1)
v v
:else (str (str/trim (slurp "resources/VERSION")) "-SNAPSHOT"))))
(def class-dir "target/classes")
(def native-class-dir "target/native-classes")
(def jar-file (format "target/%s.jar" (name lib)))
(def basis (delay (b/create-basis {:project "deps.edn"})))
(defn clean [_] (b/delete {:path "target"}))
(defn- pom-data [description]
[[:description description]
[:url "https://github.com/Blockether/clj-fff"]
[:licenses [:license [:name "MIT License"] [:url "https://opensource.org/licenses/MIT"]]]
[:scm [:url "https://github.com/Blockether/clj-fff"]
[:connection "scm:git:https://github.com/Blockether/clj-fff.git"]
[:developerConnection "scm:git:ssh://git@github.com/Blockether/clj-fff.git"]]])
(defn jar [_]
(clean nil)
(b/write-pom {:class-dir class-dir
:lib lib
:version version
:basis @basis
:src-dirs ["src"]
:pom-data (pom-data "Clojure binding to fff — fast file and content search — via JDK FFM.")})
(b/copy-dir {:src-dirs ["src"] :target-dir class-dir})
;; Ship the GraalVM native-image config (FFM downcalls + prebuilds glob) so a
;; downstream native-image build (e.g. vis) picks it up automatically.
(b/copy-dir {:src-dirs ["resources/META-INF"] :target-dir (str class-dir "/META-INF")})
;; Ship the version under a NAMESPACED resource path (fff/VERSION), not the
;; jar root, so it can't collide with other libs' `VERSION` on a shared
;; classpath (which made a sibling lib resolve a foreign version and 404 the
;; native download).
(let [vfile (io/file class-dir "fff" "VERSION")]
(io/make-parents vfile)
(spit vfile version))
(b/jar {:class-dir class-dir :jar-file jar-file})
(println "Built:" jar-file "version:" version))
(defn- native-lib [platform]
(symbol "com.blockether" (str "fff-native-" platform)))
(defn native-jar [{:keys [platform]}]
(let [platform (some-> platform name)]
(when-not (native-platforms platform)
(throw (ex-info (str "Unknown native platform: " platform) {:platform platform :known native-platforms})))
(let [fname (native-libs platform)
src (format "resources/prebuilds/%s/%s" platform fname)
lib* (native-lib platform)
jar* (format "target/%s.jar" (name lib*))]
(b/delete {:path native-class-dir})
(b/delete {:path jar*})
(when-not (.exists (io/file src))
(throw (ex-info (str "Native library not found: " src) {:platform platform :path src})))
(b/write-pom {:class-dir native-class-dir
:lib lib*
:version version
:basis @basis
:src-dirs []
:pom-data (pom-data (format "Native fff-c library for %s." platform))})
(b/copy-file {:src src :target (format "%s/prebuilds/%s/%s" native-class-dir platform fname)})
(b/jar {:class-dir native-class-dir :jar-file jar*})
(println "Built:" jar* "version:" version)
jar*)))
(defn deploy [_]
(jar nil)
(dd/deploy {:installer :remote :artifact jar-file :pom-file (b/pom-path {:lib lib :class-dir class-dir})}))
(defn deploy-native [{:keys [platform]}]
(let [platform (some-> platform name)
jar* (native-jar {:platform platform})
lib* (native-lib platform)]
(dd/deploy {:installer :remote :artifact jar* :pom-file (b/pom-path {:lib lib* :class-dir native-class-dir})})))
(defn install [_]
(jar nil)
(dd/deploy {:installer :local :artifact jar-file :pom-file (b/pom-path {:lib lib :class-dir class-dir})}))