-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.jl
104 lines (81 loc) · 4.59 KB
/
build.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
using Pkg.Artifacts
using Pkg.BinaryPlatforms
using JSON
import URIParser
import NodeJS
package_dict = JSON.parsefile(joinpath(@__DIR__, "package.json"))
pkgname = package_dict["name"]
version = VersionNumber(package_dict["version"])
vega_version = VersionNumber(package_dict["dependencies"]["vega"])
vegalite_version = VersionNumber(package_dict["dependencies"]["vega-lite"])
vegaembed_version = VersionNumber(package_dict["dependencies"]["vega-embed"])
build_path = joinpath(@__DIR__, "build")
if ispath(build_path)
rm(build_path, force=true, recursive=true)
end
mkpath(build_path)
artifact_toml = joinpath(build_path, "Artifacts.toml")
platforms = [
# glibc Linuces
Linux(:i686),
Linux(:x86_64),
Linux(:aarch64),
Linux(:armv7l),
Linux(:powerpc64le),
# musl Linuces
Linux(:i686, libc=:musl),
Linux(:x86_64, libc=:musl),
Linux(:aarch64, libc=:musl),
Linux(:armv7l, libc=:musl),
# BSDs
MacOS(:x86_64),
MacOS(:aarch64),
FreeBSD(:x86_64),
# Windows
Windows(:i686),
Windows(:x86_64),
]
nodejs_cmd = NodeJS.nodejs_cmd()
npm_cmd = NodeJS.npm_cmd()
for platform in platforms
@info "Now doing" platform
l_libc = platform isa Linux ? "glibc" : "unknown"
product_hash = create_artifact() do artifact_dir
cp(joinpath(@__DIR__, "package.json"), joinpath(artifact_dir, "package.json"))
cp(joinpath(@__DIR__, "package-lock.json"), joinpath(artifact_dir, "package-lock.json"))
cp(joinpath(@__DIR__, "vg2svg.js"), joinpath(artifact_dir, "vg2svg.js"))
cp(joinpath(@__DIR__, "vl2vg.js"), joinpath(artifact_dir, "vl2vg.js"))
bin_links_flat = platform isa Windows ? "--no-bin-links" : ""
if platform isa MacOS || (arch(platform)==:x86_64 && (platform isa Windows || (platform isa Linux && libc(platform)==:glibc)))
l_arch = platform isa MacOS ? "x64" : arch(platform)==:x86_64 ? "x64" : arch(platform)==:i686 ? "ia32" : arch(platform)==:armv7l ? "arm" : error("Unknown arch.")
l_target = platform isa MacOS ? "darwin" : platform isa Windows ? "win32" : platform isa Linux ? "linux" : platform isa FreeBSD ? "freebsd" : error("Unknown target.")
canvas_path = abspath(joinpath(artifact_dir, "node_modules", "canvas"))
run(Cmd(`$npm_cmd install --scripts-prepend-node-path=true --ignore-scripts --omit=dev --omit=optional --no-package-lock $bin_links_flat`, dir=artifact_dir))
run(Cmd(`$nodejs_cmd $(joinpath(artifact_dir, "node_modules", "@mapbox", "node-pre-gyp", "bin", "node-pre-gyp")) install -C $canvas_path --target_arch=$l_arch --target_platform=$l_target --target_libc=$l_libc`, dir=artifact_dir))
else
run(Cmd(`$npm_cmd uninstall vega-cli --scripts-prepend-node-path=true --save`, dir=artifact_dir))
run(Cmd(`$npm_cmd uninstall canvas --scripts-prepend-node-path=true --save`, dir=artifact_dir))
run(Cmd(`$npm_cmd install --scripts-prepend-node-path=true --ignore-scripts --omit=dev --no-package-lock --omit=optional $bin_links_flat`, dir=artifact_dir))
end
run(Cmd(`$npm_cmd prune --production --scripts-prepend-node-path=true`, dir=artifact_dir))
mkpath(joinpath(artifact_dir, "minified"))
mkpath(joinpath(artifact_dir, "schemas"))
download("https://vega.github.io/schema/vega/v$vega_version.json", joinpath(artifact_dir, "schemas", "vega-schema.json"))
download("https://vega.github.io/schema/vega-lite/v$vegalite_version.json", joinpath(artifact_dir, "schemas", "vega-lite-schema.json"))
download("https://cdn.jsdelivr.net/npm/vega@$vega_version", joinpath(artifact_dir, "minified", "vega.min.js"))
download("https://cdn.jsdelivr.net/npm/vega-lite@$vegalite_version", joinpath(artifact_dir, "minified", "vega-lite.min.js"))
download("https://cdn.jsdelivr.net/npm/vega-embed@$vegaembed_version", joinpath(artifact_dir, "minified", "vega-embed.min.js"))
if platform isa Windows
for (root, dirs, files) in walkdir(artifact_dir)
cd(root) do
for file in files
run(`chmod +x "$file"`)
end
end
end
end
end
archive_filename = "$pkgname-$version-$(triplet(platform)).tar.gz"
download_hash = archive_artifact(product_hash, joinpath(build_path, archive_filename))
bind_artifact!(artifact_toml, "vegalite_app", product_hash, platform=platform, force=true, download_info=Tuple[("https://github.com/queryverse/VegaLiteBuilder/releases/download/v$(URIParser.escape(string(version)))/$archive_filename", download_hash)])
end