| author | wenzelm | 
| Sun, 24 Mar 2024 19:14:56 +0100 | |
| changeset 79980 | ee04ce2ac13f | 
| parent 78298 | 3b0f8f1010f2 | 
| child 81606 | 5995afcacbc3 | 
| permissions | -rw-r--r-- | 
| 77566 
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
 wenzelm parents: 
76548diff
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: 
76548diff
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: 
78147diff
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" | |
| 78147 | 35 | val default_version = "1.5.5-4" | 
| 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 | ||
| 58 | val jar_name = component_name + ".jar" | |
| 76518 | 59 | val jar = component_dir.path + Path.basic(jar_name) | 
| 76348 | 60 | Isabelle_System.download_file( | 
| 61 | download_url + "/" + version + "/" + jar_name, jar, progress = progress) | |
| 62 | ||
| 63 |     Isabelle_System.with_tmp_dir("build") { jar_dir =>
 | |
| 76543 
fef0195f8d8e
clarified signature: prefer Scala functions instead of shell scripts;
 wenzelm parents: 
76518diff
changeset | 64 | Isabelle_System.extract(jar, jar_dir) | 
| 76518 | 65 | for (platform <- platforms) platform.install(jar_dir, component_dir.path, version) | 
| 76348 | 66 | } | 
| 67 | ||
| 68 | ||
| 69 | /* settings */ | |
| 70 | ||
| 76548 | 71 |     component_dir.write_settings("""
 | 
| 76348 | 72 | ISABELLE_ZSTD_HOME="$COMPONENT" | 
| 73 | ||
| 74 | classpath "$ISABELLE_ZSTD_HOME/""" + jar_name + """" | |
| 75 | """) | |
| 76 | } | |
| 77 | ||
| 78 | ||
| 79 | /* Isabelle tool wrapper */ | |
| 80 | ||
| 81 | val isabelle_tool = | |
| 77566 
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
 wenzelm parents: 
76548diff
changeset | 82 |     Isabelle_Tool("component_zstd", "build Isabelle zstd-jni component from official download",
 | 
| 76348 | 83 | Scala_Project.here, | 
| 84 |       { args =>
 | |
| 85 | var target_dir = Path.current | |
| 86 | var download_url = default_download_url | |
| 87 | var version = default_version | |
| 88 | ||
| 89 |         val getopts = Getopts("""
 | |
| 77566 
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
 wenzelm parents: 
76548diff
changeset | 90 | Usage: isabelle component_zstd [OPTIONS] | 
| 76348 | 91 | |
| 92 | Options are: | |
| 93 | -D DIR target directory (default ".") | |
| 94 | -U URL download URL (default: """ + quote(default_download_url) + """) | |
| 95 | -V VERSION version (default: """ + quote(default_version) + """) | |
| 96 | ||
| 97 | Build zstd-jni component from the specified download base URL and VERSION, | |
| 98 | see also https://github.com/luben/zstd-jni | |
| 99 | """, | |
| 100 | "D:" -> (arg => target_dir = Path.explode(arg)), | |
| 101 | "U:" -> (arg => download_url = arg), | |
| 102 | "V:" -> (arg => version = arg)) | |
| 103 | ||
| 104 | val more_args = getopts(args) | |
| 105 | if (more_args.nonEmpty) getopts.usage() | |
| 106 | ||
| 107 | val progress = new Console_Progress() | |
| 108 | ||
| 109 | build_zstd(target_dir = target_dir, download_url = download_url, | |
| 110 | version = version, progress = progress) | |
| 111 | }) | |
| 112 | } |