From 2db3be289c66eaceae605f4224103944a9613460 Mon Sep 17 00:00:00 2001 From: ASDAlexander77 Date: Tue, 20 Oct 2026 18:36:03 +0100 Subject: [PATCH] The default library is found next to tslang when no path is given With neither --default-lib-path nor DEFAULT_LIB_PATH, getDefaultLibPath returned "", so the library was looked for in ./defaultlib of the current folder: tslang compiled with no default library unless it ran from its own folder. --install-default-lib already installs into the folder of tslang when not told where; compiling now looks there too, when it holds defaultlib. Co-Authored-By: Claude Opus 5.5 --- tslang/tslang/exe.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tslang/tslang/exe.cpp b/tslang/tslang/exe.cpp index 17aa60582..4b20b6558 100644 --- a/tslang/tslang/exe.cpp +++ b/tslang/tslang/exe.cpp @@ -108,12 +108,24 @@ std::string getDefaultLibPath() return defaultlibpath; } - if (auto gcDefaultLibEnvValue = llvm::sys::Process::GetEnv("DEFAULT_LIB_PATH")) + if (auto gcDefaultLibEnvValue = llvm::sys::Process::GetEnv("DEFAULT_LIB_PATH")) { return gcDefaultLibEnvValue.value(); - } + } - return ""; + // Neither given: the folder of tslang itself, where --install-default-lib puts the library + // when it is not told where. Only if it holds one, so a tslang without it still compiles with + // no default library rather than failing on a path nobody asked for. + llvm::SmallString<256> exeDir(getExecutablePath("tslang")); + llvm::sys::path::remove_filename(exeDir); + llvm::SmallString<256> exeDefaultLibDir(exeDir); + llvm::sys::path::append(exeDefaultLibDir, DEFAULT_LIB_DIR); + if (!exeDir.empty() && llvm::sys::fs::is_directory(exeDefaultLibDir)) + { + return exeDir.str().str(); + } + + return ""; } bool checkFileExistsAtPath(std::string path, std::string fileName)