Skip to content

Commit b1cc9a9

Browse files
migueljetteclaude
andcommitted
Build: add compatibility with OpenFST 1.8.x and modern macOS (Apple Silicon)
OpenFST 1.8.x requires C++17 and dropped its own int64/uint32/uint64 typedef aliases in favour of the standard <cstdint> names. This commit updates the build system and source code to support both the new library version and Apple Silicon Macs running Homebrew under /opt/homebrew. Changes: - CMakeLists.txt: bump C++ standard to 17; use CMAKE_SHARED_LIBRARY_SUFFIX so -DDYNAMIC_OPENFST=ON works on macOS (.dylib) as well as Linux (.so); add /opt/homebrew ICU paths for Apple Silicon; embed RPATH so the binary finds libfst at runtime without DYLD_LIBRARY_PATH; guard the Clang-only -Wno-implicit-int-float-conversion suppression on jsoncpp - test/CMakeLists.txt: replace hardcoded WORKING_DIRECTORY build/ with CMAKE_BINARY_DIR so tests work from any build directory name - src/AdaptedComposition.h: uint32 -> uint32_t; remove std::unary_function base (removed in C++17) - src/AdaptedComposition.cpp, src/StandardComposition.cpp: int64 -> int64_t - src/fstalign.cpp: uint64 -> uint64_t - third-party/strtk: mark pointer_ mutable so output iterator can advance inside a const operator() under C++17 - README.md: add macOS / OpenFST 1.8.x build instructions Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 69df0b2 commit b1cc9a9

7 files changed

Lines changed: 41 additions & 11 deletions

File tree

CMakeLists.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
1111

1212
enable_testing()
1313

14-
set(CMAKE_CXX_STANDARD 14)
14+
set(CMAKE_CXX_STANDARD 17)
1515
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1616

1717
if(DEFINED ENV{OPENFST_ROOT})
@@ -41,7 +41,7 @@ set(OPENFST_INCLUDES
4141

4242
if(DYNAMIC_OPENFST)
4343
set(OPENFST_LIBRARIES
44-
${OPENFST_ROOT}/lib/libfst.so
44+
${OPENFST_ROOT}/lib/libfst${CMAKE_SHARED_LIBRARY_SUFFIX}
4545
)
4646
else()
4747
set(OPENFST_LIBRARIES
@@ -69,7 +69,7 @@ add_library(fstaligner-common
6969
third-party/inih/cpp/INIReader.cpp
7070
)
7171

72-
list(APPEND CMAKE_PREFIX_PATH "/usr/local/opt/icu4c") # for Mac users
72+
list(APPEND CMAKE_PREFIX_PATH "/usr/local/opt/icu4c" "/opt/homebrew/opt/icu4c@78" "/opt/homebrew/opt/icu4c") # for Mac users
7373
find_package(ICU REQUIRED COMPONENTS uc)
7474

7575
target_link_libraries(fstaligner-common
@@ -80,8 +80,16 @@ target_link_libraries(fstaligner-common
8080
)
8181

8282
add_subdirectory(third-party/jsoncpp)
83+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
84+
target_compile_options(jsoncpp_lib_static PRIVATE -Wno-implicit-int-float-conversion)
85+
endif()
8386
add_subdirectory(third-party/catch2)
8487

88+
if(DYNAMIC_OPENFST)
89+
set(CMAKE_BUILD_RPATH "${OPENFST_ROOT}/lib")
90+
set(CMAKE_INSTALL_RPATH "${OPENFST_ROOT}/lib")
91+
endif()
92+
8593
add_executable(fstalign src/main.cpp)
8694

8795
include_directories(fstalign

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,28 @@ Finally, tests can be run using:
142142
make test
143143
```
144144

145+
### Building on macOS with OpenFST 1.8.x
146+
147+
Homebrew's bundled `openfst` formula (in `openfst.rb`) provides 1.7.9 and conflicts
148+
with `homebrew/core/openfst`. Build OpenFST 1.8.x from source instead:
149+
150+
```bash
151+
curl -L -O https://www.openfst.org/twiki/pub/FST/FstDownload/openfst-1.8.4.tar.gz
152+
tar xzf openfst-1.8.4.tar.gz
153+
cd openfst-1.8.4
154+
./configure --prefix="$HOME/opt/openfst-1.8.4" --disable-dependency-tracking
155+
make -j$(sysctl -n hw.logicalcpu) install
156+
```
157+
158+
Then build fstalign pointing at the new prefix:
159+
160+
```bash
161+
mkdir build && cd build
162+
cmake .. -DOPENFST_ROOT="$HOME/opt/openfst-1.8.4" -DDYNAMIC_OPENFST=ON
163+
make -j$(sysctl -n hw.logicalcpu)
164+
make test
165+
```
166+
145167
### Docker
146168

147169
The fstalign docker image is hosted on Docker Hub and can be easily pulled and run:

src/AdaptedComposition.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ void AdaptedCompositionFst::SetSymbols(const fst::SymbolTable *symbols) {
475475
logger_->debug("{}:{} we created 2 vector<bool> of {} items", __FILE__, __LINE__, symbols->NumSymbols());
476476

477477
for (SymbolTableIterator siter(*symbols); !siter.Done(); siter.Next()) {
478-
int64 sid = siter.Value();
478+
int64_t sid = siter.Value();
479479
auto sym_tk = symbols->Find(sid);
480480

481481
if (isSynonymLabel(sym_tk)) {

src/AdaptedComposition.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ using namespace std;
1919

2020
typedef fst::Fst<fst::StdArc>::StateId StateId;
2121

22-
typedef pair<uint32, uint32> StatePair;
23-
struct key_hash : public std::unary_function<StatePair, std::size_t> {
22+
typedef pair<uint32_t, uint32_t> StatePair;
23+
struct key_hash {
2424
std::size_t operator()(const StatePair &k) const { return std::get<0>(k) ^ std::get<1>(k); }
2525
};
2626

src/fstalign.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ReverseOLabelCompare {
3535
return std::forward_as_tuple(lhs.olabel, lhs.ilabel) > std::forward_as_tuple(rhs.olabel, rhs.ilabel);
3636
}
3737

38-
constexpr uint64 Properties(uint64 props) const {
38+
constexpr uint64_t Properties(uint64_t props) const {
3939
return (props & kArcSortProperties) | kOLabelSorted | (props & kAcceptor ? kILabelSorted : 0);
4040
}
4141
};

test/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ target_link_libraries(fstalign_Test Threads::Threads)
2121

2222
add_test(NAME fstalign_Test
2323
COMMAND $<TARGET_FILE:fstalign_Test>
24-
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/build)
24+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
2525

2626
add_executable(compose-tests compose-tests.cc)
2727
target_link_libraries(compose-tests Threads::Threads)
2828

2929
add_test(NAME compose-tests
3030
COMMAND $<TARGET_FILE:compose-tests>
31-
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/build)
31+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
3232

3333
add_executable(fast-d-tests fast-d-tests.cc)
3434
target_link_libraries(fast-d-tests Threads::Threads)
3535

3636
add_test(NAME fast-d-tests
3737
COMMAND $<TARGET_FILE:fast-d-tests>
38-
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/build)
38+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})

third-party/strtk

Submodule strtk updated from b887974 to 3718839

0 commit comments

Comments
 (0)