generated from GrayJack/rust-janet-module-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject.janet
83 lines (73 loc) · 2.67 KB
/
project.janet
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
(declare-project
:name "str-ext"
:description "Janet library with functions to extend the available API for string and buffers in the langauge"
:author "GrayJack"
:license "MIT or Apache 2.0"
:url "https://grayjack.github.io/janet-str-ext/"
:repo "git+https://github.com/GrayJack/janet-str-ext.git")
(defn declare-rust
"Declare a native Rust module."
[&keys opts]
(def name (opts :name))
(def rs-name (string/replace-all "-" "_" name))
(def cargo-extra-args (opts :cargo-extra-args))
(def build-type (dyn :build-type "release"))
(def modext (dyn :modext))
(def statext (dyn :statext))
(def build-dir (find-build-dir))
(def os (os/which))
(def path (string (dyn :modpath) "/" (dirname name)))
(def rs-build-target
(match build-type
"release" "target/release/lib"
"debug" "target/debug/lib"
"develop" "target/debug/lib"))
(def os-dyn-extension
(match os
:linux ".so"
:macos ".dylib"
:windows ".dll"
x (errorf "unsupported OS %s" x)))
(def lname (string build-dir name modext))
(def lname2 (string build-dir name os-dyn-extension))
(def sname (string build-dir name statext))
(rule "cargo" []
(def release?
(match build-type
"release" "--release"
"debug" ""
"develop" ""))
(os/execute ["cargo" "build" release? "--target-dir" "target" "--quiet" ;cargo-extra-args] :p))
(rule "mv2build" ["cargo"]
(copyfile (string rs-build-target rs-name statext) sname)
(copyfile (string rs-build-target rs-name os-dyn-extension) lname2)
(copyfile (string rs-build-target rs-name os-dyn-extension) lname))
(add-output "mv2build" sname)
(add-output "mv2build" lname)
(add-output "mv2build" (string build-dir name os-dyn-extension))
(add-dep "build" "mv2build")
(install-rule lname path)
(install-rule sname path)
# Add meta file
(def metaname (modpath-to-meta lname))
(def ename (entry-name name))
(rule metaname []
(print "generating meta file " metaname "...")
(flush)
(os/mkdir (find-build-dir))
(create-dirs metaname)
(spit metaname (string/format
"# Metadata for static library %s\n\n%.20p"
(string name statext)
{:static-entry ename
:cpp false
:ldflags ~',(opts :ldflags)
:lflags ~',(opts :lflags)})))
(add-dep "build" metaname)
(install-rule metaname path)
(rule "clean-target" []
(os/execute ["cargo" "clean" "--target-dir" "target"] :p))
(add-dep "clean" "clean-target"))
(declare-rust
:name "str-ext"
:cargo-extra-args [])