Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ set(CPPINTEROP_GIT_REPOSITORY "https://github.com/compiler-research/CppInterOp.g
set(CPPINTEROP_GIT_TAG "9802d61921ad5688ae42e4e628d754fc1192244d" CACHE STRING "")
set(CPPINTEROP_SOURCE_DIR "" CACHE PATH
"Override default CppInterOp built by ExternalProject_Add, with a path to local CppInterOp source")
set(CPPJIT_EXTRA_INTERPRETER_ARGS "" CACHE STRING
"Space-separated arguments passed at interpreter creation")

# The full Development component requires libpython, which manylinux
# images do not ship and extension modules do not need.
Expand Down Expand Up @@ -78,6 +80,20 @@ target_compile_definitions(cppjit PRIVATE
CPPJIT_CLANG_INCLUDE_DIR="${CPPJIT_INTEROP_CLANG_DIR}"
)

# The value lands in a string literal, so backslashes and quotes must survive
# the preprocessor; a ";" cannot be carried through CMake at all.
if(CPPJIT_EXTRA_INTERPRETER_ARGS)
if("${CPPJIT_EXTRA_INTERPRETER_ARGS}" MATCHES ";")
message(FATAL_ERROR
"CPPJIT_EXTRA_INTERPRETER_ARGS must not contain ';', CMake's list separator")
endif()
string(REPLACE "\\" "\\\\" _cppjit_extra_args "${CPPJIT_EXTRA_INTERPRETER_ARGS}")
string(REPLACE "\"" "\\\"" _cppjit_extra_args "${_cppjit_extra_args}")
target_compile_definitions(cppjit PRIVATE
CPPJIT_EXTRA_INTERPRETER_ARGS="${_cppjit_extra_args}"
)
endif()

target_include_directories(cppjit PRIVATE
# src/ itself resolves the public "cpyrt/*.h" spellings against the
# flattened src/cpyrt/ directory
Expand Down
19 changes: 16 additions & 3 deletions src/interop/interop_wrapper.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ static bool loadDispatchAPI(const InterOpPaths& Paths) {
return true;
}

// CppInterOp itself appends CPPINTEROP_EXTRA_INTERPRETER_ARGS inside
// CreateInterpreter, so nothing needs to be forwarded from here.
// CppInterOp appends the CPPINTEROP_EXTRA_INTERPRETER_ARGS environment
// variable itself, so only build-time arguments are forwarded from here.
static interop::TInterp_t
acquireOrCreateInterpreter(const InterOpPaths& Paths) {
if (auto existingInterp = Cpp::GetInterpreter())
Expand All @@ -154,6 +154,16 @@ acquireOrCreateInterpreter(const InterOpPaths& Paths) {
args.push_back("-resource-dir");
args.push_back(resourceDir.c_str());
}
#ifdef CPPJIT_EXTRA_INTERPRETER_ARGS
// Space-split like CppInterOp's CPPINTEROP_EXTRA_INTERPRETER_ARGS, which
// CreateInterpreter appends after these.
std::vector<std::string> bakedArgs;
std::istringstream bakedStream(CPPJIT_EXTRA_INTERPRETER_ARGS);
for (std::string arg; bakedStream >> arg;)
bakedArgs.push_back(arg);
for (const std::string& arg : bakedArgs)
args.push_back(arg.c_str());
#endif
return Cpp::CreateInterpreter(args, /*GpuArgs=*/{});
}

Expand Down Expand Up @@ -246,7 +256,10 @@ extern "C" int LoadCppInterOp() {
if (!loadDispatchAPI(Paths))
return;

acquireOrCreateInterpreter(Paths);
if (!acquireOrCreateInterpreter(Paths)) {
std::cerr << "[cppjit] Failed to create interpreter" << std::endl;
return;
}
configureInterpreter(Paths);
preloadHeaders();
defineRuntimeHelpers();
Expand Down
Loading