Skip to content

Commit 94b671f

Browse files
author
kr-2003
committed
addressing issues
1 parent fda48a4 commit 94b671f

File tree

7 files changed

+61
-26
lines changed

7 files changed

+61
-26
lines changed

CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ include(GNUInstallDirs)
7979

8080
## Set Cmake packages search order
8181

82-
8382
set(CMAKE_FIND_PACKAGE_SORT_ORDER NATURAL)
8483
set(CMAKE_FIND_PACKAGE_SORT_DIRECTION DEC)
8584

@@ -303,7 +302,12 @@ string(REGEX REPLACE "/build/lib/cmake/llvm$" "" LLVM_SOURCE_DIR "${LLVM_DIR}")
303302
add_definitions(-DLLVM_SOURCE_DIR="${LLVM_SOURCE_DIR}")
304303

305304
if(LLVM_BUILT_WITH_OOP_JIT)
306-
add_definitions(-DLLVM_BUILT_WITH_OOP_JIT)
305+
if((CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm64") OR
306+
(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64"))
307+
add_definitions(-DLLVM_BUILT_WITH_OOP_JIT)
308+
else()
309+
message(FATAL_ERROR "LLVM_BUILT_WITH_OOP_JIT is only supported on Darwin arm64 or Linux x86_64. Build aborted.")
310+
endif()
307311
endif()
308312

309313
# If the llvm sources are present add them with higher priority.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ cd ..\
163163
##### Build Clang-REPL with Out-of-Process JIT Execution
164164

165165
To have ``Out-of-Process JIT Execution`` enabled, run following commands to build clang and clang-repl to support this feature:
166-
> Only for Linux and Macos
166+
> Only for Linux x86_64 and Macos amr64
167167
```bash
168168
mkdir build
169169
cd build
@@ -177,9 +177,9 @@ cmake -DLLVM_ENABLE_PROJECTS="clang;compiler-rt" \
177177
-DCLANG_ENABLE_BOOTSTRAP=OFF \
178178
../llvm
179179

180-
## For Linux
180+
## For Linux x86_64
181181
cmake --build . --target clang clang-repl llvm-jitlink-executor orc_rt-x86_64 --parallel $(nproc --all)
182-
## For MacOS
182+
## For MacOS arm64
183183
cmake --build . --target clang clang-repl llvm-jitlink-executor orc_rt_osx --parallel $(sysctl -n hw.ncpu)
184184

185185
#### Build Cling and related dependencies

docs/InstallationAndUsage.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ To have `Out-of-Process JIT Execution` enabled, run following commands to build
107107

108108
.. note::
109109

110-
Only for Linux and Macos
110+
Only for Linux x86_64 and Macos arm64
111111

112112
.. code:: bash
113113
@@ -123,10 +123,10 @@ To have `Out-of-Process JIT Execution` enabled, run following commands to build
123123
-DCLANG_ENABLE_BOOTSTRAP=OFF \
124124
../llvm
125125
126-
# For Linux
126+
# For Linux x86_64
127127
cmake --build . --target clang clang-repl llvm-jitlink-executor orc_rt-x86_64 --parallel $(nproc --all)
128128
129-
# For MacOS
129+
# For MacOS arm64
130130
cmake --build . --target clang clang-repl llvm-jitlink-executor orc_rt_osx --parallel $(sysctl -n hw.ncpu)
131131
132132
**************************************

include/CppInterOp/CppInterOp.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,10 @@ CPPINTEROP_API int Undo(unsigned N = 1);
912912
/// Returns the process ID of the executor process.
913913
/// \returns the PID of the executor process.
914914
CPPINTEROP_API pid_t GetExecutorPID();
915+
916+
/// Returns the process ID of the nth executor process.
917+
/// \returns the PID of the nth executor process.
918+
CPPINTEROP_API pid_t GetNthExecutorPID(int n);
915919
#endif
916920

917921
} // end namespace Cpp

lib/CppInterOp/Compatibility.h

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -272,26 +272,23 @@ createClangInterpreter(std::vector<const char*>& args, int stdin_fd = 0,
272272
std::string SlabAllocateSizeString = "";
273273
std::unique_ptr<llvm::orc::ExecutorProcessControl> EPC;
274274

275-
auto DefaultForkRedirection = [=] {
276-
auto redirect = [](int from, int to) {
277-
if (from != to) {
278-
dup2(from, to);
279-
close(from);
280-
}
281-
};
282-
283-
// TODO: stdin and stderr redirection is not necessary.
284-
redirect(0, STDIN_FILENO);
285-
redirect(stdout_fd, STDOUT_FILENO);
286-
redirect(2, STDERR_FILENO);
287-
288-
setvbuf(stdout, nullptr, _IONBF, 0);
289-
setvbuf(stderr, nullptr, _IONBF, 0);
290-
};
291-
292275
EPC = ExitOnError(launchExecutor(OOPExecutor, UseSharedMemory,
293276
SlabAllocateSizeString,
294-
DefaultForkRedirection));
277+
[=] { // Lambda defined inline
278+
auto redirect = [](int from, int to) {
279+
if (from != to) {
280+
dup2(from, to);
281+
close(from);
282+
}
283+
};
284+
285+
redirect(0, STDIN_FILENO);
286+
redirect(stdout_fd, STDOUT_FILENO);
287+
redirect(2, STDERR_FILENO);
288+
289+
setvbuf(stdout, nullptr, _IONBF, 0);
290+
setvbuf(stderr, nullptr, _IONBF, 0);
291+
}));
295292

296293
#ifdef __APPLE__
297294
std::string OrcRuntimePath =

lib/CppInterOp/CppInterOp.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3969,6 +3969,13 @@ pid_t GetExecutorPID() {
39693969
#endif
39703970
return -1;
39713971
}
3972+
3973+
pid_t GetNthExecutorPID(int n) {
3974+
#ifdef LLVM_BUILT_WITH_OOP_JIT
3975+
return compat::getNthExecutorPID(n);
3976+
#endif
3977+
return -1;
3978+
}
39723979
#endif
39733980

39743981
} // end namespace Cpp

unittests/CppInterOp/FunctionReflectionTest.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,3 +2579,26 @@ TEST(FunctionReflectionTest, FailingTest1) {
25792579
EXPECT_FALSE(Cpp::Declare("int x = 1;"));
25802580
EXPECT_FALSE(Cpp::Declare("int y = x;"));
25812581
}
2582+
2583+
TEST(FunctionReflectionTest, GetExecutorPIDTest) {
2584+
#ifdef _WIN32
2585+
GTEST_SKIP() << "Disabled on Windows. Needs fixing.";
2586+
#endif
2587+
#ifdef EMSCRIPTEN
2588+
GTEST_SKIP() << "Test fails for Emscipten builds";
2589+
#endif
2590+
TestUtils::CreateInterpreter();
2591+
pid_t pid = Cpp::GetExecutorPID();
2592+
if (TestUtils::use_oop_jit()) {
2593+
EXPECT_NE(pid, -1);
2594+
} else {
2595+
EXPECT_EQ(pid, -1);
2596+
}
2597+
2598+
pid = Cpp::GetNthExecutorPID(1);
2599+
if (TestUtils::use_oop_jit()) {
2600+
EXPECT_NE(pid, -1);
2601+
} else {
2602+
EXPECT_EQ(pid, -1);
2603+
}
2604+
}

0 commit comments

Comments
 (0)