| author | wenzelm | 
| Thu, 10 Apr 2025 20:54:02 +0200 | |
| changeset 82481 | 041d65893a85 | 
| parent 82467 | b0740dce1f1d | 
| child 82499 | d46bc8a03141 | 
| permissions | -rw-r--r-- | 
| 77566 
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
 wenzelm parents: 
77510diff
changeset | 1 | /* Title: Pure/Admin/component_csdp.scala | 
| 72414 | 2 | Author: Makarius | 
| 3 | ||
| 72437 | 4 | Build Isabelle CSDP component from official download. | 
| 72414 | 5 | */ | 
| 6 | ||
| 7 | package isabelle | |
| 8 | ||
| 9 | ||
| 77566 
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
 wenzelm parents: 
77510diff
changeset | 10 | object Component_CSDP {
 | 
| 72417 | 11 | // Note: version 6.2.0 does not quite work for the "sos" proof method | 
| 12 | val default_download_url = "https://github.com/coin-or/Csdp/archive/releases/6.1.1.tar.gz" | |
| 72414 | 13 | |
| 14 | ||
| 72417 | 15 | /* flags */ | 
| 72414 | 16 | |
| 75393 | 17 |   sealed case class Flags(platform: String, CFLAGS: String = "", LIBS: String = "") {
 | 
| 72417 | 18 | val changed: List[(String, String)] = | 
| 19 |       List("CFLAGS" -> CFLAGS, "LIBS" -> LIBS).filter(p => p._2.nonEmpty)
 | |
| 20 | ||
| 72438 | 21 | def print: Option[String] = | 
| 22 | if (changed.isEmpty) None | |
| 23 | else | |
| 73712 | 24 |         Some("  * " + platform + ":\n" + changed.map(p => "    " + Properties.Eq(p))
 | 
| 72438 | 25 |           .mkString("\n"))
 | 
| 72414 | 26 | |
| 75393 | 27 |     def change(path: Path): Unit = {
 | 
| 73714 | 28 | def change_line(line: String, p: (String, String)): String = | 
| 29 | line.replaceAll(p._1 + "=.*", Properties.Eq(p)) | |
| 75205 | 30 |       File.change_lines(path) { _.map(line => changed.foldLeft(line)(change_line)) }
 | 
| 72414 | 31 | } | 
| 32 | } | |
| 33 | ||
| 34 | val build_flags: List[Flags] = | |
| 35 | List( | |
| 36 |       Flags("arm64-linux",
 | |
| 72417 | 37 | CFLAGS = "-O3 -ansi -Wall -DNOSHORTS -DBIT64 -DUSESIGTERM -DUSEGETTIME -I../include", | 
| 72414 | 38 | LIBS = "-static -L../lib -lsdp -llapack -lblas -lgfortran -lm"), | 
| 72417 | 39 |       Flags("x86_64-linux",
 | 
| 40 | CFLAGS = "-O3 -ansi -Wall -DNOSHORTS -DBIT64 -DUSESIGTERM -DUSEGETTIME -I../include", | |
| 72414 | 41 | LIBS = "-static -L../lib -lsdp -llapack -lblas -lgfortran -lquadmath -lm"), | 
| 42 |       Flags("x86_64-darwin",
 | |
| 72417 | 43 | CFLAGS = "-O3 -Wall -DNOSHORTS -DBIT64 -DUSESIGTERM -DUSEGETTIME -I../include", | 
| 44 | LIBS = "-L../lib -lsdp -llapack -lblas -lm"), | |
| 45 |       Flags("x86_64-windows"))
 | |
| 46 | ||
| 47 | ||
| 48 | /* build CSDP */ | |
| 72414 | 49 | |
| 50 | def build_csdp( | |
| 72417 | 51 | download_url: String = default_download_url, | 
| 72414 | 52 | progress: Progress = new Progress, | 
| 72418 
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
 wenzelm parents: 
72417diff
changeset | 53 | target_dir: Path = Path.current, | 
| 75393 | 54 | mingw: MinGW = MinGW.none | 
| 55 |   ): Unit = {
 | |
| 82467 
b0740dce1f1d
clarified signature: fewer warnings in IntelliJ IDEA;
 wenzelm parents: 
80224diff
changeset | 56 | mingw.check() | 
| 72423 | 57 | |
| 75394 | 58 |     Isabelle_System.with_tmp_dir("build") { tmp_dir =>
 | 
| 72417 | 59 | /* component */ | 
| 60 | ||
| 61 | val Archive_Name = """^.*?([^/]+)$""".r | |
| 62 | val Version = """^[^0-9]*([0-9].*)\.tar.gz$""".r | |
| 63 | ||
| 64 | val archive_name = | |
| 65 |         download_url match {
 | |
| 66 | case Archive_Name(name) => name | |
| 67 |           case _ => error("Failed to determine source archive name from " + quote(download_url))
 | |
| 68 | } | |
| 69 | ||
| 70 | val version = | |
| 71 |         archive_name match {
 | |
| 72 | case Version(version) => version | |
| 73 |           case _ => error("Failed to determine component version from " + quote(archive_name))
 | |
| 74 | } | |
| 75 | ||
| 76 | val component_name = "csdp-" + version | |
| 76518 | 77 | val component_dir = | 
| 76547 | 78 | Components.Directory(target_dir + Path.basic(component_name)).create(progress = progress) | 
| 72414 | 79 | |
| 80 | ||
| 81 | /* platform */ | |
| 82 | ||
| 80049 | 83 | val platform_name = Isabelle_Platform.self.ISABELLE_PLATFORM(windows = true) | 
| 76518 | 84 | val platform_dir = | 
| 85 | Isabelle_System.make_directory(component_dir.path + Path.basic(platform_name)) | |
| 72414 | 86 | |
| 87 | ||
| 72417 | 88 | /* download source */ | 
| 72414 | 89 | |
| 72417 | 90 | val archive_path = tmp_dir + Path.basic(archive_name) | 
| 73566 | 91 | Isabelle_System.download_file(download_url, archive_path, progress = progress) | 
| 72417 | 92 | |
| 76540 
83de6e9ae983
clarified signature: prefer Scala functions instead of shell scripts;
 wenzelm parents: 
76529diff
changeset | 93 | Isabelle_System.extract(archive_path, tmp_dir) | 
| 
83de6e9ae983
clarified signature: prefer Scala functions instead of shell scripts;
 wenzelm parents: 
76529diff
changeset | 94 | val source_dir = File.get_dir(tmp_dir, title = download_url) | 
| 72414 | 95 | |
| 76541 | 96 | Isabelle_System.extract(archive_path, component_dir.src, strip = true) | 
| 72414 | 97 | |
| 98 | ||
| 99 | /* build */ | |
| 100 | ||
| 72440 | 101 |       progress.echo("Building CSDP for " + platform_name + " ...")
 | 
| 72414 | 102 | |
| 72417 | 103 |       build_flags.find(flags => flags.platform == platform_name) match {
 | 
| 104 |         case None => error("No build flags for platform " + quote(platform_name))
 | |
| 105 | case Some(flags) => | |
| 76529 | 106 | File.find_files(source_dir.file, pred = file => file.getName == "Makefile"). | 
| 72417 | 107 | foreach(file => flags.change(File.path(file))) | 
| 72414 | 108 | } | 
| 72418 
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
 wenzelm parents: 
72417diff
changeset | 109 | |
| 77510 
f5d6cd98b16a
clarified signature: manage "verbose" flag via "progress";
 wenzelm parents: 
76548diff
changeset | 110 |       progress.bash(mingw.bash_script("make"),
 | 
| 80224 
db92e0b6a11a
clarified signature: prefer symbolic isabelle.Path over physical java.io.File;
 wenzelm parents: 
80049diff
changeset | 111 | cwd = source_dir, | 
| 77510 
f5d6cd98b16a
clarified signature: manage "verbose" flag via "progress";
 wenzelm parents: 
76548diff
changeset | 112 | echo = progress.verbose).check | 
| 72418 
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
 wenzelm parents: 
72417diff
changeset | 113 | |
| 
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
 wenzelm parents: 
72417diff
changeset | 114 | |
| 
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
 wenzelm parents: 
72417diff
changeset | 115 | /* install */ | 
| 72414 | 116 | |
| 76529 | 117 |       Isabelle_System.copy_file(source_dir + Path.explode("LICENSE"), component_dir.path)
 | 
| 118 |       Isabelle_System.copy_file(source_dir + Path.explode("solver/csdp").platform_exe, platform_dir)
 | |
| 72418 
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
 wenzelm parents: 
72417diff
changeset | 119 | |
| 72463 | 120 |       if (Platform.is_windows) {
 | 
| 121 |         Executable.libraries_closure(platform_dir + Path.explode("csdp.exe"), mingw = mingw,
 | |
| 122 | filter = | |
| 72468 | 123 |             Set("libblas", "liblapack", "libgfortran", "libgcc_s_seh",
 | 
| 124 | "libquadmath", "libwinpthread")) | |
| 72418 
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
 wenzelm parents: 
72417diff
changeset | 125 | } | 
| 72414 | 126 | |
| 127 | ||
| 128 | /* settings */ | |
| 129 | ||
| 76548 | 130 |       component_dir.write_settings("""
 | 
| 72414 | 131 | ISABELLE_CSDP="$COMPONENT/${ISABELLE_WINDOWS_PLATFORM64:-$ISABELLE_PLATFORM64}/csdp"
 | 
| 132 | """) | |
| 133 | ||
| 134 | ||
| 135 | /* README */ | |
| 136 | ||
| 76518 | 137 | File.write(component_dir.README, | 
| 72417 | 138 | """This is CSDP """ + version + """ from | 
| 139 | """ + download_url + """ | |
| 72414 | 140 | |
| 72417 | 141 | Makefile flags have been changed for various platforms as follows: | 
| 72414 | 142 | |
| 72438 | 143 | """ + build_flags.flatMap(_.print).mkString("\n\n") + """
 | 
| 144 | ||
| 72417 | 145 | The distribution has been built like this: | 
| 72414 | 146 | |
| 72417 | 147 | cd src && make | 
| 72414 | 148 | |
| 72417 | 149 | Only the bare "solver/csdp" program is used for Isabelle. | 
| 72414 | 150 | |
| 151 | ||
| 72444 | 152 | Makarius | 
| 153 | """ + Date.Format.date(Date.now()) + "\n") | |
| 75394 | 154 | } | 
| 72414 | 155 | } | 
| 156 | ||
| 157 | ||
| 158 | /* Isabelle tool wrapper */ | |
| 159 | ||
| 160 | val isabelle_tool = | |
| 77566 
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
 wenzelm parents: 
77510diff
changeset | 161 |     Isabelle_Tool("component_csdp", "build prover component from official download", Scala_Project.here,
 | 
| 75394 | 162 |       { args =>
 | 
| 163 | var target_dir = Path.current | |
| 164 | var mingw = MinGW.none | |
| 165 | var download_url = default_download_url | |
| 166 | var verbose = false | |
| 72414 | 167 | |
| 75394 | 168 |         val getopts = Getopts("""
 | 
| 77566 
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
 wenzelm parents: 
77510diff
changeset | 169 | Usage: isabelle component_csdp [OPTIONS] | 
| 72414 | 170 | |
| 171 | Options are: | |
| 172 | -D DIR target directory (default ".") | |
| 72425 | 173 | -M DIR msys/mingw root specification for Windows | 
| 72417 | 174 | -U URL download URL | 
| 175 | (default: """" + default_download_url + """") | |
| 72414 | 176 | -v verbose | 
| 177 | ||
| 72437 | 178 | Build prover component from official download. | 
| 72414 | 179 | """, | 
| 75394 | 180 | "D:" -> (arg => target_dir = Path.explode(arg)), | 
| 181 | "M:" -> (arg => mingw = MinGW(Path.explode(arg))), | |
| 182 | "U:" -> (arg => download_url = arg), | |
| 183 | "v" -> (_ => verbose = true)) | |
| 72414 | 184 | |
| 75394 | 185 | val more_args = getopts(args) | 
| 186 | if (more_args.nonEmpty) getopts.usage() | |
| 72414 | 187 | |
| 77510 
f5d6cd98b16a
clarified signature: manage "verbose" flag via "progress";
 wenzelm parents: 
76548diff
changeset | 188 | val progress = new Console_Progress(verbose = verbose) | 
| 72414 | 189 | |
| 77510 
f5d6cd98b16a
clarified signature: manage "verbose" flag via "progress";
 wenzelm parents: 
76548diff
changeset | 190 | build_csdp(download_url = download_url, progress = progress, | 
| 75394 | 191 | target_dir = target_dir, mingw = mingw) | 
| 192 | }) | |
| 72414 | 193 | } |