Skip to content

Commit 1697d83

Browse files
committed
Use optional bindings for unsupported symbols
1 parent 0782b24 commit 1697d83

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

lib/ffi.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,12 @@ let libclang: ReturnType<
3838
>;
3939

4040
if (Deno.build.os === "windows") {
41-
/**
42-
* Windows DLL does not have error handler related symbols.
43-
* Windows DLL from `choco install --version 14.0.6 llvm`
44-
* md5 59beb52cef40898b0f24cdffc6cf2984
45-
* `dumpbin /exports libclang.dll`
46-
*/
47-
const IMPORTS_WIN = Object.fromEntries(
48-
Object.entries(IMPORTS).filter(([symbol]: [string, unknown]) =>
49-
symbol !== "clang_install_aborting_llvm_fatal_error_handler" &&
50-
symbol !== "clang_uninstall_llvm_fatal_error_handler"
51-
),
52-
) as ClangSymbols;
53-
5441
if (libclangPath.includes(".dll")) {
55-
libclang = Deno.dlopen(libclangPath, IMPORTS_WIN);
42+
libclang = Deno.dlopen(libclangPath, IMPORTS);
5643
} else {
5744
libclang = Deno.dlopen(
5845
join(libclangPath, "libclang.dll"),
59-
IMPORTS_WIN,
46+
IMPORTS,
6047
);
6148
}
6249
} else if (Deno.build.os === "darwin") {

lib/include/FatalErrorHandler.h.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
export const clang_install_aborting_llvm_fatal_error_handler = {
66
parameters: [],
77
result: "void",
8+
optional: true,
89
} as const;
910

1011
/**
@@ -15,4 +16,5 @@ export const clang_install_aborting_llvm_fatal_error_handler = {
1516
export const clang_uninstall_llvm_fatal_error_handler = {
1617
parameters: [],
1718
result: "void",
19+
optional: true,
1820
} as const;

lib/mod.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,21 @@ export const setAbortOnFatalError = (
219219
throw new Error("'setAbortOnFatalError' API is not supported on Windows");
220220
}
221221
if (value) {
222-
libclang.symbols.clang_install_aborting_llvm_fatal_error_handler();
222+
const fn = libclang.symbols.clang_install_aborting_llvm_fatal_error_handler;
223+
if (typeof fn !== "function") {
224+
throw new Error(
225+
`${getClangVersion()} does not contain symbol 'clang_install_aborting_llvm_fatal_error_handler'`,
226+
);
227+
}
228+
fn();
223229
} else {
224-
libclang.symbols.clang_uninstall_llvm_fatal_error_handler();
230+
const fn = libclang.symbols.clang_uninstall_llvm_fatal_error_handler;
231+
if (typeof fn !== "function") {
232+
throw new Error(
233+
`${getClangVersion()} does not contain symbol 'clang_uninstall_llvm_fatal_error_handler'`,
234+
);
235+
}
236+
fn();
225237
}
226238
};
227239

0 commit comments

Comments
 (0)