-
Notifications
You must be signed in to change notification settings - Fork 2
/
workspace.ergo
181 lines (164 loc) · 5.66 KB
/
workspace.ergo
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
## The minimum rust version to support.
rust-version = 1.64.0
std:import { :Array, :Iter, :Path, :String, :env, :exec, :fs, :if, :match, :task } = $std
run-task = fn :name ~:stdin ^:args -> task $name {
child = exec ^(std:merge (fn ~env={PATH = env:vars:PATH}) $args)
if $stdin {
child:stdin $stdin ()
}
child:success
}
rustc-target = {
String:match "{}host: {}\n{}" _ :target _ = String:from <| exec (env = { PATH = env:vars:PATH }) rustc -vV
$target
}
script-dir = std:source:dir ()
release = fn ^:args -> {
{ :args, :extra-options } = match (Array:from $args) [
[^:args, --, ^:extra-options] -> { args, extra-options }
:args -> { args, extra-options = [] }
]
args = std:getopt ~consecutive $args
target = std:Unset:or args:keyed:target $rustc-target
cmd = if args:keyed:cross cross else cargo
env = {
MACOSX_DEPLOYMENT_TARGET = match $target [
aarch64-apple-darwin -> 11.0
x86_64-apple-darwin -> 10.7
_ -> $unset
]
}
run-task "compiling in release mode ($target)" ~env=$env $cmd build --release --target $target ^extra-options
dir = Path:join $script-dir target $target release
oneof = fn :target -> :options -> {
[$target] = Array:from <| Iter:filter fs:exists <| Iter:map (fn :f -> Path:join $dir $f) $options
()
}
oneof :binary = [ergolang, ergolang.exe]
oneof :stdlib = [libergo_std.so, libergo_std.dylib, ergo_std.dll]
{
binary
stdlib
target
}
}
version = exec git describe --always --tags | String:from | String:trim
name = "ergo-$version"
package = fn :files -> {
name = "$(name)-$(files:target)"
installer-entry = '
' #!/bin/sh
'
' set -eu
'
' target=linux
' if [ "$$(uname)" = "Darwin" ]; then
' target=mac
' fi
'
' cmd=$${1:-}
' if [ $$# -ge 1 ]; then
' shift
' fi
'
' usage() {
' echo "Usage: installer COMMAND"
' echo
' echo "Commands:"
' echo " ergo [args...] - run ergo without installing anything"
' echo " install [dir] - install ergo to the given directory, defaulting to $$HOME/.local"
' echo " uninstall [dir] - uninstall ergo from the given directory, defaulting to $$HOME/.local"
' echo " help - display this help text"
' echo
' echo " For a system-wide install, run e.g. 'install /usr'."
' }
'
' install() {
' dir=$$1
' mkdir -p $$dir/bin $$dir/lib
' cp -r ./bin/* $$dir/bin
' cp -r ./lib/* $$dir/lib
' ln -s ergolang $$dir/bin/ergo
' ln -s ergolang $$dir/bin/ergofmt
'
' echo "ergo installed to $$dir/bin; ensure it is in your PATH"
' if [ "$$target" = "mac" ]; then
' xattr -dr com.apple.quarantine $$dir/lib/ergo
' fi
' }
'
' uninstall() {
' dir=$$1
' rm -f $$dir/bin/ergolang $$dir/bin/ergo $$dir/bin/ergofmt
' rm -rf $$dir/lib/ergo
' }
'
' case $$cmd in
' help)
' usage
' ;;
' ergo)
' exec ./bin/ergolang evaluate "$$@"
' ;;
' install)
' dir=$${1:-$$HOME/.local}
' uninstall $$dir
' install $$dir
' ;;
' uninstall)
' dir=$${1:-$$HOME/.local}
' uninstall $$dir
' ;;
' *)
' echo "unrecognized command: $$cmd"
' usage
' exit 1
' ;;
' esac
dist = Path:owned <| Path:for <| fn :dist -> {
# make directories
[
fs:create-dir <| Path:join $dist bin
fs:create-dir <| Path:join $dist lib ergo
]
# create/copy files
[
fs:copy files:binary (Path:join $dist bin ergolang)
{
fs:copy (Path:join $script-dir ergo_std/script) (Path:join $dist lib ergo std)
fs:copy files:stdlib (Path:join $dist lib ergo std plugin.ergo)
}
fs:write (Path:join $dist entry.sh) $installer-entry
]
}
makeself = std:cache <| std:Path:for <| fn :f -> {
std:fs:create-dir $f
std:net:download "https://github.com/megastep/makeself/releases/download/release-2.4.5/makeself-2.4.5.run" (Path:join $f makeself.run)
exec ~pwd=$f (env:path-search sh) makeself.run --target .
}
makeself = Path:join $makeself makeself.sh
run-task "creating $(files:target) installer" ~pwd=$script-dir (env:path-search sh) $makeself $dist "$name.run" "ergo $version" sh ./entry.sh
}
doc-html = task "generating docs" {
user-guide-dir = Path:join $script-dir user_guide
exec ~pwd=$user-guide-dir (env:path-search mdbook) build
book-dir = Path:join $user-guide-dir book
std-doc-dir = Path:join $book-dir std_docs
fs:remove $std-doc-dir
std:Type:any :std-content = id ~eval=std:Bool:false $std
doc:write $std-doc-dir $std-content
fs:copy (Path:join $user-guide-dir quick_reference.html) $book-dir
$book-dir
}
test = { [load ergo_std/test, run-task "running tests" cargo test], () }
## Commands:
## * build - build all crates
## * test - build and run tests
## * package [--target=<target>] [--cross] - create installable package
## * doc - generate documentation
command = match:value [
fn build -> run-task "compiling all projects" cargo build
fn test -> $test
fn package ^:args -> package <| release ^args
fn doc -> $doc-html
]