Skip to content

Commit 9c566ee

Browse files
committed
Initial intel compiler detection.
1 parent 07b9e58 commit 9c566ee

6 files changed

Lines changed: 158 additions & 19 deletions

File tree

src/sw/builder/command.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ String Command::makeErrorString(const String &e)
634634
boost::replace_all(err.text, "\r", "");
635635
s += "\n" + boost::trim_copy(err.text);
636636
}
637+
boost::trim(s);
637638
s += "\n";
638639
s += e;
639640
boost::trim(s);
@@ -655,7 +656,7 @@ String Command::saveCommand() const
655656

656657
String s;
657658
s += "\n";
658-
s += "pid = " + std::to_string(pid) + "\n";
659+
//s += "pid = " + std::to_string(pid) + "\n";
659660
s += "command is copied to " + p.u8string() + "\n";
660661

661662
return s;

src/sw/client/cli/command/build.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ static sw::TargetSettings compilerTypeFromStringCaseI(const sw::UnresolvedPackag
159159
ts["native"]["program"]["cpp"] = set_with_version("com.Microsoft.VisualStudio.VC.cl");
160160
ts["native"]["program"]["asm"] = set_with_version("com.Microsoft.VisualStudio.VC.ml");
161161
}
162+
else if (compiler.ppath == "intel")
163+
{
164+
ts["native"]["program"]["c"] = set_with_version("com.intel.compiler.c");
165+
ts["native"]["program"]["cpp"] = set_with_version("com.intel.compiler.cpp");
166+
ts["native"]["program"]["asm"] = set_with_version("com.Microsoft.VisualStudio.VC.ml");
167+
ts["native"]["program"]["lib"] = "com.intel.compiler.lib";
168+
ts["native"]["program"]["link"] = "com.intel.compiler.link";
169+
}
162170
else
163171
{
164172
ts["native"]["program"]["c"] = compiler.toString();

src/sw/core/program/detect.cpp

Lines changed: 104 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ static Strings listWindowsKits()
730730
return kits;
731731
}
732732

733-
void detectWindowsSdk(DETECT_ARGS)
733+
static void detectWindowsSdk(DETECT_ARGS)
734734
{
735735
// ucrt - universal CRT
736736
//
@@ -908,14 +908,14 @@ void detectWindowsSdk(DETECT_ARGS)
908908
}
909909
}
910910

911-
void detectMsvc(DETECT_ARGS)
911+
static void detectMsvc(DETECT_ARGS)
912912
{
913913
detectMsvc15Plus(s);
914914
detectMsvc14AndOlder(s);
915915
detectWindowsSdk(s);
916916
}
917917

918-
void detectWindowsClang(DETECT_ARGS)
918+
static void detectWindowsClang(DETECT_ARGS)
919919
{
920920
// create programs
921921
const path base_llvm_path = path("c:") / "Program Files" / "LLVM";
@@ -1024,13 +1024,111 @@ void detectWindowsClang(DETECT_ARGS)
10241024
}
10251025
}
10261026

