feat(cli): find the runtime headers next to the binary
A downloaded release has no checkout to refer to, and the include directory was baked in at configure time. `luacpp run` now looks for include/luacpp/rt.hpp beside its own executable and honours LUACPP_INCLUDE before falling back to that path. CMake gained install rules producing the bin/include/share tree the tarball is built from.
This commit is contained in:
2 files changed
+35
-2
No files matched your search
+20
-1
@@ -278,6 +278,25 @@ std::vector<fs::path> collect_lua_files(const fs::path& root) {
|
||||
return files;
|
||||
}
|
||||
|
||||
// A release tarball ships the runtime headers next to the binary
|
||||
// (<prefix>/bin/luacpp + <prefix>/include/luacpp), while a local build keeps
|
||||
// using the include directory configured by CMake. LUACPP_INCLUDE wins over both.
|
||||
std::string runtime_include_dir() {
|
||||
if (const char* env = std::getenv("LUACPP_INCLUDE")) {
|
||||
if (*env != '\0') return env;
|
||||
}
|
||||
#if defined(__linux__)
|
||||
std::error_code ec;
|
||||
fs::path exe = fs::read_symlink("/proc/self/exe", ec);
|
||||
if (!ec) {
|
||||
fs::path beside = exe.parent_path().parent_path() / "include";
|
||||
std::error_code missing;
|
||||
if (fs::exists(beside / "luacpp" / "rt.hpp", missing)) return beside.string();
|
||||
}
|
||||
#endif
|
||||
return LUACPP_RUNTIME_INCLUDE_DIR;
|
||||
}
|
||||
|
||||
int run_script(const Options& opt) {
|
||||
fs::path entry = opt.inputs.front();
|
||||
if (!fs::exists(entry)) {
|
||||
@@ -323,7 +342,7 @@ int run_script(const Options& opt) {
|
||||
for (const auto& job : jobs) command += " " + quoted(job.cpp.string());
|
||||
command += " " + quoted(driver.string());
|
||||
command += " -I" + quoted(srcDir.string());
|
||||
command += " -I" + quoted(LUACPP_RUNTIME_INCLUDE_DIR);
|
||||
command += " -I" + quoted(runtime_include_dir());
|
||||
command += " " + lua_link_flags();
|
||||
std::string gui_flags = LUACPP_GUI_FLAGS;
|
||||
if (!gui_flags.empty()) command += " " + gui_flags;
|
||||
|
||||
Reference in new issue
Block a user