Skip to content

Instantly share code, notes, and snippets.

@andreypopp
Created March 24, 2023 09:58
Show Gist options
  • Save andreypopp/8b4d058adb6773b8e3817d25d2f1eb3f to your computer and use it in GitHub Desktop.
Save andreypopp/8b4d058adb6773b8e3817d25d2f1eb3f to your computer and use it in GitHub Desktop.
diff --git a/backend/icu/dune b/backend/icu/dune
index cb85abd8576..2a40819420c 100644
--- a/backend/icu/dune
+++ b/backend/icu/dune
@@ -26,7 +26,7 @@
./c_ctypes_cflags)
(action
(bash
- "cc -I \"$(ocamlfind query ctypes)\" -I \"$(ocamlc -where)\" $(cat ./c_ctypes_cflags) -o icu_gen_types_ocaml icu_types.cxx")))
+ "cc -I \"$(ocamlfind query ctypes)\" -I \"$(ocamlc -where)\" $(cat ./c_ctypes_cflags) --std=c++11 -o icu_gen_types_ocaml icu_types.cxx")))
(rule
(targets icu_types_generated.ml)
@@ -53,7 +53,7 @@
(libraries ctypes.stubs icu_stubs))
(rule
- (targets icu_generated.ml icu_cstubs.cxx)
+ (targets icu_generated.ml icu_cstubs.c)
(deps
(:gen icu_gen_stubs.exe)
icu_stubs.ml)
@@ -75,12 +75,20 @@
(modules icu icu_generated)
(private_modules icu_generated)
(libraries ctypes.stubs icu_stubs integers)
+ (foreign_stubs
+ (language c)
+ (names icu_cstubs)
+ (flags
+ (:standard
+ -fpermissive
+ (:include c_flags.sexp))))
(foreign_stubs
(language cxx)
- (names icu_cstubs icu_wrappers)
+ (names icu_wrappers)
(flags
(:standard
-fpermissive
+ --std=c++11
(:include c_flags.sexp))))
(c_library_flags
(:standard
diff --git a/backend/icu/icu_gen_stubs.ml b/backend/icu/icu_gen_stubs.ml
index f599a5c58e8..b006af9e9cd 100644
--- a/backend/icu/icu_gen_stubs.ml
+++ b/backend/icu/icu_gen_stubs.ml
@@ -11,22 +11,7 @@ let () =
let c_fmt = Format.formatter_of_out_channel c_out in
List.iter (fun c_header -> Format.fprintf c_fmt "#include <%s>@\n" c_header) c_headers;
List.iter (fun c_header -> Format.fprintf c_fmt "#include \"%s\"@\n" c_header) local_c_headers;
- (* because we compile in c++ mode the generated code won't be visible if not wrapped with [extern "C"] *)
- Format.fprintf c_fmt
- {|
-#ifdef __clang__
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Werror"
-#endif
-|};
- Format.fprintf c_fmt "extern \"C\" {@\n";
Cstubs.write_c c_fmt ~prefix:"icu_stub_" (module Icu_stubs.Bindings);
- Format.fprintf c_fmt "}";
- Format.fprintf c_fmt {|
-#ifdef __clang__
-#pragma clang diagnostic pop
-#endif
-|};
Format.pp_print_flush c_fmt ();
close_out c_out;
diff --git a/backend/icu/icu_wrappers.h b/backend/icu/icu_wrappers.h
index 038fb9e037f..6ba73eb97b3 100644
--- a/backend/icu/icu_wrappers.h
+++ b/backend/icu/icu_wrappers.h
@@ -1,6 +1,9 @@
-extern "C"
-{
+#ifdef __cplusplus
+extern "C" {
+#endif
void* create_transliterator_instance();
void delete_transliterator(void *);
int full_normalize(void *transliterator, const char *src, int src_len, char *dest, int dest_len);
+#ifdef __cplusplus
}
+#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment