Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release/4.0' into macos
Browse files Browse the repository at this point in the history
  • Loading branch information
spoonincode committed Sep 20, 2023
2 parents c3af527 + d970278 commit f6ef88a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
20 changes: 19 additions & 1 deletion tools/include/compiler_options.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <string>
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "llvm/ADT/ScopeExit.h"

#ifdef ONLY_LD
#define LD_CAT EosioLdToolCategory
Expand Down Expand Up @@ -546,14 +547,31 @@ static void GetLdDefaults(std::vector<std::string>& ldopts) {
} else {
#ifdef __APPLE__
ldopts.insert(ldopts.end(), {"-arch", "x86_64", "-macosx_version_min", "10.13", "-framework", "Foundation", "-framework", "System"});

llvm::SmallString<256> output;
if(llvm::sys::fs::createTemporaryFile("cdtsdkroot", ".path", output))
throw std::runtime_error("Failed to create tmp file");
auto delete_output = llvm::make_scope_exit([&](){ llvm::sys::fs::remove(output); });

if(!eosio::cdt::environment::exec_subprogram("xcrun", {"--show-sdk-path"}, true, llvm::None, {output.str()}))
throw std::runtime_error("Failed to run xcrun --show-sdk-path");

auto buf = llvm::MemoryBuffer::getFile(output);
if(!buf)
throw std::runtime_error("Failed to open tmp file");

std::string sdkpath = buf.get()->getBuffer();
//remove newline
sdkpath.resize(sdkpath.size()-1);
ldopts.insert(ldopts.end(), {"-syslibroot", sdkpath});
#endif
if (fshared_opt) {
ldopts.emplace_back("-shared");
}
else {
ldopts.emplace_back("-static");
}
ldopts.insert(ldopts.end(), {"-Bstatic", "-lnative_c++", "-lnative_c", "-lnative_eosio", "-lnative", "-lnative_rt"});
ldopts.insert(ldopts.end(), {"-lnative_c++", "-lnative_c", "-lnative_eosio", "-lnative", "-lnative_rt"});
}
}
#endif
Expand Down
12 changes: 8 additions & 4 deletions tools/include/eosio/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ struct environment {
return env_table;
}
static bool exec_subprogram(const std::string prog, std::vector<std::string> options, bool root=false,
llvm::Optional<std::string> stdin_file = llvm::None) {
llvm::Optional<std::string> stdin_file = llvm::None,
llvm::Optional<std::string> stdout_file = llvm::None) {
std::vector<llvm::StringRef> args;
args.push_back(prog);
args.insert(args.end(), options.begin(), options.end());
Expand All @@ -142,9 +143,12 @@ struct environment {
find_path = "/usr/bin";
if ( const auto& path = llvm::sys::findProgramByName(prog.c_str(), {find_path}) ) {
std::vector<llvm::Optional<llvm::StringRef>> redirects;
if(stdin_file) {
redirects = { llvm::StringRef{*stdin_file}, llvm::None, llvm::None };
}
if(stdin_file || stdout_file)
redirects = { llvm::None, llvm::None, llvm::None };
if(stdin_file)
redirects[0] = llvm::StringRef{*stdin_file};
if(stdout_file)
redirects[1] = llvm::StringRef{*stdout_file};
return llvm::sys::ExecuteAndWait(*path, args, {}, redirects, 0, 0, nullptr, nullptr) == 0;
}
else
Expand Down

0 comments on commit f6ef88a

Please sign in to comment.