Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
vgvassilev committed Mar 18, 2024
1 parent a3d57ca commit ff21632
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 14 deletions.
1 change: 1 addition & 0 deletions recipe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ message(STATUS " libraries: ${CPPINTEROP_LIBRARIES}")
message(STATUS " include path: ${CppInterOp_INCLUDE_DIRS}")
add_executable(cmake_build_test test.cpp)
target_link_libraries(cmake_build_test LINK_PRIVATE clangCppInterOp)
add_compile_definitions(cmake_build_test PUBLIC CONDA_PREFIX="${CONDA_PREFIX}")
11 changes: 5 additions & 6 deletions recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,14 @@ test:
- test -f $PREFIX/lib/libclangCppInterOp${SHLIB_EXT} # [unix]
- if not exist %LIBRARY_BIN%\\clangCppInterOp.dll exit 1 # [win]
- mkdir -p cmake_build_test && pushd cmake_build_test
- cmake -G "Ninja" .. --trace-expand
- cmake --build . --config Debug
- CPPINTEROP_EXTRA_INTERPRETER_ARGS="-mllvm -debug-only=exec" ./cmake_build_test # [unix]
- ./cmake_build_test # [win]
- cmake -DCMAKE_BUILD_TYPE=Debug -DCONDA_PREFIX="$PREFIX" -G "Ninja" .. --trace-expand
- cmake --build . --config Debug -- -v
- ./cmake_build_test
- rm -fr *
- cmake -DCMAKE_BUILD_TYPE=Release -DCONDA_PREFIX="$PREFIX" -G "Ninja" ..
- cmake --build . --config Release && ./cmake_build_test
- rm -fr *
- cmake -G "Ninja" ..
- cmake -G "Ninja" ..
- cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCONDA_PREFIX="$PREFIX" -G "Ninja" ..
- cmake --build . --config RelWithDebInfo && ./cmake_build_test
- popd

Expand Down
54 changes: 46 additions & 8 deletions recipe/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,70 @@

#include <algorithm>
#include <iostream>
#include <string>
#include <sys/stat.h>

using Args = std::vector<const char*>;
inline bool file_exists(const std::string& name) {
struct stat buffer;
return (stat (name.c_str(), &buffer) == 0);
}

inline std::string append_path(const std::string &to, const std::string& what) {
#if defined(WIN32)
# define DIR_SEPARATOR '\\'
#else
# define DIR_SEPARATOR '/'
#endif
return to + DIR_SEPARATOR + what;
}

using Args = std::vector<std::string>;

void* createInterpreter(const Args &ExtraArgs = {}) {
Args ClangArgs = {"-v"};
Args ClangArgs;
if (std::find(ExtraArgs.begin(), ExtraArgs.end(), "-resource-dir") != ExtraArgs.end()) {
std::string resource_dir = Cpp::DetectResourceDir();
if (resource_dir == "")
std::cerr << "Failed to detect the resource-dir\n";
ClangArgs.push_back("-resource-dir");
ClangArgs.push_back(resource_dir.c_str());
ClangArgs.push_back(resource_dir);
}
std::vector<std::string> CxxSystemIncludes;
const char* DefaultCxxName = "x86_64-conda-linux-gnu-g++";
const char* DefaultCxxName = "c++";
// Oddly, conda supports "pseudo cross-compilation" and gives us the compiler
// include paths relative to the compiler binary. Now we need to find out
// where that binary is...
const char* Prefix = CONDA_PREFIX;
Cpp::DetectSystemCompilerIncludePaths(CxxSystemIncludes, DefaultCxxName);
for (const std::string& CxxInclude : CxxSystemIncludes) {
for (std::string CxxInclude : CxxSystemIncludes) {
if (!file_exists(CxxInclude)) {
// Try make these paths absolute.
std::string FullPath = append_path(Prefix, CxxInclude);
if (!file_exists(FullPath)) {
std::cerr << "'" << CxxInclude << "'" << " not found, neither is '"
<< FullPath << "'\n";
continue;
}
CxxInclude = FullPath;
}
ClangArgs.push_back("-isystem");
ClangArgs.push_back(CxxInclude.c_str());
ClangArgs.push_back(CxxInclude);
}
ClangArgs.insert(ClangArgs.end(), ExtraArgs.begin(), ExtraArgs.end());
// FIXME: We should process the kernel input options and conditionally pass
// the gpu args here.
return Cpp::CreateInterpreter(ClangArgs/*, {"-cuda"}*/);
std::vector<const char*> Args(ClangArgs.size());

std::transform(ClangArgs.begin(), ClangArgs.end(), Args.begin(),
[](const std::string &s) -> const char * { return s.data(); });

for (const char* arg : Args)
std::cout << arg << "\n";

return Cpp::CreateInterpreter(Args/*, {"-cuda"}*/);
}

int main() {
createInterpreter();
createInterpreter({"-v"});
return Cpp::Process("#include <string>");
}

0 comments on commit ff21632

Please sign in to comment.