1+ module redub.misc.ldc_install ;
2+ import std.system ;
3+
4+ bool installLdc (string ldcVersion, OS os = std.system.os , ISA isa = instructionSetArchitecture)
5+ {
6+ import std.array ;
7+ import std.file ;
8+ import redub.api;
9+ import redub.meta;
10+ import redub.misc.path;
11+ import redub.misc.unzip;
12+ import redub.libs.package_suppliers.utils;
13+ import redub.misc.make_file_executable;
14+ import redub.logging;
15+ string downloadLink = getLdcDownloadLink(ldcVersion, os, isa);
16+
17+ string workspace = buildNormalizedPath(getDubWorkspacePath, " redub-ldc" );
18+ string binPath = buildNormalizedPath(workspace, getLdcFolderName(ldcVersion, os, isa), " bin" );
19+ if (! exists(workspace))
20+ mkdirRecurse(workspace);
21+ if (exists(binPath))
22+ {
23+ infos(" LDC " ,ldcVersion," is already installed at path " , binPath);
24+ return true ;
25+ }
26+
27+ if (! downloadAndExtract(downloadLink, workspace))
28+ return false ;
29+ foreach (executable; [" ldc2" , " ldmd2" , " rdmd" , " dub" ].staticArray)
30+ if (! makeFileExecutable(buildNormalizedPath(binPath, executable)))
31+ return false ;
32+ return true ;
33+ }
34+
35+ string getLdcFolderName (string ver, OS os = std.system.os , ISA isa = instructionSetArchitecture)
36+ {
37+ import redub.command_generators.commons;
38+ import redub.api;
39+ import core.interpolation ;
40+ import std.conv :to,text;
41+ import std.string :startsWith;
42+ string sys;
43+ if (ver.startsWith(" v" ))
44+ ver = ver[1 .. $];
45+
46+ if (os.isWindows)
47+ sys = " windows-multilib" ;
48+ else if (os.isApple)
49+ sys = " osx-universal" ;
50+ else if (os.isPosix)
51+ sys = isa == ISA .aarch64 ? " linux-aarch64" : " linux-x86_64" ;
52+ else
53+ throw new RedubException(" Redub has no support to LDC for the OS '" ~ os.to! string ~ " '" );
54+ return i" ldc2-$(ver)-$(sys)" .text;
55+ }
56+ string getLdcDownloadLink (string ver, OS os = std.system.os , ISA isa = instructionSetArchitecture)
57+ {
58+ import redub.command_generators.commons;
59+ import redub.api;
60+ import core.interpolation ;
61+ import std.conv :to,text;
62+ import std.string :startsWith;
63+ string sys;
64+ if (ver.startsWith(" v" ))
65+ ver = ver[1 .. $];
66+
67+ if (os.isWindows)
68+ sys = " windows-multilib.7z" ;
69+ else if (os.isApple)
70+ sys = " osx-universal.tar.xz" ;
71+ else if (os.isPosix)
72+ sys = isa == ISA .aarch64 ? " linux-aarch64.tar.xz" : " linux-x86_64.tar.xz" ;
73+ else
74+ throw new RedubException(" Redub has no support to LDC for the OS '" ~ os.to! string ~ " '" );
75+ return i" https://github.com/ldc-developers/ldc/releases/download/v$(ver)/ldc2-$(ver)-$(sys)" .text;
76+ }
0 commit comments