-
Notifications
You must be signed in to change notification settings - Fork 3
/
build_atria.jl
executable file
·188 lines (151 loc) · 4.94 KB
/
build_atria.jl
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
182
183
184
185
186
187
188
#!julia --color=yes
using Pkg
using UUIDs
if !isempty(intersect(ARGS, ["-h", "--help", "--h"]))
println("Usage: $(@__FILE__) [path-to-install]")
exit(1)
end
function check_compatibility()
if Sys.iswindows()
# without pre-compilation
error("Atria does not support Windows Platform.")
exit()
end
if !(v"1.8" <= VERSION < v"1.10")
@warn "Julia version is not v1.8 or 1.9. The build might be fail." JULIA_VERSION = VERSION
end
if !(v"1.8" <= VERSION < v"1.9")
@warn "It is recommended to build Atria using Julia v1.8 because it is 3-20% faster than v1.9." JULIA_VERSION = VERSION
end
try
run(pipeline(`pigz --version`, stderr=devnull))
catch
error("Dependency missing: pigz not found.")
exit()
end
try
run(pipeline(`pbzip2 --version`, stderr=devnull))
catch
error("Dependency missing: pbzip2 not found.")
exit()
end
# Pkg.add("PackageCompiler")
end
function check_biosequences_for_atria()
biosequences_info = Pkg.dependencies()[UUID("7e6ae17a-c86d-528c-b3b9-7f778a29fe59")]
if !occursin("cihga39871/BioSequences.jl", biosequences_info.git_source)
# Found package BioSequences from $(biosequences_info.git_source). Atria needs a specific version of BioSequences.
Pkg.add(url="https://github.com/cihga39871/BioSequences.jl")
end
end
check_compatibility()
cd(@__DIR__)
Pkg.activate(".")
Pkg.add(url="https://github.com/cihga39871/BioSequences.jl")
Pkg.update()
check_biosequences_for_atria()
Pkg.resolve()
Pkg.instantiate()
Pkg.precompile()
import Pkg; Pkg.add("PackageCompiler")
using PackageCompiler
using Dates
ver = "atria"
if isfile("Project.toml")
for i in readlines("Project.toml")
if occursin(r"^version", i)
ind = findall("\"", i)
global ver = i[ind[1].start + 1 : ind[2].start - 1]
break
end
end
end
if length(ARGS) == 1
app_path = joinpath(ARGS[1], "atria-$ver")
else
app_path = joinpath(".", "atria-$ver")
end
if isdir(app_path)
app_path *= "_" * replace(string(now()), r":\d\d\..*" => "", ":" => "-")
end
bash_wrapper = raw"""
#!/usr/bin/env bash
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
ALLARGS=( "$@" )
# default
JULIA_NUM_THREADS=8
while [[ $# -gt 0 ]]
do
case "$1" in
--threads)
JULIA_NUM_THREADS="$2"
shift
shift
;;
-t)
JULIA_NUM_THREADS="$2"
shift
shift
;;
*)
shift
;;
esac
done
# "$DIR/AtriaEntry" "${ALLARGS[@]}"
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) EXT=so;;
Darwin*) EXT=dylib;;
*) EXT=so;;
esac
ATRIA="$DIR/_atria"
"$ATRIA" "${ALLARGS[@]}" --julia-args --check-bounds=no --math-mode=fast -t "$JULIA_NUM_THREADS"
"""
precompile_execution_file = joinpath("test", "runtests.jl")
create_app(".", app_path, incremental = true, force = true, filter_stdlibs = false, sysimage_build_args = `-O3 --check-bounds=no --math-mode=fast`, precompile_execution_file = precompile_execution_file, executables = ["_atria" => "julia_main"])
# ext = Sys.isapple() ? "dylib" : "so"
# isfile(joinpath(app_path, "bin", "AtriaEntry.$ext"))
# copy julia exe
# julia_exe = joinpath(Sys.BINDIR, Base.julia_exename())
# cp(julia_exe, joinpath(app_path, "bin", Base.julia_exename()))
Atria_bash = joinpath(app_path, "bin", "atria")
io = open(Atria_bash, "w+")
write(io, bash_wrapper)
close(io)
chmod(Atria_bash, 0o755)
# check if atria is successfully installed
# eg: fix libs that is not copyed to lib path
this_bin_dir = unsafe_string(Base.JLOptions().julia_bindir)
this_lib_dir = abspath(this_bin_dir, "..", "lib", "julia")
dest_lib_dir = abspath(app_path, "lib", "julia")
function copy_missing_lib()
if !isdir(this_lib_dir)
return nothing # skip checking
end
buffer = IOBuffer()
run(pipeline(`$Atria_bash --version`, stderr=buffer, stdout=buffer))
res = String(take!(buffer))
if occursin("Error during initialization of module", res)
m = match(r"([^ \n]*\.(so|dylib|dll)([\.0-9]*)?): cannot open shared object file", res)
if isnothing(m)
return nothing
end
lib = joinpath(this_lib_dir, m.captures[1])
dest_lib = joinpath(dest_lib_dir, m.captures[1])
if isfile(lib) && !isfile(dest_lib)
@info "Copying $(m.captures[1])"
cp(lib, dest_lib, follow_symlinks=true)
copy_missing_lib()
end
end
end
copy_missing_lib()
@info "Success. Atria is installed at $app_path/bin/atria"
check_compatibility()