From 7846f4602ee268124a6803deca0f5772d67976d0 Mon Sep 17 00:00:00 2001 From: Reuben Morais Date: Wed, 21 Jul 2021 11:30:23 +0200 Subject: [PATCH] Export needed KenLM symbols manually for Windows --- native_client/BUILD | 2 +- native_client/kenlm/lm/binary_format.hh | 2 +- native_client/kenlm/lm/config.hh | 8 +++++++- native_client/kenlm/lm/model.hh | 2 +- native_client/kenlm/util/file.hh | 13 ++++++++++--- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/native_client/BUILD b/native_client/BUILD index cd6881dd..1f35bd6c 100644 --- a/native_client/BUILD +++ b/native_client/BUILD @@ -78,7 +78,7 @@ tf_cc_shared_object( "-std=c++11" ] + select({ "//tensorflow:windows": [], - "//conditions:default": ["-fvisibility=default"], + "//conditions:default": ["-fvisibility=hidden"], }), defines = ["KENLM_MAX_ORDER=6"], includes = ["kenlm"], diff --git a/native_client/kenlm/lm/binary_format.hh b/native_client/kenlm/lm/binary_format.hh index ff99b957..b0815bad 100644 --- a/native_client/kenlm/lm/binary_format.hh +++ b/native_client/kenlm/lm/binary_format.hh @@ -23,7 +23,7 @@ extern const char *kModelNames[6]; * If so, return true and set recognized to the type. This is the only API in * this header designed for use by decoder authors. */ -bool RecognizeBinary(const char *file, ModelType &recognized); +KENLM_EXPORT bool RecognizeBinary(const char *file, ModelType &recognized); struct FixedWidthParameters { unsigned char order; diff --git a/native_client/kenlm/lm/config.hh b/native_client/kenlm/lm/config.hh index 21b9e7ee..05a4db93 100644 --- a/native_client/kenlm/lm/config.hh +++ b/native_client/kenlm/lm/config.hh @@ -10,13 +10,19 @@ /* Configuration for ngram model. Separate header to reduce pollution. */ +#if defined _MSC_VER + #define KENLM_EXPORT __declspec(dllexport) +#else + #define KENLM_EXPORT __attribute__ ((visibility("default"))) +#endif /* _MSC_VER */ + namespace lm { class EnumerateVocab; namespace ngram { -struct Config { +struct KENLM_EXPORT Config { // EFFECTIVE FOR BOTH ARPA AND BINARY READS // (default true) print progress bar to messages diff --git a/native_client/kenlm/lm/model.hh b/native_client/kenlm/lm/model.hh index 9b7206e8..060e5f2c 100644 --- a/native_client/kenlm/lm/model.hh +++ b/native_client/kenlm/lm/model.hh @@ -149,7 +149,7 @@ typedef ProbingModel Model; /* Autorecognize the file type, load, and return the virtual base class. Don't * use the virtual base class if you can avoid it. Instead, use the above * classes as template arguments to your own virtual feature function.*/ -base::Model *LoadVirtual(const char *file_name, const Config &config = Config(), ModelType if_arpa = PROBING); +KENLM_EXPORT base::Model *LoadVirtual(const char *file_name, const Config &config = Config(), ModelType if_arpa = PROBING); } // namespace ngram } // namespace lm diff --git a/native_client/kenlm/util/file.hh b/native_client/kenlm/util/file.hh index 4a50e730..22146190 100644 --- a/native_client/kenlm/util/file.hh +++ b/native_client/kenlm/util/file.hh @@ -10,9 +10,16 @@ #include #include +#if defined _MSC_VER + #define KENLM_EXPORT __declspec(dllexport) +#else + #define KENLM_EXPORT __attribute__ ((visibility("default"))) +#endif /* _MSC_VER */ + + namespace util { -class scoped_fd { +class KENLM_EXPORT scoped_fd { public: scoped_fd() : fd_(-1) {} @@ -82,7 +89,7 @@ class EndOfFileException : public Exception { class UnsupportedOSException : public Exception {}; // Open for read only. -int OpenReadOrThrow(const char *name); +KENLM_EXPORT int OpenReadOrThrow(const char *name); // Create file if it doesn't exist, truncate if it does. Opened for write. int CreateOrThrow(const char *name); @@ -110,7 +117,7 @@ bool OutputPathIsStdout(StringPiece path); // Return value for SizeFile when it can't size properly. const uint64_t kBadSize = (uint64_t)-1; -uint64_t SizeFile(int fd); +KENLM_EXPORT uint64_t SizeFile(int fd); uint64_t SizeOrThrow(int fd); void ResizeOrThrow(int fd, uint64_t to);