diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c3349d..e3bddea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,21 +1,14 @@ cmake_minimum_required(VERSION 3.16.3) -project (hipcc.bin) # Specify the C++ standard set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED True) -set (LINK_LIBS libstdc++fs.so) +project (hipcc.bin) add_executable(hipcc.bin src/hipBin.cpp) -if (NOT WIN32) # C++17 does not require the std lib linking - target_link_libraries(hipcc.bin ${LINK_LIBS} ) # for hipcc -endif() -project (hipconfig) +project (hipconfig.bin) add_executable(hipconfig.bin src/hipBin.cpp) -if (NOT WIN32) # C++17 does not require the std lib linking - target_link_libraries(hipconfig.bin ${LINK_LIBS} ) # for hipconfig -endif() # If not building as a standalone, put the binary in /bin if(DEFINED HIPCC_BUILD_PATH) diff --git a/src/hipBin_base.h b/src/hipBin_base.h index f5b3870..7cc3810 100644 --- a/src/hipBin_base.h +++ b/src/hipBin_base.h @@ -120,7 +120,8 @@ string RuntimeTypeStr(RuntimeType runtime) { enum OsType { lnx = 0, - windows + windows, + macos // add new OS types to be added here }; @@ -130,6 +131,8 @@ string OsTypeStr(OsType os) { return "linux"; case windows: return "windows"; + case macos: + return "macOS"; // add new OS types to be added here default: return "invalid OsType"; @@ -276,6 +279,8 @@ HipBinBase::HipBinBase() { void HipBinBase::readOSInfo() { #if defined _WIN32 || defined _WIN64 osInfo_ = windows; +#elif defined __APPLE__ || defined __MACOSX + osInfo_ = macos; #elif defined __unix || defined __linux__ osInfo_ = lnx; #endif @@ -389,8 +394,13 @@ void HipBinBase::getSystemInfo() const { system("wmic path win32_VideoController get AdapterCompatibility," "InstalledDisplayDrivers,Name | findstr /B /C:\"Advanced Micro Devices\""); } else { - assert(os == lnx); - cout << endl << "== Linux Kernel" << endl; + if (os == lnx) { + cout << endl << "== Linux Kernel" << endl; + } else if (os == macos) { + cout << endl << "== macOS Kernel" << endl; + } else { + assert(false); + } cout << "Hostname : " << std::flush; system("hostname"); system("uname -a"); diff --git a/src/hipBin_spirv.h b/src/hipBin_spirv.h index 8562712..76900a2 100644 --- a/src/hipBin_spirv.h +++ b/src/hipBin_spirv.h @@ -397,12 +397,13 @@ const string &HipBinSpirv::getCompilerPath() const { return hipClangPath_; } void HipBinSpirv::printCompilerInfo() const { const string &hipClangPath = getCompilerPath(); + fs::path hipLlvmPath = hipClangPath; cout << endl; - string cmd = hipClangPath + "/clang++ --version"; + string cmd = (hipLlvmPath / "clang++ --version").string(); system(cmd.c_str()); // hipclang version - cmd = hipClangPath + "/llc --version"; + cmd = (hipLlvmPath / "llc --version").string(); system(cmd.c_str()); // llc version cout << "hip-clang-cxxflags :" << endl; cout << hipInfo_.cxxflags << endl; @@ -449,7 +450,8 @@ string HipBinSpirv::getCppConfig() { return hipInfo_.cxxflags; } string HipBinSpirv::getDeviceLibPath() const { return ""; } bool HipBinSpirv::detectPlatform() { - if (getOSInfo() == windows) { + auto os = getOSInfo(); + if (os == windows) { return false; } @@ -467,8 +469,7 @@ bool HipBinSpirv::detectPlatform() { */ HipInfo hipInfo; - fs::path currentBinaryPath = fs::canonical("/proc/self/exe"); - currentBinaryPath = currentBinaryPath.parent_path(); + fs::path currentBinaryPath = hipBinUtilPtr_->getSelfPath(); fs::path sharePathBuild = currentBinaryPath.string() + "/../share"; fs::path sharePathInstall = var.hipPathEnv_.empty() ? "" : var.hipPathEnv_ + "/share"; diff --git a/src/hipBin_util.h b/src/hipBin_util.h index 42d74cc..2d5724e 100644 --- a/src/hipBin_util.h +++ b/src/hipBin_util.h @@ -100,6 +100,9 @@ namespace fs = std::filesystem; #include #include +#if defined(__APPLE__) || defined(__MACOSX) +#include +#endif #if defined(_WIN32) || defined(_WIN64) #include @@ -193,7 +196,7 @@ string HipBinUtil::mktempFile(string name) { return name; } -// gets the path of the executable name +// gets the directory path of the running executable string HipBinUtil::getSelfPath() const { int MAX_PATH_CHAR = 1024; int bufferSize = 0; @@ -206,17 +209,24 @@ string HipBinUtil::getSelfPath() const { path = string(wide.begin(), wide.end()); #else char buff[MAX_PATH_CHAR]; - ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff) - 1); - if (len > 0) { - buff[len] = '\0'; - path = string(buff); - fs::path exePath(path); - path = exePath.parent_path().string(); - } else { - cout << "readlink: Error reading the exe path" << endl; - perror("readlink"); - exit(-1); - } + #if defined(__APPLE__) || defined(__MACOSX) + uint32_t len = sizeof(buff) - 1; + if(_NSGetExecutablePath(buff, &len) || len <= 0) { + cout << "hipcc: Error reading the exe path" << endl; + exit(-1); + } + #else + ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff) - 1); + if (len <= 0) { + cout << "hipcc: Error reading the exe path" << endl; + perror("readlink"); + exit(-1); + } + #endif + buff[len] = '\0'; + path = string(buff); + fs::path exePath(path); + path = exePath.remove_filename().string(); #endif return path; }