From d115a2e02016d2684bbae08c42af9e428d09801f Mon Sep 17 00:00:00 2001 From: ASDAlexander77 Date: Wed, 2 Dec 2026 16:28:59 +0000 Subject: [PATCH] --emit=exe finds gc.lib and TypeScriptAsyncRuntime.lib beside tslang when no path is given With neither --gc-lib-path/GC_LIB_PATH nor --tslang-lib-path/TSLANG_LIB_PATH, the link named no library folder, so lld-link found gc.lib and the runtime only when run from tslang's own folder (the release package): from any other folder every program failed with "could not open 'gc.lib'". Now the folder tslang is in (or its ../lib, the Linux build) is used when it holds the target's library, as the default library and the JIT's runtime lookup already do. Co-Authored-By: Claude Opus 5.5 --- tslang/tslang/exe.cpp | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/tslang/tslang/exe.cpp b/tslang/tslang/exe.cpp index b4709d7d7..34c8b7373 100644 --- a/tslang/tslang/exe.cpp +++ b/tslang/tslang/exe.cpp @@ -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()) @@ -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 @@ -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 @@ -376,7 +411,7 @@ std::string getTslangLibPath() return tslangLibEnvValue.value(); } - return ""; + return findLibBesideCompiler("TypeScriptAsyncRuntime"); } std::string getEMSDKSysRootPath()