Skip to content

Commit

Permalink
feat: re-run with LD_LIBRARY_PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
zaucy committed Aug 11, 2024
1 parent 0be77fd commit f655bdb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
28 changes: 28 additions & 0 deletions share/cpp2b.cppm.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
module;

#ifdef _MSC_VER
# include <processenv.h>
#else
# include <stdlib.h>
#endif

export module cpp2b;

import std;
import std.compat;

export namespace cpp2b {
Expand Down Expand Up @@ -48,3 +57,22 @@ constexpr auto install_dir() -> const std::string_view {
}

} // namespace cpp2b

export namespace cpp2b::env {
inline auto set_var(const std::string& name, const std::string& value) -> void {
#if defined(_MSC_VER)
SetEnvironmentVariableA(name.c_str(), value.c_str());
#else
setenv(name.c_str(), value.c_str(), 1);
#endif
}

inline auto get_var(const std::string& name) -> std::optional<std::string> {
auto val = std::getenv(name.c_str());
if(val != nullptr) {
return std::string{val};
}

return {};
}
}
17 changes: 17 additions & 0 deletions src/main.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,15 @@ run_with_msvc_env_vars: (args) -> int = {
return std::system(cmd_str.c_str());
}

run_with_args: (args) -> int = {
cmd_str: std::string = "";
for args do (arg) {
cmd_str += " (arg)$";
}

return std::system(cmd_str.c_str());
}

main: (args) -> int = {
using std::views::drop;

Expand All @@ -324,6 +333,14 @@ main: (args) -> int = {
} else {
log_info("using vs tools {}", getenv_sv("VCToolsVersion").expect("msvc env internal error"));
}
} else {
libcxx_lib_dir := get_libcxx_build_root() / "lib";
ld_library_path := cpp2b::env::get_var("LD_LIBRARY_PATH");
if !ld_library_path || !ld_library_path*.contains(libcxx_lib_dir.string()) {
log_info("setting LD_LIBRARY_PATH to '{}'", libcxx_lib_dir.string());
cpp2b::env::set_var("LD_LIBRARY_PATH", libcxx_lib_dir.string());
return run_with_args(argz);
}
}

ensure_dir(".cache/cpp2/mod");
Expand Down

0 comments on commit f655bdb

Please sign in to comment.