1027-
void detectWindowsCompilers(DETECT_ARGS)
1027+
static void detectIntelCompilers(DETECT_ARGS)
1028+
{
1029+
// some info at https://gitlab.com/ita1024/waf/blob/master/waflib/Tools/msvc.py#L521
1030+
1031+
// C, C++
1032+
1033+
// win
1034+
{
1035+
auto add_prog_from_path = [&s](const path &name, const String &ppath)
1036+
{
1037+
auto p = std::make_shared<SimpleProgram>(s);
1038+
p->file = resolveExecutable(name);
1039+
if (fs::exists(p->file))
1040+
{
1041+
auto v = getVersion(s, p->file);
1042+
addProgram(s, PackageId(ppath, v), p);
1043+
1044+
// icl/xilib/xilink on win wants VC in PATH
1045+
auto &cld = s.getPredefinedTargets();
1046+
auto i = cld["com.Microsoft.VisualStudio.VC.cl"].rbegin_releases();
1047+
if (i != cld["com.Microsoft.VisualStudio.VC.cl"].rend_releases())
1048+
{
1049+
if (!i->second.empty())
1050+
{
1051+
if (auto t = (*i->second.begin())->as<PredefinedProgramTarget *>())
1052+
{
1053+
path x = t->getProgram().getCommand()->getProgram();
1054+
p->getCommand()->addPathDirectory(x.parent_path());
1055+
}
1056+
}
1057+
}
1058+
}
1059+
return p;
1060+
};
1061+
1062+
add_prog_from_path("icl", "com.intel.compiler.c");
1063+
add_prog_from_path("icl", "com.intel.compiler.cpp");
1064+
add_prog_from_path("xilib", "com.intel.compiler.lib");
1065+
add_prog_from_path("xilink", "com.intel.compiler.link");
1066+
1067+
// ICPP_COMPILER{VERSION} like ICPP_COMPILER19 etc.
1068+
for (int i = 9; i < 23; i++)
1069+
{
1070+
auto s = "ICPP_COMPILER" + std::to_string(i);
1071+
auto v = getenv(s.c_str());
1072+
if (!v)
1073+
continue;
1074+
1075+
path root = v;
1076+
auto bin = root;
1077+
bin /= "bin";
1078+
auto arch = "intel64";
1079+
bin /= arch;
1080+
1081+
std::shared_ptr<SimpleProgram> p;
1082+
p = add_prog_from_path(bin / "icl", "com.intel.compiler.c");
1083+
p->getCommand()->push_back("-I");
1084+
p->getCommand()->push_back(root / "compiler" / "include");
1085+
1086+
p = add_prog_from_path(bin / "icl", "com.intel.compiler.cpp");
1087+
p->getCommand()->push_back("-I");
1088+
p->getCommand()->push_back(root / "compiler" / "include");
1089+
1090+
add_prog_from_path(bin / "xilib", "com.intel.compiler.lib");
1091+
1092+
p = add_prog_from_path(bin / "xilink", "com.intel.compiler.link");
1093+
p->getCommand()->push_back("-LIBPATH:" + (root / "compiler" / "lib" / arch).u8string());
1094+
p->getCommand()->push_back("libirc.lib");
1095+
}
1096+
1097+
// also registry paths
1098+
// HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Intel ...
1099+
}
1100+
1101+
// *nix
1102+
{
1103+
{
1104+
auto p = std::make_shared<SimpleProgram>(s); // new object
1105+
p->file = resolveExecutable("icc");
1106+
if (fs::exists(p->file))
1107+
{
1108+
auto v = getVersion(s, p->file);
1109+
addProgram(s, PackageId("com.intel.compiler.c", v), p);
1110+
}
1111+
}
1112+
1113+
{
1114+
auto p = std::make_shared<SimpleProgram>(s); // new object
1115+
p->file = resolveExecutable("icpc");
1116+
if (fs::exists(p->file))
1117+
{
1118+
auto v = getVersion(s, p->file);
1119+
addProgram(s, PackageId("com.intel.compiler.cpp", v), p);
1120+
}
1121+
}
1122+
}
1123+
}
1124+
1125+
static void detectWindowsCompilers(DETECT_ARGS)
10281126
{
10291127
detectMsvc(s);
10301128
detectWindowsClang(s);
10311129
}
10321130

1033-
void detectNonWindowsCompilers(DETECT_ARGS)
1131+
static void detectNonWindowsCompilers(DETECT_ARGS)
10341132
{
10351133
auto resolve_and_add = [&s](const path &prog, const String &ppath)
10361134
{
@@ -1081,6 +1179,7 @@ void detectNativeCompilers(DETECT_ARGS)
10811179
}
10821180
else
10831181
detectNonWindowsCompilers(s);
1182+
detectIntelCompilers(s);
10841183
}
10851184

10861185
}

src/sw/driver/target/native.cpp

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -190,16 +190,21 @@ static void targetSettings2Command(primitives::Command &c, const TargetSetting &
190190
}
191191
}
192192

193-
void NativeCompiledTarget::activateCompiler(const TargetSetting &s, const StringSet &exts)
193+
static auto get_settings_package_id(const TargetSetting &s)
194194
{
195195
bool extended_desc = s.isObject();
196-
197196
UnresolvedPackage id;
198197
if (extended_desc)
199198
id = s["package"].getValue();
200199
else
201200
id = s.getValue();
201+
return id;
202+
}
202203

204+
void NativeCompiledTarget::activateCompiler(const TargetSetting &s, const StringSet &exts)
205+
{
206+
bool extended_desc = s.isObject();
207+
auto id = get_settings_package_id(s);
203208
activateCompiler(s, id, exts, extended_desc);
204209
}
205210

@@ -232,6 +237,10 @@ void NativeCompiledTarget::activateCompiler(const TargetSetting &s, const Unreso
232237
ct = CompilerType::Clang;
233238
else if (id.ppath == "org.LLVM.clangcl")
234239
ct = CompilerType::ClangCl;
240+
else if (id.ppath == "com.intel.compiler.c" || id.ppath == "com.intel.compiler.cpp")
241+
ct = CompilerType::Intel;
242+
//else
243+
//throw SW_RUNTIME_ERROR("Unknown compiler type: " + id.toString());
235244
};
236245

