Skip to content

Commit 887e658

Browse files
committed
Add reachability metadata for macOS in native image
This commit introduces a `reachability-metadata.json` file specifically for macOS. The metadata defines reflection-required classes, methods, and fields, ensuring compatibility and proper execution in native builds.
1 parent f7f0faa commit 887e658

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

‎search/src/jvmMain/kotlin/io/github/kdroidfilter/seforimlibrary/search/LuceneSearchEngine.kt‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import org.apache.lucene.search.ScoreDoc
1919
import org.apache.lucene.search.TermQuery
2020
import org.apache.lucene.util.QueryBuilder
2121
import org.apache.lucene.store.FSDirectory
22+
import org.apache.lucene.store.NIOFSDirectory
2223
import org.apache.lucene.document.IntPoint
2324
import org.jsoup.Jsoup
2425
import org.jsoup.safety.Safelist
@@ -99,8 +100,16 @@ class LuceneSearchEngine(
99100
}
100101
}
101102

102-
// Open Lucene directory lazily to avoid any I/O at app startup
103-
private val dir by lazy { FSDirectory.open(indexDir) }
103+
// Open Lucene directory lazily to avoid any I/O at app startup.
104+
// Falls back to NIOFSDirectory if MMapDirectory/FSDirectory fails (e.g. GraalVM native image
105+
// on macOS where Panama foreign downcalls for madvise are not registered).
106+
private val dir by lazy {
107+
try {
108+
FSDirectory.open(indexDir)
109+
} catch (t: Throwable) {
110+
NIOFSDirectory(indexDir)
111+
}
112+
}
104113

105114
private val stdAnalyzer: Analyzer by lazy { analyzer }
106115
private val magicDict: MagicDictionaryIndex? by lazy {

0 commit comments

Comments
 (0)