| author | wenzelm |
| Wed, 22 Oct 2025 21:23:01 +0200 | |
| changeset 83341 | b87ea73f8606 |
| parent 83151 | 954fe62909e9 |
| permissions | -rw-r--r-- |
|
77566
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents:
76548
diff
changeset
|
1 |
/* Title: Pure/Admin/component_zstd.scala |
| 76348 | 2 |
Author: Makarius |
3 |
||
4 |
Build Isabelle zstd-jni component from official download. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
|
77566
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents:
76548
diff
changeset
|
10 |
object Component_Zstd {
|
| 76348 | 11 |
/* platforms */ |
12 |
||
| 76457 | 13 |
sealed case class Platform_Info(name: String, template: String, exe: Boolean = false) {
|
| 76348 | 14 |
def install(jar_dir: Path, component_dir: Path, version: String): Unit = {
|
15 |
val source = jar_dir + Path.explode(template.replace("{V}", version))
|
|
16 |
val target = Isabelle_System.make_directory(component_dir + Path.basic(name)) |
|
17 |
Isabelle_System.copy_file(source, target) |
|
|
78298
3b0f8f1010f2
clarified signature, with subtle change of semantics (amending 8b5a2e4b16d4);
wenzelm
parents:
78147
diff
changeset
|
18 |
if (exe) File.set_executable(target + source.base) |
| 76348 | 19 |
} |
20 |
} |
|
21 |
||
22 |
private val platforms = |
|
23 |
List( |
|
| 76457 | 24 |
Platform_Info("arm64-darwin", "darwin/aarch64/libzstd-jni-{V}.dylib"),
|
25 |
Platform_Info("x86_64-darwin", "darwin/x86_64/libzstd-jni-{V}.dylib"),
|
|
26 |
Platform_Info("arm64-linux", "linux/aarch64/libzstd-jni-{V}.so"),
|
|
27 |
Platform_Info("x86_64-linux", "linux/amd64/libzstd-jni-{V}.so"),
|
|
28 |
Platform_Info("x86_64-windows", "win/amd64/libzstd-jni-{V}.dll", exe = true))
|
|
| 76348 | 29 |
|
30 |
||
31 |
/* build zstd */ |
|
32 |
||
33 |
val license_url = "https://raw.githubusercontent.com/luben/zstd-jni/master/LICENSE" |
|
34 |
val default_download_url = "https://repo1.maven.org/maven2/com/github/luben/zstd-jni" |
|
| 83341 | 35 |
val default_version = "1.5.7-6" |
| 76348 | 36 |
|
37 |
def build_zstd( |
|
38 |
target_dir: Path = Path.current, |
|
39 |
download_url: String = default_download_url, |
|
40 |
version: String = default_version, |
|
41 |
progress: Progress = new Progress, |
|
42 |
): Unit = {
|
|
43 |
/* component */ |
|
44 |
||
45 |
val component_name = "zstd-jni-" + version |
|
| 76518 | 46 |
val component_dir = |
| 76547 | 47 |
Components.Directory(target_dir + Path.basic(component_name)).create(progress = progress) |
| 76348 | 48 |
|
| 76518 | 49 |
File.write(component_dir.README, |
| 76348 | 50 |
"This is " + component_name + " from\n" + download_url + |
51 |
"\n\n Makarius\n " + Date.Format.date(Date.now()) + "\n") |
|
52 |
||
| 76518 | 53 |
Isabelle_System.download_file(license_url, component_dir.LICENSE, progress = progress) |
| 76348 | 54 |
|
55 |
||
56 |
/* jar */ |
|
57 |
||
| 83151 | 58 |
Isabelle_System.make_directory(component_dir.lib) |
59 |
||
| 76348 | 60 |
val jar_name = component_name + ".jar" |
| 83151 | 61 |
val jar = component_dir.lib + Path.basic(jar_name) |
| 76348 | 62 |
Isabelle_System.download_file( |
63 |
download_url + "/" + version + "/" + jar_name, jar, progress = progress) |
|
64 |
||
65 |
Isabelle_System.with_tmp_dir("build") { jar_dir =>
|
|
|
76543
fef0195f8d8e
clarified signature: prefer Scala functions instead of shell scripts;
wenzelm
parents:
76518
diff
changeset
|
66 |
Isabelle_System.extract(jar, jar_dir) |
| 76518 | 67 |
for (platform <- platforms) platform.install(jar_dir, component_dir.path, version) |
| 76348 | 68 |
} |
69 |
||
70 |
||
71 |
/* settings */ |
|
72 |
||
| 76548 | 73 |
component_dir.write_settings("""
|
| 76348 | 74 |
ISABELLE_ZSTD_HOME="$COMPONENT" |
75 |
||
| 83151 | 76 |
classpath "$ISABELLE_ZSTD_HOME/lib/""" + jar_name + """" |
| 76348 | 77 |
""") |
78 |
} |
|
79 |
||
80 |
||
81 |
/* Isabelle tool wrapper */ |
|
82 |
||
83 |
val isabelle_tool = |
|
|
77566
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents:
76548
diff
changeset
|
84 |
Isabelle_Tool("component_zstd", "build Isabelle zstd-jni component from official download",
|
| 76348 | 85 |
Scala_Project.here, |
86 |
{ args =>
|
|
87 |
var target_dir = Path.current |
|
88 |
var download_url = default_download_url |
|
89 |
var version = default_version |
|
90 |
||
91 |
val getopts = Getopts("""
|
|
|
77566
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents:
76548
diff
changeset
|
92 |
Usage: isabelle component_zstd [OPTIONS] |
| 76348 | 93 |
|
94 |
Options are: |
|
95 |
-D DIR target directory (default ".") |
|
96 |
-U URL download URL (default: """ + quote(default_download_url) + """) |
|
97 |
-V VERSION version (default: """ + quote(default_version) + """) |
|
98 |
||
99 |
Build zstd-jni component from the specified download base URL and VERSION, |
|
100 |
see also https://github.com/luben/zstd-jni |
|
101 |
""", |
|
102 |
"D:" -> (arg => target_dir = Path.explode(arg)), |
|
103 |
"U:" -> (arg => download_url = arg), |
|
104 |
"V:" -> (arg => version = arg)) |
|
105 |
||
106 |
val more_args = getopts(args) |
|
107 |
if (more_args.nonEmpty) getopts.usage() |
|
108 |
||
109 |
val progress = new Console_Progress() |
|
110 |
||
111 |
build_zstd(target_dir = target_dir, download_url = download_url, |
|
112 |
version = version, progress = progress) |
|
113 |
}) |
|
114 |
} |