237246
auto c = std::dynamic_pointer_cast<CompilerBaseProgram>(t->getProgram().clone());
@@ -331,6 +340,20 @@ void NativeCompiledTarget::activateCompiler(const TargetSetting &s, const Unreso
331340
throw SW_RUNTIME_ERROR("Unknown arch");
332341
}
333342
}
343+
else if (id.ppath == "com.intel.compiler.c" || id.ppath == "com.intel.compiler.cpp")
344+
{
345+
auto C = std::make_shared<VisualStudioCompiler>(getSolution().getContext());
346+
c = C;
347+
C->ForceSynchronousPDBWrites = false;
348+
if (ts["native"]["stdlib"]["cpp"].getValue() == "com.Microsoft.VisualStudio.VC.libcpp")
349+
{
350+
// take same ver as cl
351+
UnresolvedPackage up(ts["native"]["stdlib"]["cpp"].getValue());
352+
up.range = id.range;
353+
*this += up;
354+
libstdcppset = true;
355+
}
356+
}
334357
else
335358
throw SW_RUNTIME_ERROR("Unknown compiler: " + id.toString());
336359

@@ -342,13 +365,7 @@ void NativeCompiledTarget::activateCompiler(const TargetSetting &s, const Unreso
342365
std::shared_ptr<NativeLinker> NativeCompiledTarget::activateLinker(const TargetSetting &s)
343366
{
344367
bool extended_desc = s.isObject();
345-
346-
UnresolvedPackage id;
347-
if (extended_desc)
348-
id = s["package"].getValue();
349-
else
350-
id = s.getValue();
351-
368+
auto id = get_settings_package_id(s);
352369
return activateLinker(s, id, extended_desc);
353370
}
354371

@@ -379,7 +396,8 @@ std::shared_ptr<NativeLinker> NativeCompiledTarget::activateLinker(const TargetS
379396
targetSettings2Command(*C, s["command"]);
380397
};
381398

382-
if (id.ppath == "com.Microsoft.VisualStudio.VC.lib")
399+
if (0);
400+
else if (id.ppath == "com.Microsoft.VisualStudio.VC.lib")
383401
{
384402
c = std::make_shared<VisualStudioLibrarian>(getSolution().getContext());
385403
c->Type = LinkerType::MSVC;
@@ -457,6 +475,16 @@ std::shared_ptr<NativeLinker> NativeCompiledTarget::activateLinker(const TargetS
457475
//cmd->push_back("-target");
458476
//cmd->push_back(getBuildSettings().getTargetTriplet());
459477
}
478+
else if (id.ppath == "com.intel.compiler.lib")
479+
{
480+
c = std::make_shared<VisualStudioLibrarian>(getSolution().getContext());
481+
c->Type = LinkerType::MSVC;
482+
}
483+
else if (id.ppath == "com.intel.compiler.link")
484+
{
485+
c = std::make_shared<VisualStudioLinker>(getSolution().getContext());
486+
c->Type = LinkerType::MSVC;
487+
}
460488
else
461489
throw SW_RUNTIME_ERROR("Unknown librarian/linker: " + id.toString());
462490

@@ -492,7 +520,7 @@ void NativeCompiledTarget::findCompiler()
492520
activateCompiler(ts["native"]["program"]["c"], { ".c" });
493521

494522
if (ct == CompilerType::UnspecifiedCompiler)
495-
throw SW_RUNTIME_ERROR("Unknown compiler: " + ts.toString());
523+
throw SW_RUNTIME_ERROR("Unknown compiler: " + get_settings_package_id(ts["native"]["program"]["c"]).toString());
496524

497525
if (getBuildSettings().TargetOS.is(OSType::Windows))
498526
{

src/sw/manager/sw_context.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ std::unordered_map<UnresolvedPackage, LocalPackage> SwManagerContext::install(co
133133

134134
auto &e = getExecutor();
135135
Futures<void> fs;
136-
for (auto &[_,p] : pkgs2)
137-
fs.push_back(e.push([this, &p]{ install(*p); }));
136+
for (auto &p : pkgs2)
137+
fs.push_back(e.push([this, &p]{ install(*p.second); }));
138138
waitAndGet(fs);
139139

140140
// install should be fast enough here

sw.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,9 @@ void build(Solution &s)
294294
}
295295
}
296296

297+
if (client.getBuildSettings().TargetOS.Type != OSType::Windows)
298+
return;
299+
297300
auto &gui = client.addTarget<ExecutableTarget>("gui");
298301
{
299302
gui.PackageDefinitions = true;

0 commit comments

Comments
 (0)