Skip to content

Commit b6a1c08

Browse files
authored
Enable exception handling in xeus-cpp deployment (#686)
1 parent 515c1c8 commit b6a1c08

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

.github/workflows/emscripten.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ jobs:
318318
elseif ( "${{ matrix.clang-runtime }}" -imatch "20" )
319319
{
320320
git apply -v emscripten-clang20-2-shift-temporary-files-to-tmp-dir.patch
321+
git apply -v emscripten-clang20-3-enable_exception_handling.patch
321322
}
322323
cd build
323324
echo "Apply clang${{ matrix.clang-runtime }}-*.patch patches:"

Emscripten-build-instructions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ On Windows execute the following
6464
cd .\llvm-project\
6565
cp -r ..\patches\llvm\emscripten-clang20*
6666
git apply -v emscripten-clang20-2-shift-temporary-files-to-tmp-dir.patch
67+
git apply -v emscripten-clang20-3-enable_exception_handling.patch
6768
```
6869

6970
We are now in a position to build an emscripten build of llvm by executing the following on Linux

docs/Emscripten-build-instructions.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ On Windows execute the following
8383
cd .\llvm-project\
8484
cp -r ..\patches\llvm\emscripten-clang20*
8585
git apply -v emscripten-clang20-2-shift-temporary-files-to-tmp-dir.patch
86+
git apply -v emscripten-clang20-3-enable_exception_handling.patch
8687
8788
We are now in a position to build an emscripten build of llvm by executing the following on Linux
8889
and osx
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
2+
index 3b81f9d70..2704edb8a 100644
3+
--- a/clang/lib/Interpreter/Interpreter.cpp
4+
+++ b/clang/lib/Interpreter/Interpreter.cpp
5+
@@ -142,6 +142,48 @@ CreateCI(const llvm::opt::ArgStringList &Argv) {
6+
return std::move(Clang);
7+
}
8+
9+
+static llvm::Error HandleFrontendOptions(const CompilerInstance &CI) {
10+
+ const auto &FrontendOpts = CI.getFrontendOpts();
11+
+
12+
+ if (FrontendOpts.ShowHelp) {
13+
+ driver::getDriverOptTable().printHelp(
14+
+ llvm::outs(), "clang -cc1 [options] file...",
15+
+ "LLVM 'Clang' Compiler: http://clang.llvm.org",
16+
+ /*ShowHidden=*/false, /*ShowAllAliases=*/false,
17+
+ llvm::opt::Visibility(driver::options::CC1Option));
18+
+ return llvm::createStringError(llvm::errc::not_supported, "Help displayed");
19+
+ }
20+
+
21+
+ if (FrontendOpts.ShowVersion) {
22+
+ llvm::cl::PrintVersionMessage();
23+
+ return llvm::createStringError(llvm::errc::not_supported,
24+
+ "Version displayed");
25+
+ }
26+
+
27+
+ if (!FrontendOpts.LLVMArgs.empty()) {
28+
+ unsigned NumArgs = FrontendOpts.LLVMArgs.size();
29+
+ auto Args = std::make_unique<const char *[]>(NumArgs + 2);
30+
+ Args[0] = "clang-repl (LLVM option parsing)";
31+
+ for (unsigned i = 0; i != NumArgs; ++i) {
32+
+ Args[i + 1] = FrontendOpts.LLVMArgs[i].c_str();
33+
+ // remove the leading '-' from the option name
34+
+ if (Args[i + 1][0] == '-') {
35+
+ auto *option = static_cast<llvm::cl::opt<bool> *>(
36+
+ llvm::cl::getRegisteredOptions()[Args[i + 1] + 1]);
37+
+ if (option) {
38+
+ option->setInitialValue(true);
39+
+ } else {
40+
+ llvm::errs() << "Unknown LLVM option: " << Args[i + 1] << "\n";
41+
+ }
42+
+ }
43+
+ }
44+
+ Args[NumArgs + 1] = nullptr;
45+
+ llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get());
46+
+ }
47+
+
48+
+ return llvm::Error::success();
49+
+}
50+
+
51+
} // anonymous namespace
52+
53+
namespace clang {
54+
@@ -456,7 +498,12 @@ const char *const Runtimes = R"(
55+
56+
llvm::Expected<std::unique_ptr<Interpreter>>
57+
Interpreter::create(std::unique_ptr<CompilerInstance> CI) {
58+
- llvm::Error Err = llvm::Error::success();
59+
+
60+
+ llvm::Error Err = HandleFrontendOptions(*CI);
61+
+ if (Err) {
62+
+ return std::move(Err);
63+
+ }
64+
+
65+
auto Interp =
66+
std::unique_ptr<Interpreter>(new Interpreter(std::move(CI), Err));
67+
if (Err)

0 commit comments

Comments
 (0)