Skip to content

Commit 22e2ba0

Browse files
jacobkahnfacebook-github-bot
authored andcommitted
Explicitly export library symbols (#70)
Summary: Explicitly export symbols with visibility to avoid using the bad `WINDOWS_EXPORT_ALL_SYMBOLS` option. Pull Request resolved: #70 Test Plan: CI, local test ### Checklist - [x] Test coverage - [x] Tests pass - [x] Code formatted - [x] Rebased on latest matter - [x] Code documented Reviewed By: mthrok Differential Revision: D46530422 Pulled By: jacobkahn fbshipit-source-id: cb730f09024c9760dc00b35e184185be0cf60922
1 parent 4994f11 commit 22e2ba0

21 files changed

Lines changed: 98 additions & 38 deletions

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,8 @@ wheels/
5252
*.exe
5353
*.out
5454
*.app
55+
56+
# Dev environment
57+
.vscode
58+
.vs
59+
CMakeSettings.json

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ target_compile_definitions(
5656
flashlight-text
5757
PUBLIC
5858
FL_TEXT_USE_KENLM=$<BOOL:${FL_TEXT_USE_KENLM}>
59+
FL_TEXT_DLL
5960
)
6061

6162

flashlight/lib/text/Defines.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT-style license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
#if defined(_WIN32) || defined(_MSC_VER)
11+
12+
#ifdef FL_TEXT_DLL
13+
#define FL_TEXT_API __declspec(dllexport)
14+
#else // FL_TEXT_DLL
15+
#define FL_TEXT_API __declspec(dllimport)
16+
#endif // FL_TEXT_DLL
17+
18+
#else // defined(_WIN32) || defined(_MSC_VER)
19+
20+
#define FL_TEXT_API __attribute__((visibility("default")))
21+
#define FL_DEPRECATED(msg) __attribute__((deprecated(msg)))
22+
23+
#endif // defined(_WIN32) || defined(_MSC_VER)

flashlight/lib/text/String.h

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include <unordered_map>
1818
#include <vector>
1919

20+
#include "flashlight/lib/text/Defines.h"
21+
2022
namespace fl {
2123
namespace lib {
2224

@@ -32,37 +34,39 @@ using EnableIfSame = typename std::enable_if<std::is_same<S, T>::value>::type;
3234
// ================================== Functions
3335
// ==================================
3436

35-
std::string trim(const std::string& str);
37+
FL_TEXT_API std::string trim(const std::string& str);
3638

37-
void replaceAll(
38-
std::string& str,
39-
const std::string& from,
40-
const std::string& repl);
39+
FL_TEXT_API void
40+
replaceAll(std::string& str, const std::string& from, const std::string& repl);
4141

42-
bool startsWith(const std::string& input, const std::string& pattern);
43-
bool endsWith(const std::string& input, const std::string& pattern);
42+
FL_TEXT_API bool startsWith(
43+
const std::string& input,
44+
const std::string& pattern);
45+
FL_TEXT_API bool endsWith(const std::string& input, const std::string& pattern);
4446

45-
std::vector<std::string>
47+
FL_TEXT_API std::vector<std::string>
4648
split(char delim, const std::string& input, bool ignoreEmpty = false);
4749

48-
std::vector<std::string> split(
50+
FL_TEXT_API std::vector<std::string> split(
4951
const std::string& delim,
5052
const std::string& input,
5153
bool ignoreEmpty = false);
5254

53-
std::vector<std::string> splitOnAnyOf(
55+
FL_TEXT_API std::vector<std::string> splitOnAnyOf(
5456
const std::string& delim,
5557
const std::string& input,
5658
bool ignoreEmpty = false);
5759

58-
std::vector<std::string> splitOnWhitespace(
60+
FL_TEXT_API std::vector<std::string> splitOnWhitespace(
5961
const std::string& input,
6062
bool ignoreEmpty = false);
6163

6264
/**
6365
* Join a vector of `std::string` inserting `delim` in between.
6466
*/
65-
std::string join(const std::string& delim, const std::vector<std::string>& vec);
67+
FL_TEXT_API std::string join(
68+
const std::string& delim,
69+
const std::vector<std::string>& vec);
6670

6771
/**
6872
* Join a range of `std::string` specified by iterators.
@@ -126,5 +130,6 @@ void dedup(std::vector<T>& in) {
126130
auto it = std::unique(in.begin(), in.end());
127131
in.resize(std::distance(in.begin(), it));
128132
}
133+
129134
} // namespace lib
130135
} // namespace fl

flashlight/lib/text/decoder/Decoder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class Decoder {
7272
/* Get all the final hypothesis */
7373
virtual std::vector<DecodeResult> getAllFinalHypothesis() const = 0;
7474
};
75+
7576
} // namespace text
7677
} // namespace lib
7778
} // namespace fl

flashlight/lib/text/decoder/LexiconDecoder.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <unordered_map>
1111

12+
#include "flashlight/lib/text/Defines.h"
1213
#include "flashlight/lib/text/decoder/Decoder.h"
1314
#include "flashlight/lib/text/decoder/Trie.h"
1415
#include "flashlight/lib/text/decoder/lm/LM.h"
@@ -111,7 +112,7 @@ struct LexiconDecoderState {
111112
* search space and all candidate words are generated from it if unkScore is
112113
* -inf, otherwise <UNK> will be generated for OOVs.
113114
*/
114-
class LexiconDecoder : public Decoder {
115+
class FL_TEXT_API LexiconDecoder : public Decoder {
115116
public:
116117
LexiconDecoder(
117118
LexiconDecoderOptions opt,
@@ -182,6 +183,7 @@ class LexiconDecoder : public Decoder {
182183
int nDecodedFrames_; // Total number of decoded frames.
183184
int nPrunedFrames_; // Total number of pruned frames from hyp_.
184185
};
186+
185187
} // namespace text
186188
} // namespace lib
187189
} // namespace fl

flashlight/lib/text/decoder/LexiconFreeDecoder.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <unordered_map>
1111

12+
#include "flashlight/lib/text/Defines.h"
1213
#include "flashlight/lib/text/decoder/Decoder.h"
1314
#include "flashlight/lib/text/decoder/lm/LM.h"
1415

@@ -96,7 +97,7 @@ struct LexiconFreeDecoderState {
9697
* score of the transcription W. We are allowed to generate words from all the
9798
* possible combination of tokens.
9899
*/
99-
class LexiconFreeDecoder : public Decoder {
100+
class FL_TEXT_API LexiconFreeDecoder : public Decoder {
100101
public:
101102
LexiconFreeDecoder(
102103
LexiconFreeDecoderOptions opt,
@@ -165,6 +166,7 @@ class LexiconFreeDecoder : public Decoder {
165166
int nDecodedFrames_; // Total number of decoded frames.
166167
int nPrunedFrames_; // Total number of pruned frames from hyp_.
167168
};
169+
168170
} // namespace text
169171
} // namespace lib
170172
} // namespace fl

flashlight/lib/text/decoder/LexiconFreeSeq2SeqDecoder.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <optional>
1212
#include <unordered_map>
1313

14+
#include "flashlight/lib/text/Defines.h"
1415
#include "flashlight/lib/text/decoder/Decoder.h"
1516
#include "flashlight/lib/text/decoder/Utils.h"
1617
#include "flashlight/lib/text/decoder/lm/LM.h"
@@ -93,7 +94,7 @@ struct LexiconFreeSeq2SeqDecoderState {
9394
* TODO: Doesn't support online decoding now.
9495
*
9596
*/
96-
class LexiconFreeSeq2SeqDecoder : public Decoder {
97+
class FL_TEXT_API LexiconFreeSeq2SeqDecoder : public Decoder {
9798
public:
9899
LexiconFreeSeq2SeqDecoder(
99100
LexiconFreeSeq2SeqDecoderOptions opt,
@@ -136,6 +137,7 @@ class LexiconFreeSeq2SeqDecoder : public Decoder {
136137

137138
std::unordered_map<int, std::vector<LexiconFreeSeq2SeqDecoderState>> hyp_;
138139
};
140+
139141
} // namespace text
140142
} // namespace lib
141143
} // namespace fl

flashlight/lib/text/decoder/LexiconSeq2SeqDecoder.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <optional>
1212
#include <unordered_map>
1313

14+
#include "flashlight/lib/text/Defines.h"
1415
#include "flashlight/lib/text/decoder/Decoder.h"
1516
#include "flashlight/lib/text/decoder/Trie.h"
1617
#include "flashlight/lib/text/decoder/Utils.h"
@@ -111,7 +112,7 @@ struct LexiconSeq2SeqDecoderState {
111112
* TODO: Doesn't support online decoding now.
112113
*
113114
*/
114-
class LexiconSeq2SeqDecoder : public Decoder {
115+
class FL_TEXT_API LexiconSeq2SeqDecoder : public Decoder {
115116
public:
116117
LexiconSeq2SeqDecoder(
117118
LexiconSeq2SeqDecoderOptions opt,
@@ -160,6 +161,7 @@ class LexiconSeq2SeqDecoder : public Decoder {
160161

161162
std::unordered_map<int, std::vector<LexiconSeq2SeqDecoderState>> hyp_;
162163
};
164+
163165
} // namespace text
164166
} // namespace lib
165167
} // namespace fl

flashlight/lib/text/decoder/Trie.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <unordered_map>
1111
#include <vector>
1212

13+
#include "flashlight/lib/text/Defines.h"
14+
1315
namespace fl {
1416
namespace lib {
1517
namespace text {
@@ -59,7 +61,7 @@ using TrieNodePtr = std::shared_ptr<TrieNode>;
5961
* the search space in deocder and quickly look up scores for a given token
6062
* (completed word) or make prediction for incompleted ones based on smearing.
6163
*/
62-
class Trie {
64+
class FL_TEXT_API Trie {
6365
public:
6466
Trie(int maxChildren, int rootIdx)
6567
: root_(std::make_shared<TrieNode>(rootIdx)), maxChildren_(maxChildren) {}
@@ -90,6 +92,7 @@ class Trie {
9092
};
9193

9294
using TriePtr = std::shared_ptr<Trie>;
95+
9396
} // namespace text
9497
} // namespace lib
9598
} // namespace fl

0 commit comments

Comments
 (0)