Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions tslang/tslang/exe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,36 @@ static std::string getTargetLibDir(llvm::StringRef path, bool windowsX86)
return dir.str().str();
}

// Neither the option nor its variable given: the folder tslang itself is in (the release package
// keeps gc.lib and TypeScriptAsyncRuntime.lib beside tslang.exe) or its ../lib (a Linux build),
// whichever holds the target's `name` library. Without it the link named no folder at all, so it
// found the libraries only when run from tslang's own folder. Empty when neither holds it, as
// before, so a cross compile does not pick up the host's libraries.
static std::string findLibBesideCompiler(llvm::StringRef name)
{
llvm::SmallString<256> exeDir(getExecutablePath("tslang"));
llvm::sys::path::remove_filename(exeDir);
if (exeDir.empty())
{
return "";
}

llvm::SmallString<256> libDir(exeDir);
llvm::sys::path::append(libDir, "..", "lib");
llvm::sys::path::remove_dots(libDir, /*remove_dot_dot=*/true);
for (llvm::StringRef dir : {exeDir.str(), libDir.str()})
{
llvm::SmallString<256> lib(getTargetLibDir(dir, isWindowsX86Target()));
llvm::sys::path::append(lib, getTargetStaticLibName(name));
if (llvm::sys::fs::exists(lib))
{
return dir.str();
}
}

return "";
}

void checkGCLibPath(std::string path)
{
if (isWindowsX86Target())
Expand Down Expand Up @@ -268,7 +298,7 @@ std::string getGCLibPath()
return gcLibEnvValue.value();
}

return "";
return findLibBesideCompiler("gc");
}

// Boehm built as a DLL: a directory holding its import library `gc.lib`, with `gc.dll` beside it
Expand Down Expand Up @@ -327,6 +357,11 @@ std::string getGCSharedLibPath()
staticPath = llvm::sys::Process::GetEnv("GC_LIB_PATH").value_or("");
}

if (staticPath.empty())
{
staticPath = findLibBesideCompiler("gc");
}

if (!staticPath.empty())
{
// the release package: the shared build in a gcdll folder beside the static gc.lib
Expand Down Expand Up @@ -376,7 +411,7 @@ std::string getTslangLibPath()
return tslangLibEnvValue.value();
}

return "";
return findLibBesideCompiler("TypeScriptAsyncRuntime");
}

std::string getEMSDKSysRootPath()
Expand Down
Loading